feat: 完善 user_social / department / 查询单个无条件时直接返回

main
NoahLan 1 year ago
parent bd2b5fe35d
commit 29bb09a130

@ -25,7 +25,30 @@ const (
UserEmailAlreadyExists // 此邮箱已被注册
)
// User
const (
UpdateUserMetaErr code.Code = iota + 1200
)
// Role
const (
RoleCodeNotEmpty code.Code = iota + 1300
RoleCodeInUsed
)
// OAuthProvider
const (
OAuthProviderNameNotEmpty code.Code = iota + 1400
OAuthProviderNameInUsed
)
// UserSocial
const (
UserSocialUserIdNotEmpty code.Code = iota + 1500
)
func init() {
// Common
msg.Add(WrongCode, "auth.wrongCode")
msg.Add(WrongCaptcha, "auth.wrongCaptcha")
msg.Add(WrongPassword, "auth.wrongPassword")
@ -33,10 +56,25 @@ func init() {
msg.Add(NeedPhoneOrEmail, "auth.needPhoneOrEmail")
msg.Add(UnsupportedLoginType, "auth.unsupportedLoginType")
// User Register
msg.Add(UsernameAlreadyExists, "register.user.usernameExists")
msg.Add(PasswordInvalidArgument, "register.user.passwordInvalid")
msg.Add(UserPhoneNumberAlreadyExists, "register.user.phoneNumberExists")
msg.Add(UserExists, "register.user.exists")
msg.Add(UserNicknameAlreadyExists, "register.user.nicknameExists")
msg.Add(UserEmailAlreadyExists, "register.user.emailExists")
// User
msg.Add(UpdateUserMetaErr, "user.updateMetaErr")
// Role
msg.Add(RoleCodeNotEmpty, "role.codeNotEmpty")
msg.Add(RoleCodeInUsed, "role.codeInUsed")
// OAuthProvider
msg.Add(OAuthProviderNameNotEmpty, "oauthProvider.nameNotEmpty")
msg.Add(OAuthProviderNameInUsed, "oauthProvider.nameInUsed")
// UserSocial
msg.Add(UserSocialUserIdNotEmpty, "userSocial.userIdNotEmpty")
}

@ -1,16 +0,0 @@
package errx
import (
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/code"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/msg"
)
const (
RoleCodeNotEmpty code.Code = iota + 3000
RoleCodeInUsed
)
func init() {
msg.Add(RoleCodeNotEmpty, "role.codeNotEmpty")
msg.Add(RoleCodeInUsed, "role.codeInUsed")
}

@ -1,14 +0,0 @@
package errx
import (
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/code"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/msg"
)
const (
UpdateUserMetaErr code.Code = iota + 2000
)
func init() {
msg.Add(UpdateUserMetaErr, "user.updateMetaErr")
}

@ -43,5 +43,12 @@
"role": {
"codeNotEmpty": "角色代码不能为空",
"codeInUsed": "角色代码已被使用"
},
"oauthProvider": {
"nameNotEmpty": "提供商名称不能为空",
"nameInUsed": "提供商名称已被使用"
},
"userSocial": {
"userIdNotEmpty": "用户ID不能为空"
}
}

@ -44,7 +44,7 @@ func (Dictionary) Edges() []ent.Edge {
func (Dictionary) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.WithComments(true),
entsql.Annotation{Table: "sys_dictionaries"},
entsql.Annotation{Table: "sys_dictionary"},
schema.Comment("字典表"),
}
}

