58 lines
1.6 KiB
Go
58 lines
1.6 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"juwan-backend/app/user_verifications/rpc/internal/models/schema"
|
|
|
|
"juwan-backend/app/user_verifications/rpc/internal/svc"
|
|
"juwan-backend/app/user_verifications/rpc/pb"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type UpdateUserVerificationsLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewUpdateUserVerificationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserVerificationsLogic {
|
|
return &UpdateUserVerificationsLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *UpdateUserVerificationsLogic) UpdateUserVerifications(in *pb.UpdateUserVerificationsReq) (*pb.UpdateUserVerificationsResp, error) {
|
|
var materials *schema.MaterialStruct
|
|
materials = nil
|
|
if in.Materials != nil {
|
|
err := json.Unmarshal([]byte(*in.Materials), &materials)
|
|
if err != nil {
|
|
logx.Errorf("Unmarshal materials failed, err:%v.", err)
|
|
return nil, errors.New("bad input materials")
|
|
}
|
|
if len(materials.GameScreenshots) > 20 {
|
|
logx.Errorf("User %v upload oo many game screenshots: %d", in.UserId, len(materials.GameScreenshots))
|
|
return nil, errors.New("too many game screenshots")
|
|
}
|
|
}
|
|
|
|
_, err := l.svcCtx.UserVeriModelRW.UpdateOneID(in.Id).
|
|
SetNillableRejectReason(in.RejectReason).
|
|
SetNillableMaterials(materials).
|
|
SetNillableRole(in.Role).
|
|
SetNillableStatus(in.Status).
|
|
SetReviewedBy(in.ReviewedBy).
|
|
Save(l.ctx)
|
|
if err != nil {
|
|
logx.Errorf("save user verifications failed, err:%v.", err)
|
|
return nil, errors.New("save user verifications failed")
|
|
}
|
|
|
|
return &pb.UpdateUserVerificationsResp{}, nil
|
|
}
|