feat: sample data

This commit is contained in:
2025-03-08 20:06:06 +07:00
parent b4ea46140d
commit 9ea91f3b40
13 changed files with 396 additions and 73 deletions

View File

@@ -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<Author> = {}) {
@@ -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<Author>);
}
}
@@ -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<Post> = {}) {
@@ -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<Post>);
}
}
// Private type creation functions
const $$createType0 = Post.createFrom;
const $$createType1 = $Create.Array($$createType0);
const $$createType2 = Author.createFrom;

View File

@@ -20,7 +20,7 @@ export function Count(): Promise<number> & { 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<void> & { 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);

View File

@@ -20,7 +20,7 @@ export function Count(): Promise<number> & { 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<void> & { 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);

View File

@@ -1,10 +1,12 @@
<script setup lang="ts">
import PostScheme from './post/PostScheme.vue';
import AuthorScheme from "./author/AuthorScheme.vue";
</script>
<template>
<main class="w-screen h-screen">
<PostScheme />
<AuthorScheme />
</main>
</template>

View File

@@ -1,31 +1,48 @@
<script setup lang="ts">
import Table from '../table/Table.vue'
import { onMounted, reactive } from 'vue'
import { getDefaultValues } from '../utils/structs/defaults.util.ts'
import S from './author.service.ts'
import type { Scheme } from '../types/scheme.type'
import { Author } from '../../bindings/app/internal/services/models.ts'
import {onMounted, reactive} from 'vue'
import {getDefaultValues} from '../utils/structs/defaults.util'
import Service from './author.service.ts'
import type {Scheme} from '../types/scheme.type'
import {Author} from '../../bindings/app/internal/services'
const service = new S
import PostService from '../post/post.service.ts'
const postService = new PostService
const service = new Service
onMounted(async () => {
(scheme as any).Posts.type!.nested!.values = await postService.readAll()
console.log(scheme)
})
const scheme: Scheme<Author> = reactive({
Id:{
Id: {
hidden: true,
type: {
primitive: "number",
},
},
Name:{
},
Name: {
russian: "Имя",
type: {
primitive: "string",
},
},
},
Posts: {
russian: "Посты",
many: true,
type: {
nested: {
values: [],
field: ['Text']
},
},
},
})

View File

@@ -1,5 +1,5 @@
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<Author> {

View File

@@ -1,37 +1,69 @@
<script setup lang="ts">
import Table from '../table/Table.vue'
import { onMounted, reactive } from 'vue'
import { getDefaultValues } from '../utils/structs/defaults.util.ts'
import S from './post.service.ts'
import { getDefaultValues } from '../utils/structs/defaults.util'
import Service from './post.service.ts'
import type { Scheme } from '../types/scheme.type'
import { Post } from '../../bindings/app/internal/services/models.ts'
import { Post } from '../../bindings/app/internal/services'
const service = new S
import AuthorService from '../author/author.service.ts'
const authorService = new AuthorService
const service = new Service
onMounted(async () => {
(scheme as any).Author.type!.nested!.values = await authorService.readAll()
})
const scheme: Scheme<Post> = reactive({
Id: {
hidden: true,
type: {
primitive: "number",
},
},
},
Text: {
russian: "Текст",
type: {
primitive: "string",
},
},
Deadline: {
russian: "Дедлайн",
type: {
primitive: "number",
},
},
CreatedAt: {
hidden: true,
type: {
primitive: "number",
},
},
AuthorId: {
type: {
primitive: "number",
},
},
Author: {
russian: "Автор",
type: {
nested: {
values: [],
field: ['Name']
},
},
},
})
const getDefaults = () => getDefaultValues(scheme)

View File

@@ -1,5 +1,5 @@
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<Post> {

View File

@@ -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()
@@ -40,6 +58,7 @@ type author struct {
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 {

View File

@@ -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 {

View File

@@ -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=Имя"`
Posts []Post `ui:"label=Посты, data=Post, field=[Text]"`
}
// TODO: correct processing the semicolon (get attention to quotes)

View File

@@ -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) {
@@ -24,14 +25,20 @@ func insertPosts() {
{
Id: 1,
Text: "Жителям Кузбасса запретили болеть.",
Deadline: time.Now().Unix(),
AuthorId: 1,
},
{
Id: 2,
Deadline: time.Now().Add(time.Hour * 24 * 5).Unix(),
Text: "⚡️⚡️⚡️Дома будут летать.",
AuthorId: 2,
},
{
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: "ЧТД",
},
})
}

18
package-lock.json generated Normal file
View File

@@ -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"
}
}
}