@ -2,6 +2,12 @@ package department
import (
"context"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils/entx"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils/hander"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/code"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/msg"
"git.noahlan.cn/noahlan/ntool-biz/core/orm/nent/types"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/svc"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core"
@ -21,7 +27,38 @@ func NewCreateDepartmentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
// Role management
func (l *CreateDepartmentLogic) CreateDepartment(in *core.DepartmentInfo) (*core.BaseIDResp, error) {
// todo: add your logic here and delete this line
var id int64
if err := entx.WithTx(l.ctx, l.svcCtx.DB, func(tx *ent.Tx) error {
if err := l.preCheck(tx); err != nil {
return err
}
create := tx.Department.Create().
SetStatus(types.ParseStatus(in.Status)).
SetName(in.Name).
SetRemark(in.Remark)
if in.LeaderId != 0 {
create.SetLeaderID(in.LeaderId)
}
if in.ParentId != 0 {
create.SetParentID(in.ParentId)
}
dbData, err := create.Save(l.ctx)
if err != nil {
return hander.HandleEntErr(err, in)
}
id = dbData.ID
return nil
}); err != nil {
return nil, err
}
return &core.BaseIDResp{
ID: id,
Code: code.StatusOK,
Msg: msg.CreateSuccess,
}, nil
}
return &core.BaseIDResp{}, nil
func (l *CreateDepartmentLogic) preCheck(tx *ent.Tx) error {
return nil
}

@ -2,6 +2,10 @@ package department
import (
"context"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/department"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils/hander"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/code"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/msg"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/svc"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core"
@ -20,7 +24,15 @@ func NewDeleteDepartmentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
}
func (l *DeleteDepartmentLogic) DeleteDepartment(in *core.IDsReq) (*core.BaseResp, error) {
// todo: add your logic here and delete this line
_, err := l.svcCtx.DB.Department.Delete().
Where(department.IDIn(in.Ids...)).
Exec(l.ctx)
if err != nil {
return nil, hander.HandleEntErr(err, in)
}
return &core.BaseResp{}, nil
return &core.BaseResp{
Code: code.StatusOK,
Msg: msg.DeleteSuccess,
}, nil
}

@ -2,6 +2,11 @@ package department
import (
"context"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/department"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/predicate"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils/hander"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/svc"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core"
@ -20,7 +25,51 @@ func NewGetDepartmentListLogic(ctx context.Context, svcCtx *svc.ServiceContext)
}
func (l *GetDepartmentListLogic) GetDepartmentList(in *core.DepartmentReq) (*core.DepartmentListResp, error) {
// todo: add your logic here and delete this line
var predicates []predicate.Department
if in.ID != 0 {
predicates = append(predicates, department.IDEQ(in.ID))
goto Query
}
if in.Name != "" {
predicates = append(predicates, department.NameContains(in.Name))
}
Query:
query := l.svcCtx.DB.Department.Query().Where(predicates...)
if in.WithUser {
query.WithUsers()
}
if in.WithLeader {
query.WithLeader()
}
if in.WithChildren {
query.WithChildren()
}
var (
pagination *core.Pagination
list []*ent.Department
err error
)
if in.Page != nil {
result, pageErr := query.Page(l.ctx, in.Page.Current, in.Page.Size)
if pageErr == nil {
pagination = utils.ConvertPaginationDb(result.PageDetails)
list = result.List
} else {
err = pageErr
}
} else {
list, err = query.All(l.ctx)
}
if err != nil {
return nil, hander.HandleEntErr(err, in)
}
resp := &core.DepartmentListResp{
Page: pagination,
Data: make([]*core.DepartmentInfo, len(list)),
}
return &core.DepartmentListResp{}, nil
for i, v := range list {
resp.Data[i] = l.svcCtx.Convert.ConvertDepartmentRpc(l.ctx, v)
}
return resp, nil
}

@ -2,6 +2,9 @@ package department
import (
"context"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/department"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/predicate"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils/hander"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/svc"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core"
@ -20,7 +23,33 @@ func NewGetDepartmentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Get
}
func (l *GetDepartmentLogic) GetDepartment(in *core.DepartmentReq) (*core.DepartmentInfo, error) {
// todo: add your logic here and delete this line
return &core.DepartmentInfo{}, nil
var predicates []predicate.Department
if in.ID != 0 {
predicates = append(predicates, department.IDEQ(in.ID))
goto Query
}
if in.Name != "" {
predicates = append(predicates, department.NameEQ(in.Name))
}
// 无条件不查询
if len(predicates) == 0 {
return nil, nil
}
Query:
query := l.svcCtx.DB.Department.Query().Where(predicates...)
if in.WithUser {
query.WithUsers()
}
if in.WithLeader {
query.WithLeader()
}
if in.WithChildren {
query.WithChildren()
}
dbData, err := query.First(l.ctx)
if err != nil {
return nil, hander.HandleEntErr(err, in)
}
resp := l.svcCtx.Convert.ConvertDepartmentRpc(l.ctx, dbData)
return resp, nil
}

@ -2,6 +2,10 @@ package department
import (
"context"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils/hander"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/code"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/msg"
"git.noahlan.cn/noahlan/ntool-biz/core/orm/nent/types"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/svc"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core"
@ -20,7 +24,27 @@ func NewUpdateDepartmentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
}
func (l *UpdateDepartmentLogic) UpdateDepartment(in *core.DepartmentInfo) (*core.BaseResp, error) {
// todo: add your logic here and delete this line
update := l.svcCtx.DB.Department.Update()
update.SetNotEmptyName(in.Name).
SetNotEmptyRemark(in.Remark)
if in.Status != "" {
update.SetStatus(types.ParseStatus(in.Status))
}
if in.LeaderId != 0 {
update.ClearLeader()
update.SetLeaderID(in.LeaderId)
}
if in.ParentId != 0 {
update.ClearParent()
update.SetParentID(in.ParentId)
}
err := update.Exec(l.ctx)
if err != nil {
return nil, hander.HandleEntErr(err, in)
}
return &core.BaseResp{}, nil
return &core.BaseResp{
Code: code.StatusOK,
Msg: msg.UpdateSuccess,
}, nil
}

@ -2,7 +2,12 @@ package oauth_provider
import (
"context"
"git.noahlan.cn/n-admin/n-admin-server/dal/errx"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/oauthprovider"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils/entx"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils/hander"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/code"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/msg"
@ -24,27 +29,53 @@ func NewCreateOauthProviderLogic(ctx context.Context, svcCtx *svc.ServiceContext
// OauthProvider management
func (l *CreateOauthProviderLogic) CreateOauthProvider(in *core.OauthProviderInfo) (*core.BaseIDResp, error) {
create := l.svcCtx.DB.OauthProvider.Create().
SetName(in.Name).
SetClientID(in.ClientId).
SetClientSecret(in.ClientSecret).
SetRedirectURL(in.RedirectUrl).
SetScopes(in.Scopes).
SetAuthURL(in.AuthUrl).
SetTokenURL(in.TokenUrl).
SetInfoURL(in.InfoUrl).
SetDescription(in.Description).
SetSystem(in.System)
if in.ClientId != "" && in.ClientSecret != "" {
create.SetInit(true)
}
result, err := create.Save(l.ctx)
if err != nil {
return nil, hander.HandleEntErr(err, in)
var dbData *ent.OauthProvider
if err := entx.WithTx(l.ctx, l.svcCtx.DB, func(tx *ent.Tx) error {
var err error
if err := l.preCheck(tx, in); err != nil {
return err
}
create := tx.OauthProvider.Create().
SetName(in.Name).
SetClientID(in.ClientId).
SetClientSecret(in.ClientSecret).
SetRedirectURL(in.RedirectUrl).
SetScopes(in.Scopes).
SetAuthURL(in.AuthUrl).
SetTokenURL(in.TokenUrl).
SetInfoURL(in.InfoUrl).
SetDescription(in.Description).
SetSystem(in.System)
if in.ClientId != "" && in.ClientSecret != "" {
create.SetInit(true)
}
dbData, err = create.Save(l.ctx)
if err != nil {
return hander.HandleEntErr(err, in)
}
return nil
}); err != nil {
return nil, err
}
return &core.BaseIDResp{
ID: result.ID,
ID: dbData.ID,
Code: code.StatusOK,
Msg: msg.CreateSuccess,
}, nil
}
func (l *CreateOauthProviderLogic) preCheck(tx *ent.Tx, in *core.OauthProviderInfo) error {
if in.Name == "" {
return nstatus.NewBizErrWithCode(errx.OAuthProviderNameNotEmpty)
} else {
exist, err := tx.OauthProvider.Query().Where(oauthprovider.NameEQ(in.Name)).Exist(l.ctx)
if err != nil {
return hander.HandleEntErr(err, in)
}
if exist {
return nstatus.NewBizErrWithCode(errx.OAuthProviderNameInUsed)
}
}
return nil
}

@ -41,6 +41,9 @@ func (l *GetOauthProviderLogic) GetOauthProvider(in *core.OauthProviderReq) (*co
if in.Init != nil {
predicates = append(predicates, oauthprovider.InitEQ(in.GetInit()))
}
if len(predicates) == 0 {
return nil, nil
}
Query:
dbData, err := l.svcCtx.DB.OauthProvider.Query().
Where(predicates...).

@ -34,6 +34,9 @@ func (l *GetRoleLogic) GetRole(in *core.RoleReq) (*core.RoleInfo, error) {
if in.Code != "" {
predicates = append(predicates, role.CodeEQ(in.Code))
}
if len(predicates) == 0 {
return nil, nil
}
Query:
query := l.svcCtx.DB.Role.Query().Where(predicates...)
if in.WithUser {

@ -40,6 +40,9 @@ func (l *GetUserLogic) GetUser(in *core.UserReq) (*core.UserInfo, error) {
if in.Nickname != "" {
predicates = append(predicates, user.NicknameEQ(in.Nickname))
}
if len(predicates) == 0 {
return nil, nil
}
Query:
query := l.svcCtx.DB.User.Query().
Where(predicates...).

@ -2,9 +2,15 @@ package user_social
import (
"context"
"git.noahlan.cn/n-admin/n-admin-server/dal/errx"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/svc"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils/entx"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils/hander"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/code"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/msg"
)
type CreateUserSocialLogic struct {
@ -21,7 +27,43 @@ func NewCreateUserSocialLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
// User Management
func (l *CreateUserSocialLogic) CreateUserSocial(in *core.UserSocialInfo) (*core.BaseIDResp, error) {
// todo: add your logic here and delete this line
var dbData *ent.UserSocial
if err := entx.WithTx(l.ctx, l.svcCtx.DB, func(tx *ent.Tx) error {
var err error
if err := l.preCheck(tx, in); err != nil {
return err
}
create := tx.UserSocial.Create()
create.SetProvider(in.Provider).
SetAccessToken(in.AccessToken).
SetRefreshToken(in.RefreshToken).
SetUID(in.Uid).
SetOpenID(in.OpenId).
SetUnionID(in.UnionId).
SetKey(in.Key).
SetExpiresIn(in.ExpiresIn).
SetUserProfile(in.UserProfile)
if in.UserId != 0 {
create.SetUserID(in.UserId)
}
dbData, err = create.Save(l.ctx)
if err != nil {
return hander.HandleEntErr(err, in)
}
return nil
}); err != nil {
return nil, err
}
return &core.BaseIDResp{
ID: dbData.ID,
Code: code.StatusOK,
Msg: msg.CreateSuccess,
}, nil
}
return &core.BaseIDResp{}, nil
func (l *CreateUserSocialLogic) preCheck(tx *ent.Tx, in *core.UserSocialInfo) error {
if in.UserId == 0 {
return nstatus.NewBizErrWithCode(errx.UserSocialUserIdNotEmpty)
}
return nil
}

@ -2,6 +2,10 @@ package user_social
import (
"context"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/usersocial"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils/hander"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/code"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/msg"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/svc"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core"
@ -20,7 +24,12 @@ func NewDeleteUserSocialLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
}
func (l *DeleteUserSocialLogic) DeleteUserSocial(in *core.IDsReq) (*core.BaseResp, error) {
// todo: add your logic here and delete this line
return &core.BaseResp{}, nil
_, err := l.svcCtx.DB.UserSocial.Delete().Where(usersocial.IDIn(in.Ids...)).Exec(l.ctx)
if err != nil {
return nil, hander.HandleEntErr(err, in)
}
return &core.BaseResp{
Code: code.StatusOK,
Msg: msg.DeleteSuccess,
}, nil
}

@ -2,6 +2,11 @@ package user_social
import (
"context"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/predicate"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/usersocial"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils/hander"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/svc"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core"
@ -20,7 +25,60 @@ func NewGetUserSocialListLogic(ctx context.Context, svcCtx *svc.ServiceContext)
}
func (l *GetUserSocialListLogic) GetUserSocialList(in *core.UserSocialReq) (*core.UserSocialListResp, error) {
// todo: add your logic here and delete this line
var predicates []predicate.UserSocial
if in.ID != 0 {
predicates = append(predicates, usersocial.IDEQ(in.ID))
goto Query
}
if in.UserId != 0 {
predicates = append(predicates, usersocial.UserIDEQ(in.UserId))
}
if in.Provider != "" {
predicates = append(predicates, usersocial.ProviderEQ(in.Provider))
}
if in.AccessToken != "" {
predicates = append(predicates, usersocial.AccessTokenEQ(in.AccessToken))
}
if in.Uid != "" {
predicates = append(predicates, usersocial.UIDEQ(in.Uid))
}
if in.OpenId != "" {
predicates = append(predicates, usersocial.OpenID(in.OpenId))
}
if in.UnionId != "" {
predicates = append(predicates, usersocial.UnionIDEQ(in.UnionId))
}
Query:
query := l.svcCtx.DB.UserSocial.Query().Where(predicates...)
if in.WithUser {
query.WithUser()
}
var (
pagination *core.Pagination
list []*ent.UserSocial
err error
)
if in.Page != nil {
result, pageErr := query.Page(l.ctx, in.Page.Current, in.Page.Size)
if pageErr == nil {
pagination = utils.ConvertPaginationDb(result.PageDetails)
list = result.List
} else {
err = pageErr
}
} else {
list, err = query.All(l.ctx)
}
if err != nil {
return nil, hander.HandleEntErr(err, in)
}
resp := &core.UserSocialListResp{
Page: pagination,
Data: make([]*core.UserSocialInfo, len(list)),
}
return &core.UserSocialListResp{}, nil
for i, v := range list {
resp.Data[i] = l.svcCtx.Convert.ConvertUserSocialRpc(l.ctx, v)
}
return resp, nil
}

@ -2,6 +2,9 @@ package user_social
import (
"context"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/predicate"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/usersocial"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils/hander"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/svc"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core"
@ -20,7 +23,40 @@ func NewGetUserSocialLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Get
}
func (l *GetUserSocialLogic) GetUserSocial(in *core.UserSocialReq) (*core.UserSocialInfo, error) {
// todo: add your logic here and delete this line
return &core.UserSocialInfo{}, nil
var predicates []predicate.UserSocial
if in.ID != 0 {
predicates = append(predicates, usersocial.IDEQ(in.ID))
goto Query
}
if in.UserId != 0 {
predicates = append(predicates, usersocial.UserIDEQ(in.UserId))
}
if in.Provider != "" {
predicates = append(predicates, usersocial.ProviderEQ(in.Provider))
}
if in.AccessToken != "" {
predicates = append(predicates, usersocial.AccessTokenEQ(in.AccessToken))
}
if in.Uid != "" {
predicates = append(predicates, usersocial.UIDEQ(in.Uid))
}
if in.OpenId != "" {
predicates = append(predicates, usersocial.OpenID(in.OpenId))
}
if in.UnionId != "" {
predicates = append(predicates, usersocial.UnionIDEQ(in.UnionId))
}
if len(predicates) == 0 {
return nil, nil
}
Query:
query := l.svcCtx.DB.UserSocial.Query().Where(predicates...)
if in.WithUser {
query.WithUser()
}
dbData, err := query.First(l.ctx)
if err != nil {
return nil, hander.HandleEntErr(err, in)
}
return l.svcCtx.Convert.ConvertUserSocialRpc(l.ctx, dbData), nil
}

@ -2,6 +2,10 @@ package user_social
import (
"context"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/usersocial"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils/hander"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/code"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/msg"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/svc"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core"
@ -20,7 +24,21 @@ func NewUpdateUserSocialLogic(ctx context.Context, svcCtx *svc.ServiceContext) *
}
func (l *UpdateUserSocialLogic) UpdateUserSocial(in *core.UserSocialInfo) (*core.BaseResp, error) {
// todo: add your logic here and delete this line
return &core.BaseResp{}, nil
update := l.svcCtx.DB.UserSocial.Update().Where(usersocial.IDEQ(in.ID))
update.SetNotEmptyProvider(in.Provider).
SetNotEmptyAccessToken(in.AccessToken).
SetNotEmptyRefreshToken(in.RefreshToken).
SetNotEmptyUID(in.Uid).
SetNotEmptyOpenID(in.OpenId).
SetNotEmptyUnionID(in.UnionId).
SetNotEmptyKey(in.Key).
SetExpiresIn(in.ExpiresIn)
err := update.Exec(l.ctx)
if err != nil {
return nil, hander.HandleEntErr(err, in)
}
return &core.BaseResp{
Code: code.StatusOK,
Msg: msg.UpdateSuccess,
}, nil
}

@ -76,7 +76,7 @@ func (c *Convert) ConvertUserRpc(ctx context.Context, v *ent.User) *core.UserInf
if len(v.Edges.Socials) > 0 {
tmp.Socials = make([]*core.UserSocialInfo, len(v.Edges.Socials))
for i, item := range v.Edges.Socials {
tmp.Socials[i] = c.ConvertSocialRpc(ctx, item)
tmp.Socials[i] = c.ConvertUserSocialRpc(ctx, item)
}
}
@ -99,7 +99,7 @@ func (c *Convert) ConvertTokenRpc(ctx context.Context, v *ent.Token) *core.Token
return &tmp
}
func (c *Convert) ConvertSocialRpc(ctx context.Context, v *ent.UserSocial) *core.UserSocialInfo {
func (c *Convert) ConvertUserSocialRpc(ctx context.Context, v *ent.UserSocial) *core.UserSocialInfo {
if v == nil {
return nil
}

Loading…
Cancel
Save