组织添加用户

This commit is contained in:
guosl 2024-07-31 19:31:02 +08:00
parent c84626960c
commit 88771a470a
4 changed files with 37 additions and 8 deletions

View File

@ -2,6 +2,7 @@
package repo
import (
"context"
"time"
"github.com/samber/do"
@ -29,7 +30,9 @@ func (m *UserOrganization) TableName() string {
}
type UserOrganizationRepo interface{
Create(ctx context.Context,userOrgs []UserOrganization)error
Delete(ctx context.Context,orgId uint,userIds []uint)error
SearchOrgUser(ctx context.Context,orgId uint,query Query)([]User,error)
}
type userOrganizationRepo struct{
@ -40,4 +43,16 @@ func NewUserOrganizationRepo(i *do.Injector)(UserOrganizationRepo,error){
return &userOrganizationRepo{
db:do.MustInvoke[*gorm.DB](i),
},nil
}
func (u *userOrganizationRepo)Create(ctx context.Context,userOrgs []UserOrganization)error{
return u.db.Create(userOrgs).Error
}
func (u *userOrganizationRepo)Delete(ctx context.Context,orgId uint,userIds []uint)error{
return u.db.Where("org_id = ? and user_id in ?",orgId,userIds).Delete(&UserOrganization{}).Error
}
func (u *userOrganizationRepo)SearchOrgUser(ctx context.Context,orgId uint,query Query)([]User,error){
return nil,nil
}

View File

@ -17,5 +17,5 @@ type OrganizationService interface {
EnableOrganization(ctx context.Context, info *orgModel.EnableOrgReq) error
AddUser(ctx context.Context, info *orgModel.AddUsersReq) error
RemoveUser(ctx context.Context, info *orgModel.RemoveUsersReq) error
OrganizationUsers(ctx context.Context, orgId uint) ([]userModel.UserInfo, error)
SearchOrgUsers(ctx context.Context, query *orgModel.SearchOrgUserReq) ([]userModel.UserInfo, error)
}

View File

@ -187,7 +187,16 @@ func (o *organizationService) EnableOrganization(ctx context.Context, info *orgM
}
func (o *organizationService) AddUser(ctx context.Context, info *orgModel.AddUsersReq) error {
org, err := o.orgRepo.GetById(ctx, info.OrgId)
if err != nil && err != gorm.ErrRecordNotFound {
return err
}
if err == gorm.ErrRecordNotFound {
return fmt.Errorf("组织%d不存在", info.OrgId)
}
o.orgRepo.Create()
return nil
}
@ -195,6 +204,6 @@ func (o *organizationService) RemoveUser(ctx context.Context, info *orgModel.Rem
return nil
}
func (o *organizationService) OrganizationUsers(ctx context.Context, orgId uint) ([]userModel.UserInfo, error) {
func (o *organizationService) SearchOrgUsers(ctx context.Context, query *orgModel.SearchOrgUserReq) ([]userModel.UserInfo, error) {
return nil, nil
}

View File

@ -4,6 +4,7 @@ import (
"context"
orgModel "busniess-user-center/internal/models/organization"
userModel "busniess-user-center/internal/models/user"
organizationService "busniess-user-center/internal/service/organization"
ginUtil "busniess-user-center/pkg/utils/gin"
@ -38,6 +39,9 @@ func RegisterRoute(api *gin.RouterGroup) {
api.GET("/orgs", ginUtil.WrapNoReq(server.OrganizationTree))
api.POST("/disenable", ginUtil.WrapNoRsp(server.DisableOrganization))
api.POST("/enable", ginUtil.WrapNoRsp(server.EnableOrganization))
api.POST("/adduser", ginUtil.WrapNoRsp(server.AddUsers))
api.DELETE("/removeuser", ginUtil.WrapNoRsp(server.RemoveUsers))
api.GET("/search_org_user", ginUtil.WrapNoRsp(server.RemoveUsers))
}
func (u *OrganizationServer) Create(ctx context.Context, req *orgModel.CreateOrgReq) (err error) {
@ -74,12 +78,13 @@ func (u *OrganizationServer) EnableOrganization(ctx context.Context, info *orgMo
}
func (u *OrganizationServer) AddUsers(ctx context.Context, info *orgModel.AddUsersReq) error {
// todo
return nil
return u.organizationService.AddUser(ctx, info)
}
func (u *OrganizationServer) RemoveUsers(ctx context.Context, info *orgModel.RemoveUsersReq) error {
// todo
return nil
return u.organizationService.RemoveUser(ctx, info)
}
func (u *OrganizationServer) SearchOrgUsers(ctx context.Context, query *orgModel.SearchOrgUserReq) ([]userModel.UserInfo, error) {
return u.organizationService.SearchOrgUsers(ctx, query)
}