remove sub things and add view
This commit is contained in:
parent
feb248e991
commit
2b13e5c03a
@ -1,25 +1,8 @@
|
||||
export namespace model {
|
||||
|
||||
export class SubThing {
|
||||
ID: number;
|
||||
ThingID: number;
|
||||
Name: string;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new SubThing(source);
|
||||
}
|
||||
|
||||
constructor(source: any = {}) {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.ID = source["ID"];
|
||||
this.ThingID = source["ThingID"];
|
||||
this.Name = source["Name"];
|
||||
}
|
||||
}
|
||||
export class Thing {
|
||||
ID: number;
|
||||
Name: string;
|
||||
Subthings: SubThing[];
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new Thing(source);
|
||||
@ -29,26 +12,7 @@ export namespace model {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.ID = source["ID"];
|
||||
this.Name = source["Name"];
|
||||
this.Subthings = this.convertValues(source["Subthings"], SubThing);
|
||||
}
|
||||
|
||||
convertValues(a: any, classs: any, asMap: boolean = false): any {
|
||||
if (!a) {
|
||||
return a;
|
||||
}
|
||||
if (a.slice && a.map) {
|
||||
return (a as any[]).map(elem => this.convertValues(elem, classs));
|
||||
} else if ("object" === typeof a) {
|
||||
if (asMap) {
|
||||
for (const key of Object.keys(a)) {
|
||||
a[key] = new classs(a[key]);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
return new classs(a);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
6
frontend/wailsjs/go/things/Service.d.ts
vendored
6
frontend/wailsjs/go/things/Service.d.ts
vendored
@ -2,14 +2,8 @@
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
import {model} from '../models';
|
||||
|
||||
export function AddSubThing(arg1:number,arg2:string):Promise<void>;
|
||||
|
||||
export function DeleteSubThing(arg1:number):Promise<void>;
|
||||
|
||||
export function DeleteThing(arg1:number):Promise<void>;
|
||||
|
||||
export function GetSubThings(arg1:number):Promise<Array<model.SubThing>>;
|
||||
|
||||
export function GetThings():Promise<Array<model.Thing>>;
|
||||
|
||||
export function NewThing(arg1:string):Promise<void>;
|
||||
|
@ -2,22 +2,10 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
export function AddSubThing(arg1, arg2) {
|
||||
return window['go']['things']['Service']['AddSubThing'](arg1, arg2);
|
||||
}
|
||||
|
||||
export function DeleteSubThing(arg1) {
|
||||
return window['go']['things']['Service']['DeleteSubThing'](arg1);
|
||||
}
|
||||
|
||||
export function DeleteThing(arg1) {
|
||||
return window['go']['things']['Service']['DeleteThing'](arg1);
|
||||
}
|
||||
|
||||
export function GetSubThings(arg1) {
|
||||
return window['go']['things']['Service']['GetSubThings'](arg1);
|
||||
}
|
||||
|
||||
export function GetThings() {
|
||||
return window['go']['things']['Service']['GetThings']();
|
||||
}
|
||||
|
@ -10,15 +10,8 @@ import (
|
||||
)
|
||||
|
||||
type Thing struct {
|
||||
ID int
|
||||
Name string
|
||||
Subthings []SubThing
|
||||
}
|
||||
|
||||
type SubThing struct {
|
||||
ID int
|
||||
ThingID int
|
||||
Name string
|
||||
ID int
|
||||
Name string
|
||||
}
|
||||
|
||||
func InitDB() *gorm.DB {
|
||||
@ -30,6 +23,6 @@ func InitDB() *gorm.DB {
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
db.AutoMigrate(&Thing{}, &SubThing{})
|
||||
db.AutoMigrate(&Thing{})
|
||||
return db
|
||||
}
|
||||
|
@ -31,24 +31,3 @@ func (s *Service) DeleteThing(id int) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) GetSubThings(thingID int) (subthings []model.SubThing) {
|
||||
if err := s.DB.Where("thing_id = ?", thingID).Find(&subthings).Error; err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
func (s *Service) AddSubThing(thingID int, name string) {
|
||||
if err := s.DB.Save(&model.SubThing{
|
||||
ThingID: thingID,
|
||||
Name: name,
|
||||
}).Error; err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) DeleteSubThing(id int) {
|
||||
if err := s.DB.Delete(model.SubThing{}, id).Error; err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user