优化
This commit is contained in:
+10
-11
@@ -35,15 +35,6 @@ type UserListFilter struct {
|
||||
Desc bool
|
||||
}
|
||||
|
||||
type Authority struct {
|
||||
AuthorityID uint
|
||||
AuthorityName string
|
||||
ParentID *uint
|
||||
DataScope int
|
||||
DefaultRouter string
|
||||
Children []*Authority
|
||||
}
|
||||
|
||||
type UserRepo interface {
|
||||
FindUserByUsername(context.Context, string) (*User, error)
|
||||
FindUserByID(context.Context, uint) (*User, error)
|
||||
@@ -125,8 +116,16 @@ func (uc *UserUsecase) CreateUser(ctx context.Context, user *User, authorityIDs
|
||||
return uc.repo.CreateUserWithAuthorities(ctx, user, authorityIDs)
|
||||
}
|
||||
func (uc *UserUsecase) UpdateUser(ctx context.Context, user *User, authorityIDs []uint) error {
|
||||
authorityIDs = includeAuthority(authorityIDs, user.AuthorityID)
|
||||
return uc.repo.UpdateUserWithAuthorities(ctx, user, authorityIDs)
|
||||
// Role associations are updated first only when authorityIds was supplied,
|
||||
// and then updates the basic user fields as a separate operation. Preserve
|
||||
// that ordering and partial-failure behavior instead of coupling both writes
|
||||
// into the data-layer transaction used by lower-level callers.
|
||||
if len(authorityIDs) > 0 {
|
||||
if err := uc.repo.SetUserAuthorities(ctx, user.ID, authorityIDs); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return uc.repo.UpdateUser(ctx, user)
|
||||
}
|
||||
|
||||
func (uc *UserUsecase) UpdateSelfUser(ctx context.Context, user *User) error {
|
||||
|
||||
Reference in New Issue
Block a user