Фикс ошибок

This commit is contained in:
Александр Кирюхин 2024-04-29 23:31:44 +03:00
parent 98b3ad7954
commit 7e706a3981
No known key found for this signature in database
GPG key ID: 35E33E1AB7776B39
9 changed files with 58 additions and 53 deletions

View file

@ -18,6 +18,7 @@ dev-front:
.PHONY: deploy
deploy: frontend/dist
unset DOCKER_HOST
docker context use curie
docker compose up -d
docker compose up -d --build --remove-orphans
docker context use default

View file

@ -278,7 +278,6 @@ components:
- taskCount
- createdAt
- authors
- icon
taskView:
type: object
properties:
@ -309,8 +308,6 @@ components:
type: string
code:
type: string
required:
- description
gameEdit:
type: object
properties:
@ -370,7 +367,6 @@ components:
code:
type: string
required:
- description
- code
gameType:
type: string

View file

@ -295,27 +295,27 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL
// Base64 encoded, gzipped, json marshaled Swagger object
var swaggerSpec = []string{
"H4sIAAAAAAAC/8xZX2/cNgz/KoO2Rze+/nnyWxdkQbGg2Lp0L8EhUGzmosaWHIlOcwv83QdKts8+y39y",
"da99is+mKPLHHylSeWaxynIlQaJh0TPTYHIlDdgfoLXSn6o39CJWEkEiPfI8T0XMUSgZfjFK0jsT30HG",
"6SnXKgeNwumJVWKX4zYHFjEhETagWRmwDIzhm/ZHg1rIDSvLgGl4KISGhEVXTsVOfh3U8urmC8TISlqQ",
"gIm1yMkmFjHSfytSMBfC4EFeCITMOvCbhlsWsV/DHVihEzMhbfEBIaPtKpu41nw7ZNKGZ/A+yYQ8yKQx",
"S0jzWSJwbOfviwXt8K+Ar3OxQG7uF4eBlDoj/JsWeap4sgCti0Ik9PdW6Ywji9yLYILJVmgufwsDenGA",
"SOkwQGVQqWlS13JqKqlrb/cUer4fAlpbZ+C27kPoPljPlrJ2xAzf/k0t6O0/y+mAKS02QvL0I8/85hrx",
"n7eU7hlqtXeUVUt9Vjd1o2f1ZChj92HSr5nu50pU51D/qKC0NrMrEUm7WrhfiQKGAlM/uu7FdI27JLky",
"YI/CiJuOrhulUuCyF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4fMDsShpeQM2",
"OShabaP7IWERs8MTzTF/0HBnuWieAQJddleVEcR5Z8JDpdTOAagLCFr98lQ7ug66o/Gb1WooSBu6sD99",
"tr1glW3jf9UPsXJNJzzohG6KsdmszBBKny0R4XRMmCyb31Wy3ZtYsiJFkXONIbF5lXD0DFVkZEfSjZBc",
"b70TgmeEermT9sbBb/JQU8XGA/e8ztQXK9sb4a3RIxFAN/q5qzDDjlnmyaE81KDua8i3OyB8LkQyUT/O",
"oYZlOi1cqB+5diwGDMiNkDCBCWFxZgl/XkQ6j0Uu3jrGhfXE70+HM4mgT12TdiQLD8u3Wc8Y895HDkxK",
"H9Lu8hkPIsDZV813iqABkFWMgK8MauBZF+zpa6b3RGZvqAqV8YJfFZnlSj2JtN3oiMTPrls94CJsvzWW",
"AXu3ejt9qPsvgpaKYao2Qg6n41/KWFUvLNlS2TI8y+TcmK9KJ9O5VHfizYnF8qqP8OrlCHcugXUHb1Xg",
"LMCJrqf/u97LIDNFHIMxv1SsD9V4p6OGjTDo4ndcy0815Q+NjN3mG+/u/HHPM+k1cttSfu5YG+1A1lSU",
"DejHuuwXOmURC2nkK9fl/wEAAP//MtUIV2ocAAA=",
}
// GetSwagger returns the content of the embedded swagger specification file

View file

