Skip to content

Commit

Permalink
update migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkCherepovskyi committed Jan 4, 2024
1 parent 38ae9b3 commit e0dcc21
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
7 changes: 5 additions & 2 deletions docs/spec/components/schemas/Template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ allOf:
- is_completed
- template_name
- template_short_name
- template-id
- template_id
- is_default_template
properties:
template:
type: object
Expand All @@ -36,5 +37,7 @@ allOf:
type: string
template_id:
type: int
format: int64
format: int64
is_default_template:
type: boolean

5 changes: 5 additions & 0 deletions internal/assets/migrations/002_default_template.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- +migrate Up

ALTER TABLE template ADD is_default_template INTEGER;

ALTER TABLE template ADD CONSTRAINT ck_testbool_ischk CHECK (is_default_template IN (1,0));
13 changes: 7 additions & 6 deletions internal/service/api/handlers/create_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func CreateTemplate(w http.ResponseWriter, r *http.Request) {
ape.RenderErr(w, problems.BadRequest(err)...)
return
}

client, err := MasterQ(r).ClientQ().FilterByName(req.Data.Relationships.User.Data.ID).Get()
if err != nil {
Log(r).WithError(err).Error("failed to get client")
Expand All @@ -38,12 +39,12 @@ func CreateTemplate(w http.ResponseWriter, r *http.Request) {
}

err = MasterQ(r).TemplateQ().Insert(&data.Template{
Template: templateBytes,
ImgBytes: []byte(strings.Replace(req.Data.Attributes.BackgroundImg, "data:image/png;base64,", "", 1)),
Name: req.Data.Attributes.TemplateName,
ShortName: req.Data.Attributes.TemplateShortName,
UserID: client.ID,
//IsDefaultTemplate: TODO update
Template: templateBytes,
ImgBytes: []byte(strings.Replace(req.Data.Attributes.BackgroundImg, "data:image/png;base64,", "", 1)),
Name: req.Data.Attributes.TemplateName,
ShortName: req.Data.Attributes.TemplateShortName,
UserID: client.ID,
IsDefaultTemplate: req.Data.Attributes.IsDefaultTemplate,
})
if err != nil {
Log(r).WithError(err).Error("failed to insert template")
Expand Down
3 changes: 2 additions & 1 deletion resources/model_template_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import "encoding/json"
type TemplateAttributes struct {
BackgroundImg string `json:"background_img"`
IsCompleted bool `json:"is_completed"`
IsDefaultTemplate bool `json:"is_default_template"`
Template json.RawMessage `json:"template"`
TemplateId int64 `json:"template_id,omitempty"`
TemplateId int64 `json:"template_id"`
TemplateName string `json:"template_name"`
TemplateShortName string `json:"template_short_name"`
}

0 comments on commit e0dcc21

Please sign in to comment.