diff --git a/backend/app/dto/group.go b/backend/app/dto/group.go index 387d492a2..60179d7ac 100644 --- a/backend/app/dto/group.go +++ b/backend/app/dto/group.go @@ -13,6 +13,7 @@ type GroupSearch struct { type GroupUpdate struct { ID uint `json:"id"` Name string `json:"name"` + Type string `json:"type" validate:"required"` IsDefault bool `json:"isDefault"` } diff --git a/backend/app/repo/group.go b/backend/app/repo/group.go index 1c2afb6a5..de154e02b 100644 --- a/backend/app/repo/group.go +++ b/backend/app/repo/group.go @@ -14,7 +14,7 @@ type IGroupRepo interface { Create(group *model.Group) error Update(id uint, vars map[string]interface{}) error Delete(opts ...DBOption) error - CancelDefault() error + CancelDefault(groupType string) error WithByIsDefault(isDefault bool) DBOption } @@ -64,6 +64,6 @@ func (u *GroupRepo) Delete(opts ...DBOption) error { return db.Delete(&model.Group{}).Error } -func (u *GroupRepo) CancelDefault() error { - return global.DB.Model(&model.Group{}).Where("`is_default` = 1").Updates(map[string]interface{}{"is_default": 0}).Error +func (u *GroupRepo) CancelDefault(groupType string) error { + return global.DB.Model(&model.Group{}).Where("is_default = ? AND type = ?", 1, groupType).Updates(map[string]interface{}{"is_default": 0}).Error } diff --git a/backend/app/service/group.go b/backend/app/service/group.go index 09152281f..11c5f87c4 100644 --- a/backend/app/service/group.go +++ b/backend/app/service/group.go @@ -73,7 +73,7 @@ func (u *GroupService) Delete(id uint) error { func (u *GroupService) Update(req dto.GroupUpdate) error { if req.IsDefault { - if err := groupRepo.CancelDefault(); err != nil { + if err := groupRepo.CancelDefault(req.Type); err != nil { return err } } diff --git a/frontend/src/components/group/index.vue b/frontend/src/components/group/index.vue index bb8735663..5ef57bf91 100644 --- a/frontend/src/components/group/index.vue +++ b/frontend/src/components/group/index.vue @@ -124,6 +124,7 @@ const saveGroup = async (formEl: FormInstance, group: Group.GroupInfo) => { const setDefault = (group: Group.GroupInfo) => { group.isDefault = true; + group.type = type.value; UpdateGroup(group).then(() => { MsgSuccess(i18n.global.t('commons.msg.updateSuccess')); search(); diff --git a/frontend/src/views/login/components/login-form.vue b/frontend/src/views/login/components/login-form.vue index 9f4453f20..bbbd14910 100644 --- a/frontend/src/views/login/components/login-form.vue +++ b/frontend/src/views/login/components/login-form.vue @@ -70,7 +70,7 @@
- +