feat: services: crus, migrations

This commit is contained in:
2025-01-04 01:36:01 +07:00
parent 0c9f60bba5
commit 081ebf2b28
22 changed files with 533 additions and 63 deletions

View File

@@ -0,0 +1,36 @@
package services
import (
"app/internal/dialogs"
"fmt"
)
func InsertDefaultData() {
insertPosts()
}
func InsertDefaultEntityData[T any](service Service[T], entities []T) {
for _, item := range entities {
createdItem, err := service.Create(item)
if err != nil {
dialogs.ErrorDialog("Ошибка при вставке данных по умолчанию", fmt.Sprintf("Произошла ошибка при вставке значения %#v: %s", createdItem, err))
}
}
}
func insertPosts() {
InsertDefaultEntityData(&PostService{}, []Post{
{
Id: 1,
Text: "Жителям Кузбасса запретили болеть.",
},
{
Id: 2,
Text: "⚡️⚡️⚡️Дома будут летать.",
},
{
Id: 3,
Text: "В Кузбассе начали строить дома выше, чтобы жители были ближе к богу и солнцу.",
},
})
}