组织添加用户

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 package repo
import ( import (
"context"
"time" "time"
"github.com/samber/do" "github.com/samber/do"
@ -29,7 +30,9 @@ func (m *UserOrganization) TableName() string {
} }
type UserOrganizationRepo interface{ 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{ type userOrganizationRepo struct{
@ -41,3 +44,15 @@ func NewUserOrganizationRepo(i *do.Injector)(UserOrganizationRepo,error){
db:do.MustInvoke[*gorm.DB](i), db:do.MustInvoke[*gorm.DB](i),
},nil },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 EnableOrganization(ctx context.Context, info *orgModel.EnableOrgReq) error
AddUser(ctx context.Context, info *orgModel.AddUsersReq) error AddUser(ctx context.Context, info *orgModel.AddUsersReq) error
RemoveUser(ctx context.Context, info *orgModel.RemoveUsersReq) 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 { 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 return nil
} }
@ -195,6 +204,6 @@ func (o *organizationService) RemoveUser(ctx context.Context, info *orgModel.Rem
return nil 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 return nil, nil
} }

View File

@ -4,6 +4,7 @@ import (
"context" "context"
orgModel "busniess-user-center/internal/models/organization" orgModel "busniess-user-center/internal/models/organization"
userModel "busniess-user-center/internal/models/user"
organizationService "busniess-user-center/internal/service/organization" organizationService "busniess-user-center/internal/service/organization"
ginUtil "busniess-user-center/pkg/utils/gin" ginUtil "busniess-user-center/pkg/utils/gin"
@ -38,6 +39,9 @@ func RegisterRoute(api *gin.RouterGroup) {
api.GET("/orgs", ginUtil.WrapNoReq(server.OrganizationTree)) api.GET("/orgs", ginUtil.WrapNoReq(server.OrganizationTree))
api.POST("/disenable", ginUtil.WrapNoRsp(server.DisableOrganization)) api.POST("/disenable", ginUtil.WrapNoRsp(server.DisableOrganization))
api.POST("/enable", ginUtil.WrapNoRsp(server.EnableOrganization)) 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) { 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 { func (u *OrganizationServer) AddUsers(ctx context.Context, info *orgModel.AddUsersReq) error {
return u.organizationService.AddUser(ctx, info)
// todo
return nil
} }
func (u *OrganizationServer) RemoveUsers(ctx context.Context, info *orgModel.RemoveUsersReq) error { func (u *OrganizationServer) RemoveUsers(ctx context.Context, info *orgModel.RemoveUsersReq) error {
// todo return u.organizationService.RemoveUser(ctx, info)
return nil }
func (u *OrganizationServer) SearchOrgUsers(ctx context.Context, query *orgModel.SearchOrgUserReq) ([]userModel.UserInfo, error) {
return u.organizationService.SearchOrgUsers(ctx, query)
} }