Full crud with the C
This commit is contained in:
7
.gitignore
vendored
7
.gitignore
vendored
@@ -1,2 +1,9 @@
|
|||||||
.idea/
|
.idea/
|
||||||
*/__pycache__
|
*/__pycache__
|
||||||
|
|
||||||
|
front/app-back/
|
||||||
|
front/app-back2/
|
||||||
|
front/app-back3/
|
||||||
|
front/app-back4/
|
||||||
|
front/paper-dashboard-angular-2.4.0/
|
||||||
|
front/app/note_modules
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ def get_crud_router(model, model_create, model_read, model_update):
|
|||||||
async def create(item: model_create) -> dict:
|
async def create(item: model_create) -> dict:
|
||||||
await item.validate_foreign_key()
|
await item.validate_foreign_key()
|
||||||
o = await model(**item.dict()).create()
|
o = await model(**item.dict()).create()
|
||||||
return {"message": "{} added successfully".format(model.__name__), "id": o}
|
return {"message": "{} added successfully".format(model.__name__), "id": o.id}
|
||||||
|
|
||||||
@router.get("/{id}", response_description="{} record retrieved".format(model.__name__))
|
@router.get("/{id}", response_description="{} record retrieved".format(model.__name__))
|
||||||
async def read_id(id: PydanticObjectId) -> model_read:
|
async def read_id(id: PydanticObjectId) -> model_read:
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ import {Component, Input, OnInit} from '@angular/core';
|
|||||||
import { FormGroup } from '@angular/forms';
|
import { FormGroup } from '@angular/forms';
|
||||||
import { FormlyFieldConfig } from '@ngx-formly/core'
|
import { FormlyFieldConfig } from '@ngx-formly/core'
|
||||||
import { FormlyJsonschema } from '@ngx-formly/core/json-schema';
|
import { FormlyJsonschema } from '@ngx-formly/core/json-schema';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
import { CrudService } from '../crud.service'
|
import { CrudService } from '../crud.service'
|
||||||
import {ParamMap} from "@angular/router";
|
|
||||||
import {BehaviorSubject} from "rxjs";
|
import {BehaviorSubject} from "rxjs";
|
||||||
|
|
||||||
export interface Model {
|
export interface Model {
|
||||||
@@ -32,11 +32,9 @@ export class CardComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constructor(private crudService: CrudService,
|
constructor(private crudService: CrudService,
|
||||||
private formlyJsonschema: FormlyJsonschema
|
private formlyJsonschema: FormlyJsonschema,
|
||||||
) {
|
private router: Router
|
||||||
|
) { }
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this._loading$.next(true);
|
this._loading$.next(true);
|
||||||
@@ -54,7 +52,7 @@ export class CardComponent implements OnInit {
|
|||||||
if (this.resource_id !== null) {
|
if (this.resource_id !== null) {
|
||||||
this.crudService.get(this.resource_id!).subscribe((model: any) => {
|
this.crudService.get(this.resource_id!).subscribe((model: any) => {
|
||||||
this.model = model
|
this.model = model
|
||||||
})
|
});
|
||||||
|
|
||||||
this._loading$.next(false);
|
this._loading$.next(false);
|
||||||
}
|
}
|
||||||
@@ -62,10 +60,17 @@ export class CardComponent implements OnInit {
|
|||||||
|
|
||||||
onSubmit(model: any) {
|
onSubmit(model: any) {
|
||||||
this._loading$.next(true);
|
this._loading$.next(true);
|
||||||
|
if (this.resource_id !== null) {
|
||||||
this.crudService.update(model).subscribe((model: any) => {
|
this.crudService.update(model).subscribe((model: any) => {
|
||||||
this.model = model
|
this.model = model;
|
||||||
this._loading$.next(false);
|
this._loading$.next(false);
|
||||||
})
|
});
|
||||||
|
} else {
|
||||||
|
this.crudService.create(model).subscribe((response: any) => {
|
||||||
|
this._loading$.next(false);
|
||||||
|
this.router.navigateByUrl('/entities/' + response.id);
|
||||||
|
});
|
||||||
|
}
|
||||||
console.log(model);
|
console.log(model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,4 +35,11 @@ export class CrudService {
|
|||||||
model
|
model
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public create(model: any) {
|
||||||
|
return this.http.post<{ menu: [{}] }>(
|
||||||
|
`/api/v1/entity/`,
|
||||||
|
model
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user