Added: Alembic for migrations
Moving from Pyramid to FastAPI
This commit is contained in:
@ -40,9 +40,13 @@ export class ProductListDataSource extends DataSource<Product> {
|
||||
|
||||
private getFilteredData(data: Product[]): Product[] {
|
||||
const filter = (this.filterValue === undefined) ? '' : this.filterValue;
|
||||
if (filter === '') {
|
||||
return data;
|
||||
} else {
|
||||
return data.filter(x => {
|
||||
return x.menuCategory.id === filter || filter === '';
|
||||
return x.menuCategory.id === filter;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,7 +3,6 @@ import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
|
||||
import { ProductListDataSource } from './product-list-datasource';
|
||||
import { MatTable } from '@angular/material';
|
||||
import { Product } from '../../core/product';
|
||||
import { ToCsvService } from '../../shared/to-csv.service';
|
||||
import { ToasterService } from '../../core/toaster.service';
|
||||
@ -17,7 +16,6 @@ import { BehaviorSubject } from 'rxjs';
|
||||
styleUrls: ['./product-list.component.css']
|
||||
})
|
||||
export class ProductListComponent implements OnInit {
|
||||
@ViewChild('table', { static: true }) table: MatTable<Product>;
|
||||
dataSource: ProductListDataSource;
|
||||
filter: BehaviorSubject<string>;
|
||||
form: FormGroup;
|
||||
@ -30,7 +28,6 @@ export class ProductListComponent implements OnInit {
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private fb: FormBuilder,
|
||||
private router: Router,
|
||||
private toaster: ToasterService,
|
||||
private toCsv: ToCsvService,
|
||||
private ser: ProductService
|
||||
@ -50,20 +47,24 @@ export class ProductListComponent implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.dataSource = new ProductListDataSource(this.filter, this.data);
|
||||
this.route.data
|
||||
.subscribe((data: { list: Product[], menuCategories: MenuCategory[] }) => {
|
||||
this.data.next(data.list);
|
||||
this.menuCategories = data.menuCategories;
|
||||
this.loadData(data.list, data.menuCategories);
|
||||
});
|
||||
this.dataSource = new ProductListDataSource(this.filter, this.data);
|
||||
}
|
||||
|
||||
loadData(list: Product[], menuCategories: MenuCategory[]) {
|
||||
this.menuCategories = menuCategories;
|
||||
this.data.next(list);
|
||||
}
|
||||
|
||||
updateSortOrder() {
|
||||
this.ser.updateSortOrder(this.dataSource.viewData)
|
||||
.subscribe(
|
||||
(result) => {
|
||||
(result: Product[]) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/products');
|
||||
this.loadData(result, this.menuCategories);
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error.error);
|
||||
|
||||
@ -9,7 +9,7 @@ const httpOptions = {
|
||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||
};
|
||||
|
||||
const url = '/v1/products';
|
||||
const url = '/api/products';
|
||||
const serviceName = 'ProductService';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
@ -19,7 +19,7 @@ export class ProductService {
|
||||
}
|
||||
|
||||
get(id: string): Observable<Product> {
|
||||
const getUrl: string = (id === null) ? `${url}/new` : `${url}/${id}`;
|
||||
const getUrl: string = (id === null) ? `${url}` : `${url}/${id}`;
|
||||
return <Observable<Product>>this.http.get<Product>(getUrl)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, `get id=${id}`))
|
||||
@ -27,23 +27,22 @@ export class ProductService {
|
||||
}
|
||||
|
||||
list(): Observable<Product[]> {
|
||||
const options = {params: new HttpParams().set('l', '')};
|
||||
return <Observable<Product[]>>this.http.get<Product[]>(url, options)
|
||||
return <Observable<Product[]>>this.http.get<Product[]>(`${url}/list`)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
);
|
||||
}
|
||||
|
||||
listIsActiveOfCategory(id: string): Observable<Product[]> {
|
||||
const options = {params: new HttpParams().set('mc', id).set('a', '')};
|
||||
return <Observable<Product[]>>this.http.get<Product[]>(url, options)
|
||||
const options = {params: new HttpParams().set('mc', id).set('a', 'true')};
|
||||
return <Observable<Product[]>>this.http.get<Product[]>(`${url}/query`, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'listIsActiveOfCategory'))
|
||||
);
|
||||
}
|
||||
|
||||
save(product: Product): Observable<Product> {
|
||||
return <Observable<Product>>this.http.post<Product>(`${url}/new`, product, httpOptions)
|
||||
return <Observable<Product>>this.http.post<Product>(`${url}`, product, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'save'))
|
||||
);
|
||||
@ -56,8 +55,8 @@ export class ProductService {
|
||||
);
|
||||
}
|
||||
|
||||
updateSortOrder(list: Product[]): Observable<boolean> {
|
||||
return <Observable<boolean>>this.http.post<Product[]>(url, list, httpOptions)
|
||||
updateSortOrder(list: Product[]): Observable<Product[]> {
|
||||
return <Observable<Product[]>>this.http.post<Product[]>(`${url}/list`, list, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'updateSortOrder'))
|
||||
);
|
||||
@ -78,17 +77,9 @@ export class ProductService {
|
||||
);
|
||||
}
|
||||
|
||||
autocomplete(term: string): Observable<Product[]> {
|
||||
const options = {params: new HttpParams().set('t', term)};
|
||||
return <Observable<Product[]>>this.http.get<Product[]>(url, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'autocomplete'))
|
||||
);
|
||||
}
|
||||
|
||||
balance(id: string, date: string): Observable<number> {
|
||||
const options = {params: new HttpParams().set('b', 'true').set('d', date)};
|
||||
return <Observable<number>>this.http.get<number>(`${url}/${id}`, options)
|
||||
const options = {params: new HttpParams().set('d', date)};
|
||||
return <Observable<number>>this.http.get<number>(`${url}/balance`, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'balance'))
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user