This commit is contained in:
2026-08-16 09:02:39 +08:00
parent c554152f4f
commit f7f6db8695
105 changed files with 2535 additions and 948 deletions
+10 -11
View File
@@ -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 {