Skip to content

Commit 935bdd2

Browse files
committed
feat: update set layout API
1 parent 91c79ce commit 935bdd2

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

services/core/api/user_layout.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ type ChangePrivacyRequest struct {
1010
IsPrivate bool `json:"is_private"`
1111
}
1212

13-
type SetUserLayout struct {
13+
type SetUserLayoutRequest struct {
1414
UserID string `json:"user_id"`
1515
LayoutConfig []map[string]any `json:"layout_config"`
16+
Name string `json:"name"`
17+
IsPrivate bool `json:"is_private"`
1618
}

services/core/db/metadata-db.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,11 @@ func (db Database) GetUserLayout(userID string) (*models.UserLayout, error) {
158158
}
159159
// set user layout
160160
func (db Database) SetUserLayout( layoutConfig models.UserLayout) error {
161-
err:= db.orm.Model(&models.UserLayout{}).
162-
Where("user_id = ?", layoutConfig.UserID).Update("layout_config", layoutConfig.LayoutConfig).Error
161+
err := db.orm.Clauses(clause.OnConflict{
162+
Columns: []clause.Column{{Name: "user_id"}},
163+
DoUpdates: clause.AssignmentColumns([]string{"layout_config", "name", "is_private"}),
164+
}).Create(&layoutConfig).Error
163165
if err != nil {
164-
if errors.Is(err, gorm.ErrRecordNotFound) {
165-
return err
166-
}
167166
return err
168167
}
169168
return nil

services/core/http_routes.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,7 @@ func (h HttpHandler) GetUserLayout(echoCtx echo.Context) error {
16051605

16061606
}
16071607
func (h HttpHandler) SetUserLayout(echoCtx echo.Context) error {
1608-
var req api.SetUserLayout
1608+
var req api.SetUserLayoutRequest
16091609
if err := bindValidate(echoCtx, &req); err != nil {
16101610
return err
16111611
}
@@ -1622,6 +1622,8 @@ func (h HttpHandler) SetUserLayout(echoCtx echo.Context) error {
16221622
user_layout := models.UserLayout{
16231623
UserID: userId,
16241624
LayoutConfig: layout_config,
1625+
Name: req.Name,
1626+
IsPrivate: req.IsPrivate,
16251627
}
16261628
err = h.db.SetUserLayout(user_layout)
16271629
if err != nil {

0 commit comments

Comments
 (0)