@ -36,14 +36,14 @@ const (
// CodeEdit defines model for codeEdit.
type CodeEdit struct {
Code string `json:"code"`
Description string `json:"description"`
Description *string `json:"description,omitempty"`
Id *openapi_types.UUID `json:"id,omitempty"`
}
// CodeView defines model for codeView.
type CodeView struct {
Code *string `json:"code,omitempty"`
Description string `json:"description"`
Description *string `json:"description,omitempty"`
}
// FileItem defines model for fileItem.
@ -73,7 +73,7 @@ type GameView struct {
Authors []UserView `json:"authors"`
CreatedAt string `json:"createdAt"`
Description string `json:"description"`
Icon openapi_types.UUID `json:"icon"`
Icon *openapi_types.UUID `json:"icon,omitempty"`
Id openapi_types.UUID `json:"id"`
Points int `json:"points"`
TaskCount int `json:"taskCount"`

View file

@ -46,7 +46,7 @@ const router = createBrowserRouter(
<Route
path="/admin/quests/new"
element={<Auth role="creator"><EditQuest /></Auth>}
// loader={() => ajax(`/api/admin/games`)}
loader={() => ({ quest: null, files: [] })}
/>
<Route
path="/admin/quests/:gameId"

View file

@ -41,7 +41,7 @@ func (a *Admin) AdminEditGame(ctx echo.Context) error {
codes = append(codes, api.CodeEdit{
Id: &c.ID,
Code: c.Code,
Description: c.Description,
Description: &c.Description,
})
}
tasks = append(tasks, api.TaskEdit{
@ -54,7 +54,7 @@ func (a *Admin) AdminEditGame(ctx echo.Context) error {
return ctx.JSON(http.StatusOK, api.GameAdminResponse{
Description: game.Description,
Icon: &game.IconID,
Icon: game.IconID,
Id: &game.ID,
Points: game.Points,
Tasks: tasks,
@ -94,7 +94,7 @@ func (a *Admin) AdminGetGame(ctx echo.Context, uid uuid.UUID) error {
codes = append(codes, api.CodeEdit{
Id: &c.ID,
Code: c.Code,
Description: c.Description,
Description: &c.Description,
})
}
tasks = append(tasks, api.TaskEdit{
@ -107,7 +107,7 @@ func (a *Admin) AdminGetGame(ctx echo.Context, uid uuid.UUID) error {
return ctx.JSON(http.StatusOK, api.GameAdminResponse{
Description: game.Description,
Icon: &game.IconID,
Icon: game.IconID,
Id: &game.ID,
Points: game.Points,
Tasks: tasks,
@ -145,13 +145,10 @@ func (a *Admin) AdminListGames(ctx echo.Context) error {
func (*Admin) mapCreateGameRequest(req *api.GameEdit, user *models.User) *models.Game {
id := uuid.New()
icon := uuid.New()
if req.Id != nil {
id = *req.Id
}
if req.Icon != nil {
icon = *req.Icon
}
game := &models.Game{
ID: id,
Visible: req.Visible,
@ -163,7 +160,7 @@ func (*Admin) mapCreateGameRequest(req *api.GameEdit, user *models.User) *models
Type: api.MapGameType(req.Type),
Tasks: make([]*models.Task, 0, len(req.Tasks)),
Points: req.Points,
IconID: icon,
IconID: req.Icon,
}
for order, te := range req.Tasks {
id := uuid.New()
@ -183,10 +180,14 @@ func (*Admin) mapCreateGameRequest(req *api.GameEdit, user *models.User) *models
if ce.Id != nil {
id = *ce.Id
}
desc := ""
if ce.Description != nil {
desc = *ce.Description
}
task.Codes = append(task.Codes, &models.Code{
ID: id,
Code: ce.Code,
Description: ce.Description,
Description: desc,
})
}
game.Tasks = append(game.Tasks, task)

View file

@ -83,7 +83,7 @@ func mapCursorToTask(cursor *models.GameCursor, message *api.TaskViewMessage) *a
}
for _, code := range cursor.Task.Codes {
c := api.CodeView{
Description: code.Description,
Description: &code.Description,
}
for _, cd := range cursor.Codes {
if cd.ID == code.ID {

View file

@ -16,8 +16,8 @@ type Game struct {
Authors []*User `gorm:"many2many:game_authors"`
Type GameType
Points int
Icon *File
IconID uuid.UUID
Icon *File `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
IconID *uuid.UUID
CreatedAt time.Time `json:"-"`
UpdatedAt time.Time `json:"-"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`

View file

@ -6,6 +6,7 @@ import (
"github.com/google/uuid"
"gitrepo.ru/neonxp/nquest/pkg/models"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
type Game struct {
@ -69,6 +70,12 @@ func (gs *Game) ListByAuthor(ctx context.Context, author *models.User) ([]*model
func (gs *Game) UpsertGame(ctx context.Context, game *models.Game) (*models.Game, error) {
return game, gs.DB.Debug().
Session(&gorm.Session{FullSaveAssociations: true}).
Save(game).
Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "id"}},
DoUpdates: clause.AssignmentColumns([]string{
"title", "description",
}),
}).
Create(&game).
Error
}