MCPcopy Index your code
hub / github.com/go-dev-frame/sponge / Create

Method Create

internal/service/userExample.go:50–72  ·  view source on GitHub ↗

Create a new userExample

(ctx context.Context, req *serverNameExampleV1.CreateUserExampleRequest)

Source from the content-addressed store, hash-verified

48
49// Create a new userExample
50func (s *userExample) Create(ctx context.Context, req *serverNameExampleV1.CreateUserExampleRequest) (*serverNameExampleV1.CreateUserExampleReply, error) {
51 err := req.Validate()
52 if err != nil {
53 logger.Warn("req.Validate error", logger.Err(err), logger.Any("req", req), interceptor.ServerCtxRequestIDField(ctx))
54 return nil, ecode.StatusInvalidParams.Err()
55 }
56 ctx = interceptor.WrapServerCtx(ctx)
57
58 record := &model.UserExample{}
59 err = copier.Copy(record, req)
60 if err != nil {
61 return nil, ecode.StatusCreateUserExample.Err()
62 }
63 // Note: if copier.Copy cannot assign a value to a field, add it here
64
65 err = s.iDao.Create(ctx, record)
66 if err != nil {
67 logger.Error("Create error", logger.Err(err), logger.Any("userExample", record), interceptor.ServerCtxRequestIDField(ctx))
68 return nil, ecode.StatusInternalServerError.ToRPCErr()
69 }
70
71 return &serverNameExampleV1.CreateUserExampleReply{Id: record.ID}, nil
72}
73
74// DeleteByID delete a userExample by id
75func (s *userExample) DeleteByID(ctx context.Context, req *serverNameExampleV1.DeleteUserExampleByIDRequest) (*serverNameExampleV1.DeleteUserExampleByIDReply, error) {

Callers

nothing calls this directly

Calls 11

WarnFunction · 0.92
ErrFunction · 0.92
AnyFunction · 0.92
ServerCtxRequestIDFieldFunction · 0.92
WrapServerCtxFunction · 0.92
CopyFunction · 0.92
ErrorFunction · 0.92
ToRPCErrMethod · 0.80
ValidateMethod · 0.65
CreateMethod · 0.65
ErrMethod · 0.45

Tested by

no test coverage detected