diff --git a/frontend/bindings/app/internal/models/models.ts b/frontend/bindings/app/internal/models/models.ts index 46517a5..b3174ba 100644 --- a/frontend/bindings/app/internal/models/models.ts +++ b/frontend/bindings/app/internal/models/models.ts @@ -8,6 +8,7 @@ import {Create as $Create} from "@wailsio/runtime"; export class Author { "Id": number; "Name": string; + "Posts": Post[]; /** Creates a new Author instance. */ constructor($$source: Partial = {}) { @@ -17,6 +18,9 @@ export class Author { if (!("Name" in $$source)) { this["Name"] = ""; } + if (!("Posts" in $$source)) { + this["Posts"] = []; + } Object.assign(this, $$source); } @@ -25,7 +29,11 @@ export class Author { * Creates a new Author instance from a string or object. */ static createFrom($$source: any = {}): Author { + const $$createField2_0 = $$createType1; let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source; + if ("Posts" in $$parsedSource) { + $$parsedSource["Posts"] = $$createField2_0($$parsedSource["Posts"]); + } return new Author($$parsedSource as Partial); } } @@ -33,7 +41,10 @@ export class Author { export class Post { "Id": number; "Text": string; + "Deadline": number; "CreatedAt": number; + "AuthorId": number; + "Author": Author; /** Creates a new Post instance. */ constructor($$source: Partial = {}) { @@ -43,9 +54,18 @@ export class Post { if (!("Text" in $$source)) { this["Text"] = ""; } + if (!("Deadline" in $$source)) { + this["Deadline"] = 0; + } if (!("CreatedAt" in $$source)) { this["CreatedAt"] = 0; } + if (!("AuthorId" in $$source)) { + this["AuthorId"] = 0; + } + if (!("Author" in $$source)) { + this["Author"] = (new Author()); + } Object.assign(this, $$source); } @@ -54,7 +74,16 @@ export class Post { * Creates a new Post instance from a string or object. */ static createFrom($$source: any = {}): Post { + const $$createField5_0 = $$createType2; let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source; + if ("Author" in $$parsedSource) { + $$parsedSource["Author"] = $$createField5_0($$parsedSource["Author"]); + } return new Post($$parsedSource as Partial); } } + +// Private type creation functions +const $$createType0 = Post.createFrom; +const $$createType1 = $Create.Array($$createType0); +const $$createType2 = Author.createFrom; diff --git a/frontend/bindings/app/internal/services/authorservice.ts b/frontend/bindings/app/internal/services/authorservice.ts index b6380f1..6ec3d81 100644 --- a/frontend/bindings/app/internal/services/authorservice.ts +++ b/frontend/bindings/app/internal/services/authorservice.ts @@ -20,7 +20,7 @@ export function Count(): Promise & { cancel(): void } { export function Create(item: $models.Author): Promise<$models.Author> & { cancel(): void } { let $resultPromise = $Call.ByID(3684602449, item) as any; - let $typingPromise = $resultPromise.then(($result: any) => { + let $typingPromise = $resultPromise.then(($result) => { return $$createType0($result); }) as any; $typingPromise.cancel = $resultPromise.cancel.bind($resultPromise); @@ -34,7 +34,7 @@ export function Delete(id: number): Promise & { cancel(): void } { export function GetAll(): Promise<($models.Author | null)[]> & { cancel(): void } { let $resultPromise = $Call.ByID(3248293926) as any; - let $typingPromise = $resultPromise.then(($result: any) => { + let $typingPromise = $resultPromise.then(($result) => { return $$createType2($result); }) as any; $typingPromise.cancel = $resultPromise.cancel.bind($resultPromise); @@ -43,7 +43,7 @@ export function GetAll(): Promise<($models.Author | null)[]> & { cancel(): void export function GetById(id: number): Promise<$models.Author | null> & { cancel(): void } { let $resultPromise = $Call.ByID(1703016211, id) as any; - let $typingPromise = $resultPromise.then(($result: any) => { + let $typingPromise = $resultPromise.then(($result) => { return $$createType1($result); }) as any; $typingPromise.cancel = $resultPromise.cancel.bind($resultPromise); @@ -52,7 +52,7 @@ export function GetById(id: number): Promise<$models.Author | null> & { cancel() export function Update(item: $models.Author): Promise<$models.Author> & { cancel(): void } { let $resultPromise = $Call.ByID(2240704960, item) as any; - let $typingPromise = $resultPromise.then(($result: any) => { + let $typingPromise = $resultPromise.then(($result) => { return $$createType0($result); }) as any; $typingPromise.cancel = $resultPromise.cancel.bind($resultPromise); diff --git a/frontend/bindings/app/internal/services/postservice.ts b/frontend/bindings/app/internal/services/postservice.ts index 72d6196..04dec58 100644 --- a/frontend/bindings/app/internal/services/postservice.ts +++ b/frontend/bindings/app/internal/services/postservice.ts @@ -20,7 +20,7 @@ export function Count(): Promise & { cancel(): void } { export function Create(item: $models.Post): Promise<$models.Post> & { cancel(): void } { let $resultPromise = $Call.ByID(1443399856, item) as any; - let $typingPromise = $resultPromise.then(($result: any) => { + let $typingPromise = $resultPromise.then(($result) => { return $$createType0($result); }) as any; $typingPromise.cancel = $resultPromise.cancel.bind($resultPromise); @@ -39,7 +39,7 @@ export function ExportToExcel(): Promise & { cancel(): void } { export function GetAll(): Promise<($models.Post | null)[]> & { cancel(): void } { let $resultPromise = $Call.ByID(65691059) as any; - let $typingPromise = $resultPromise.then(($result: any) => { + let $typingPromise = $resultPromise.then(($result) => { return $$createType2($result); }) as any; $typingPromise.cancel = $resultPromise.cancel.bind($resultPromise); @@ -48,7 +48,7 @@ export function GetAll(): Promise<($models.Post | null)[]> & { cancel(): void } export function GetById(id: number): Promise<$models.Post | null> & { cancel(): void } { let $resultPromise = $Call.ByID(4074736792, id) as any; - let $typingPromise = $resultPromise.then(($result: any) => { + let $typingPromise = $resultPromise.then(($result) => { return $$createType1($result); }) as any; $typingPromise.cancel = $resultPromise.cancel.bind($resultPromise); @@ -57,7 +57,7 @@ export function GetById(id: number): Promise<$models.Post | null> & { cancel(): export function Update(item: $models.Post): Promise<$models.Post> & { cancel(): void } { let $resultPromise = $Call.ByID(137798821, item) as any; - let $typingPromise = $resultPromise.then(($result: any) => { + let $typingPromise = $resultPromise.then(($result) => { return $$createType0($result); }) as any; $typingPromise.cancel = $resultPromise.cancel.bind($resultPromise); diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 6775cb9..6005d1f 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -1,10 +1,12 @@ diff --git a/frontend/src/author/AuthorScheme.vue b/frontend/src/author/AuthorScheme.vue index 840b0dd..7805e05 100644 --- a/frontend/src/author/AuthorScheme.vue +++ b/frontend/src/author/AuthorScheme.vue @@ -1,40 +1,57 @@ +
+
+
+ \ No newline at end of file diff --git a/frontend/src/author/author.service.ts b/frontend/src/author/author.service.ts index dd0f1db..5d88779 100644 --- a/frontend/src/author/author.service.ts +++ b/frontend/src/author/author.service.ts @@ -1,7 +1,7 @@ import { GetAll, Create, Delete, GetById, Update, Count } from "../../bindings/app/internal/services/authorservice.ts" -import type { Author } from "../../bindings/app/internal/services/models.ts" +import type { Author } from "../../bindings/app/internal/services" import type { IService } from "../types/service.type.ts" - + export default class AuthorService implements IService { async read(id: number) { return await GetById(id) as Author @@ -26,4 +26,4 @@ export default class AuthorService implements IService { async count() { return await Count() } -} +} \ No newline at end of file diff --git a/frontend/src/post/PostScheme.vue b/frontend/src/post/PostScheme.vue index 018b4e8..8ea9933 100644 --- a/frontend/src/post/PostScheme.vue +++ b/frontend/src/post/PostScheme.vue @@ -1,37 +1,69 @@ +
+
+
+ \ No newline at end of file diff --git a/frontend/src/post/post.service.ts b/frontend/src/post/post.service.ts index 074e01b..ce362dc 100644 --- a/frontend/src/post/post.service.ts +++ b/frontend/src/post/post.service.ts @@ -1,7 +1,7 @@ import { GetAll, Create, Delete, GetById, Update, Count } from "../../bindings/app/internal/services/postservice.ts" -import type { Post } from "../../bindings/app/internal/services/models.ts" +import type { Post } from "../../bindings/app/internal/services" import type { IService } from "../types/service.type.ts" - + export default class PostService implements IService { async read(id: number) { return await GetById(id) as Post @@ -26,4 +26,4 @@ export default class PostService implements IService { async count() { return await Count() } -} +} \ No newline at end of file diff --git a/internal/dal/authors.gen.go b/internal/dal/authors.gen.go index 5af5a72..7425d78 100644 --- a/internal/dal/authors.gen.go +++ b/internal/dal/authors.gen.go @@ -28,6 +28,24 @@ func newAuthor(db *gorm.DB, opts ...gen.DOOption) author { _author.ALL = field.NewAsterisk(tableName) _author.Id = field.NewUint(tableName, "id") _author.Name = field.NewString(tableName, "name") + _author.Posts = authorHasManyPosts{ + db: db.Session(&gorm.Session{}), + + RelationField: field.NewRelation("Posts", "models.Post"), + Author: struct { + field.RelationField + Posts struct { + field.RelationField + } + }{ + RelationField: field.NewRelation("Posts.Author", "models.Author"), + Posts: struct { + field.RelationField + }{ + RelationField: field.NewRelation("Posts.Author.Posts", "models.Post"), + }, + }, + } _author.fillFieldMap() @@ -37,9 +55,10 @@ func newAuthor(db *gorm.DB, opts ...gen.DOOption) author { type author struct { authorDo - ALL field.Asterisk - Id field.Uint - Name field.String + ALL field.Asterisk + Id field.Uint + Name field.String + Posts authorHasManyPosts fieldMap map[string]field.Expr } @@ -74,9 +93,10 @@ func (a *author) GetFieldByName(fieldName string) (field.OrderExpr, bool) { } func (a *author) fillFieldMap() { - a.fieldMap = make(map[string]field.Expr, 2) + a.fieldMap = make(map[string]field.Expr, 3) a.fieldMap["id"] = a.Id a.fieldMap["name"] = a.Name + } func (a author) clone(db *gorm.DB) author { @@ -89,6 +109,84 @@ func (a author) replaceDB(db *gorm.DB) author { return a } +type authorHasManyPosts struct { + db *gorm.DB + + field.RelationField + + Author struct { + field.RelationField + Posts struct { + field.RelationField + } + } +} + +func (a authorHasManyPosts) Where(conds ...field.Expr) *authorHasManyPosts { + if len(conds) == 0 { + return &a + } + + exprs := make([]clause.Expression, 0, len(conds)) + for _, cond := range conds { + exprs = append(exprs, cond.BeCond().(clause.Expression)) + } + a.db = a.db.Clauses(clause.Where{Exprs: exprs}) + return &a +} + +func (a authorHasManyPosts) WithContext(ctx context.Context) *authorHasManyPosts { + a.db = a.db.WithContext(ctx) + return &a +} + +func (a authorHasManyPosts) Session(session *gorm.Session) *authorHasManyPosts { + a.db = a.db.Session(session) + return &a +} + +func (a authorHasManyPosts) Model(m *models.Author) *authorHasManyPostsTx { + return &authorHasManyPostsTx{a.db.Model(m).Association(a.Name())} +} + +type authorHasManyPostsTx struct{ tx *gorm.Association } + +func (a authorHasManyPostsTx) Find() (result []*models.Post, err error) { + return result, a.tx.Find(&result) +} + +func (a authorHasManyPostsTx) Append(values ...*models.Post) (err error) { + targetValues := make([]interface{}, len(values)) + for i, v := range values { + targetValues[i] = v + } + return a.tx.Append(targetValues...) +} + +func (a authorHasManyPostsTx) Replace(values ...*models.Post) (err error) { + targetValues := make([]interface{}, len(values)) + for i, v := range values { + targetValues[i] = v + } + return a.tx.Replace(targetValues...) +} + +func (a authorHasManyPostsTx) Delete(values ...*models.Post) (err error) { + targetValues := make([]interface{}, len(values)) + for i, v := range values { + targetValues[i] = v + } + return a.tx.Delete(targetValues...) +} + +func (a authorHasManyPostsTx) Clear() error { + return a.tx.Clear() +} + +func (a authorHasManyPostsTx) Count() int64 { + return a.tx.Count() +} + type authorDo struct{ gen.DO } type IAuthorDo interface { diff --git a/internal/dal/posts.gen.go b/internal/dal/posts.gen.go index 0452361..cf6c303 100644 --- a/internal/dal/posts.gen.go +++ b/internal/dal/posts.gen.go @@ -28,7 +28,27 @@ func newPost(db *gorm.DB, opts ...gen.DOOption) post { _post.ALL = field.NewAsterisk(tableName) _post.Id = field.NewUint(tableName, "id") _post.Text = field.NewString(tableName, "text") + _post.Deadline = field.NewInt64(tableName, "deadline") _post.CreatedAt = field.NewInt64(tableName, "created_at") + _post.AuthorId = field.NewUint(tableName, "author_id") + _post.Author = postBelongsToAuthor{ + db: db.Session(&gorm.Session{}), + + RelationField: field.NewRelation("Author", "models.Author"), + Posts: struct { + field.RelationField + Author struct { + field.RelationField + } + }{ + RelationField: field.NewRelation("Author.Posts", "models.Post"), + Author: struct { + field.RelationField + }{ + RelationField: field.NewRelation("Author.Posts.Author", "models.Author"), + }, + }, + } _post.fillFieldMap() @@ -41,7 +61,10 @@ type post struct { ALL field.Asterisk Id field.Uint Text field.String + Deadline field.Int64 CreatedAt field.Int64 + AuthorId field.Uint + Author postBelongsToAuthor fieldMap map[string]field.Expr } @@ -60,7 +83,9 @@ func (p *post) updateTableName(table string) *post { p.ALL = field.NewAsterisk(table) p.Id = field.NewUint(table, "id") p.Text = field.NewString(table, "text") + p.Deadline = field.NewInt64(table, "deadline") p.CreatedAt = field.NewInt64(table, "created_at") + p.AuthorId = field.NewUint(table, "author_id") p.fillFieldMap() @@ -77,10 +102,13 @@ func (p *post) GetFieldByName(fieldName string) (field.OrderExpr, bool) { } func (p *post) fillFieldMap() { - p.fieldMap = make(map[string]field.Expr, 3) + p.fieldMap = make(map[string]field.Expr, 6) p.fieldMap["id"] = p.Id p.fieldMap["text"] = p.Text + p.fieldMap["deadline"] = p.Deadline p.fieldMap["created_at"] = p.CreatedAt + p.fieldMap["author_id"] = p.AuthorId + } func (p post) clone(db *gorm.DB) post { @@ -93,6 +121,84 @@ func (p post) replaceDB(db *gorm.DB) post { return p } +type postBelongsToAuthor struct { + db *gorm.DB + + field.RelationField + + Posts struct { + field.RelationField + Author struct { + field.RelationField + } + } +} + +func (a postBelongsToAuthor) Where(conds ...field.Expr) *postBelongsToAuthor { + if len(conds) == 0 { + return &a + } + + exprs := make([]clause.Expression, 0, len(conds)) + for _, cond := range conds { + exprs = append(exprs, cond.BeCond().(clause.Expression)) + } + a.db = a.db.Clauses(clause.Where{Exprs: exprs}) + return &a +} + +func (a postBelongsToAuthor) WithContext(ctx context.Context) *postBelongsToAuthor { + a.db = a.db.WithContext(ctx) + return &a +} + +func (a postBelongsToAuthor) Session(session *gorm.Session) *postBelongsToAuthor { + a.db = a.db.Session(session) + return &a +} + +func (a postBelongsToAuthor) Model(m *models.Post) *postBelongsToAuthorTx { + return &postBelongsToAuthorTx{a.db.Model(m).Association(a.Name())} +} + +type postBelongsToAuthorTx struct{ tx *gorm.Association } + +func (a postBelongsToAuthorTx) Find() (result *models.Author, err error) { + return result, a.tx.Find(&result) +} + +func (a postBelongsToAuthorTx) Append(values ...*models.Author) (err error) { + targetValues := make([]interface{}, len(values)) + for i, v := range values { + targetValues[i] = v + } + return a.tx.Append(targetValues...) +} + +func (a postBelongsToAuthorTx) Replace(values ...*models.Author) (err error) { + targetValues := make([]interface{}, len(values)) + for i, v := range values { + targetValues[i] = v + } + return a.tx.Replace(targetValues...) +} + +func (a postBelongsToAuthorTx) Delete(values ...*models.Author) (err error) { + targetValues := make([]interface{}, len(values)) + for i, v := range values { + targetValues[i] = v + } + return a.tx.Delete(targetValues...) +} + +func (a postBelongsToAuthorTx) Clear() error { + return a.tx.Clear() +} + +func (a postBelongsToAuthorTx) Count() int64 { + return a.tx.Count() +} + type postDo struct{ gen.DO } type IPostDo interface { diff --git a/internal/models/models.go b/internal/models/models.go index bb5af6d..5f5979d 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -7,10 +7,16 @@ var Entities = []any{ type Post struct { Id uint `gorm:"primaryKey" ui:"hidden"` Text string `displayName:"Текст" ui:"label=Текст"` + Deadline int64 `ui:"label=Дедлайн"` CreatedAt int64 `gorm:"autoCreateTime" ui:"hidden"` + AuthorId uint + Author Author `ui:"label=Автор, data=Author, field=[Name]"` } type Author struct { - Id uint `gorm:"primaryKey" ui:"hidden"` - Name string `ui:"label=Имя"` + Id uint `gorm:"primaryKey" ui:"hidden"` + Name string `ui:"label=Имя"` + Posts []Post `ui:"label=Посты, data=Post, field=[Text]"` } + +// TODO: correct processing the semicolon (get attention to quotes) diff --git a/internal/services/default_data.go b/internal/services/default_data.go index 832cdd6..e0c26d1 100644 --- a/internal/services/default_data.go +++ b/internal/services/default_data.go @@ -3,11 +3,12 @@ package services import ( "app/internal/dialogs" "fmt" + "time" ) func InsertDefaultData() { - insertPosts() insertAuthors() + insertPosts() } func InsertDefaultEntityData[T any](service Service[T], entities []T) { @@ -22,16 +23,22 @@ func InsertDefaultEntityData[T any](service Service[T], entities []T) { func insertPosts() { InsertDefaultEntityData(&PostService{}, []Post{ { - Id: 1, - Text: "Жителям Кузбасса запретили болеть.", + Id: 1, + Text: "Жителям Кузбасса запретили болеть.", + Deadline: time.Now().Unix(), + AuthorId: 1, }, { - Id: 2, - Text: "⚡️⚡️⚡️Дома будут летать.", + Id: 2, + Deadline: time.Now().Add(time.Hour * 24 * 5).Unix(), + Text: "⚡️⚡️⚡️Дома будут летать.", + AuthorId: 2, }, { - Id: 3, - Text: "В Кузбассе начали строить дома выше, чтобы жители были ближе к богу и солнцу.", + Id: 3, + Deadline: time.Now().Add(time.Hour * 24 * 6).Unix(), + Text: "В Кузбассе начали строить дома выше, чтобы жители были ближе к богу и солнцу.", + AuthorId: 3, }, }) } @@ -42,5 +49,13 @@ func insertAuthors() { Id: 1, Name: "ИА Кузбасс", }, + { + Id: 2, + Name: "ASTRA", + }, + { + Id: 3, + Name: "ЧТД", + }, }) } diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..a69d2f9 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,18 @@ +{ + "name": "boilerplate", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "@wailsio/runtime": "3.0.0-alpha.66" + } + }, + "node_modules/@wailsio/runtime": { + "version": "3.0.0-alpha.66", + "resolved": "https://registry.npmjs.org/@wailsio/runtime/-/runtime-3.0.0-alpha.66.tgz", + "integrity": "sha512-ENLu8rn1griL1gFHJqkq1i+BVxrrA0JPJHYneUJYuf/s54kjuQViW0RKDEe/WTDo56ABpfykrd/T8OYpPUyXUw==", + "license": "MIT" + } + } +}