From 309be4261ce1b360fa8f147fc4ab9291e39e6adb Mon Sep 17 00:00:00 2001 From: Kang Huquan <799385272@qq.com> Date: Tue, 30 Jul 2019 11:30:26 +0800 Subject: [PATCH 01/12] add tags --- backend/api/content/main.go | 10 +- backend/srv/content/main.go | 191 ++++++++++++++---------- backend/srv/content/proto/content.pb.go | 171 +++++++++++---------- backend/srv/content/proto/content.proto | 6 +- 4 files changed, 218 insertions(+), 160 deletions(-) diff --git a/backend/api/content/main.go b/backend/api/content/main.go index 4bfaad4..f158a2a 100644 --- a/backend/api/content/main.go +++ b/backend/api/content/main.go @@ -141,10 +141,11 @@ func deleteContent(c *gin.Context) { */ func updateContent(c *gin.Context) { type param struct { - ContentID string `form:"contentID" binding:"required"` - ContentToken string `form:"contentToken" binding:"required"` - FileID string `form:"fileID" binding:"required"` - Type int32 `form:"type"` + ContentID string `form:"contentID" binding:"required"` + ContentToken string `form:"contentToken" binding:"required"` + FileID string `form:"fileID" binding:"required"` + Type int32 `form:"type"` + Tags []string `form:"tags" binding:"required"` } var p param role := utils.GetRole(c) @@ -173,6 +174,7 @@ func updateContent(c *gin.Context) { FileID: p.FileID, Content: data, Type: content.ContentUpdateRequest_Type(p.Type), + Tags: p.Tags, }) if utils.LogContinue(err, utils.Warning, "Content service error: %v", err) { c.JSON(500, err) diff --git a/backend/srv/content/main.go b/backend/srv/content/main.go index 7b5ef93..0500016 100644 --- a/backend/srv/content/main.go +++ b/backend/srv/content/main.go @@ -9,9 +9,10 @@ import ( "jiaojiao/utils" "time" + uuid "github.com/satori/go.uuid" + "github.com/h2non/filetype" "github.com/micro/go-micro/client" - uuid "github.com/satori/go.uuid" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" ) @@ -27,12 +28,12 @@ type srv struct{} * * @apiParam {string} [contentID] 24 bytes content id, left empty for first upload * @apiParam {string} [contentToken] content token, left empty for first upload - * @apiParam {bytes} content binary bytes, file accept [image](https://github.com/h2non/filetype#image) and [video](https://github.com/h2non/filetype#video) - * @apiParam {int32} type 1 for picture
2 for video + * @apiParam {bytes} [content] binary bytes, file accept [image](https://github.com/h2non/filetype#image) and [video](https://github.com/h2non/filetype#video) + * @apiParam {int32} [type] 1 for picture
2 for video * @apiSuccess {int32} status -1 for invalid param
1 for success
2 for invalid token
2 for invalid type * @apiSuccess {string} contentID 24 bytes contentID * @apiSuccess {string} contentToken random uuid content token - * @apiSuccess {string} fileID 24 bytes fileID + * @apiSuccess {string} [fileID] 24 bytes fileID, return if content and type not empty * @apiUse DBServerDown */ func (a *srv) Create(ctx context.Context, req *content.ContentCreateRequest, rsp *content.ContentCreateResponse) error { @@ -56,42 +57,55 @@ func (a *srv) Create(ctx context.Context, req *content.ContentCreateRequest, rsp } // check param - if !utils.RequireParam(req.Content, req.Type) { - rsp.Status = content.ContentCreateResponse_INVALID_PARAM - return nil - } - if !utils.CheckInTest() && !filetype.IsImage(req.Content) && !filetype.IsVideo(req.Content) { rsp.Status = content.ContentCreateResponse_INVALID_TYPE return nil } if utils.IsEmpty(req.ContentID) && utils.IsEmpty(req.ContentToken) { // create new - objID, err := upload() - if utils.LogContinue(err, utils.Warning) { - return err - } - token := uuid.NewV4().String() ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() collection := db.MongoDatabase.Collection("sellinfo") - res, err := collection.InsertOne(ctx, bson.M{ - "token": token, - "files": bson.A{ - bson.M{ - "fileID": objID, - "type": req.Type, - }}, - }) - if utils.LogContinue(err, utils.Warning) { - return err - } - rsp.ContentID = res.InsertedID.(primitive.ObjectID).Hex() - rsp.ContentToken = token - rsp.FileID = objID.Hex() - rsp.Status = content.ContentCreateResponse_SUCCESS + if utils.RequireParam(req.Content, req.Type) { // add file + objID, err := upload() + if utils.LogContinue(err, utils.Warning) { + return err + } + + res, err := collection.InsertOne(ctx, bson.M{ + "token": token, + "files": bson.A{ + bson.M{ + "fileID": objID, + "type": req.Type, + }, + }, + "tags": bson.A{}, + }) + if utils.LogContinue(err, utils.Warning) { + return err + } + + rsp.ContentID = res.InsertedID.(primitive.ObjectID).Hex() + rsp.ContentToken = token + rsp.FileID = objID.Hex() + rsp.Status = content.ContentCreateResponse_SUCCESS + } else { // empty content + res, err := collection.InsertOne(ctx, bson.M{ + "token": token, + "files": bson.A{}, + "tags": bson.A{}, + }) + if utils.LogContinue(err, utils.Warning) { + return err + } + + rsp.ContentID = res.InsertedID.(primitive.ObjectID).Hex() + rsp.ContentToken = token + rsp.Status = content.ContentCreateResponse_SUCCESS + } } else if !utils.IsEmpty(req.ContentID) && !utils.IsEmpty(req.ContentToken) { // add exist one if !validCheck(req.ContentID, req.ContentToken) { rsp.Status = content.ContentCreateResponse_INVALID_TOKEN @@ -148,12 +162,13 @@ func (a *srv) Create(ctx context.Context, req *content.ContentCreateRequest, rsp * @apiParam {bytes} [content] binary bytes, file accept [image](https://github.com/h2non/filetype#image) * and [video](https://github.com/h2non/filetype#video) (note: only delete the file if empty) * @apiParam {int32} [type] 1 for picture
2 for video (note: only delete the file if empty) + * @apiParam {array} tags string array tags, simply overwrite original tags, clear if empty * @apiSuccess {int32} status -1 for invalid param
1 for success
2 for invalid token
3 for not found
4 for failed
5 for invalid type * @apiSuccess {string} [fileID] 24 bytes updated file id (note: new file id differs from old one, meaningful only if content and type are not empty) * @apiUse DBServerDown */ func (a *srv) Update(ctx context.Context, req *content.ContentUpdateRequest, rsp *content.ContentUpdateResponse) error { - if !utils.RequireParam(req.ContentID, req.ContentToken, req.FileID) { + if !utils.RequireParam(req.ContentID, req.ContentToken) { rsp.Status = content.ContentUpdateResponse_INVALID_PARAM return nil } @@ -164,7 +179,7 @@ func (a *srv) Update(ctx context.Context, req *content.ContentUpdateRequest, rsp return nil } - //delete old file + //prepare ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() collection := db.MongoDatabase.Collection("sellinfo") @@ -179,63 +194,82 @@ func (a *srv) Update(ctx context.Context, req *content.ContentUpdateRequest, rsp rsp.Status = content.ContentUpdateResponse_NOT_FOUND return nil } - _, err = collection.UpdateOne(ctx, bson.D{ - {"_id", rid}, - {"token", req.ContentToken}, - }, bson.D{ - {"$pull", bson.D{ - {"files", bson.D{ - {"fileID", fid}, - }}, - }}, - }) - if utils.LogContinue(err, utils.Warning) { - rsp.Status = content.ContentUpdateResponse_NOT_FOUND - return nil - } - - srv := utils.CallMicroService("file", func(name string, c client.Client) interface{} { return file.NewFileService(name, c) }, - func() interface{} { return mock.NewFileService() }).(file.FileService) - microDeleteRsp, err := srv.Delete(context.TODO(), &file.FileRequest{ - FileID: req.FileID, - }) - if utils.LogContinue(err, utils.Warning) || microDeleteRsp.Status != file.FileDeleteResponse_SUCCESS { - rsp.Status = content.ContentUpdateResponse_NOT_FOUND - return nil - } - - //add new file - if utils.RequireParam(req.Content, req.Type) { - microCreateRsp, err := srv.Create(context.TODO(), &file.FileCreateRequest{ - File: req.Content, - }) - if utils.LogContinue(err, utils.Warning) || microDeleteRsp.Status != file.FileDeleteResponse_SUCCESS { - rsp.Status = content.ContentUpdateResponse_FAILED - return nil - } - fid, err = primitive.ObjectIDFromHex(microCreateRsp.FileID) - if utils.LogContinue(err, utils.Warning) { - rsp.Status = content.ContentUpdateResponse_FAILED - return nil - } + if utils.RequireParam(req.FileID) { + //delete old file _, err = collection.UpdateOne(ctx, bson.D{ {"_id", rid}, {"token", req.ContentToken}, }, bson.D{ - {"$push", bson.D{ + {"$pull", bson.D{ {"files", bson.D{ {"fileID", fid}, - {"type", req.Type}, }}, }}, }) if utils.LogContinue(err, utils.Warning) { - rsp.Status = content.ContentUpdateResponse_FAILED + rsp.Status = content.ContentUpdateResponse_NOT_FOUND + return nil + } + + srv := utils.CallMicroService("file", func(name string, c client.Client) interface{} { return file.NewFileService(name, c) }, + func() interface{} { return mock.NewFileService() }).(file.FileService) + microDeleteRsp, err := srv.Delete(context.TODO(), &file.FileRequest{ + FileID: req.FileID, + }) + if utils.LogContinue(err, utils.Warning) || microDeleteRsp.Status != file.FileDeleteResponse_SUCCESS { + rsp.Status = content.ContentUpdateResponse_NOT_FOUND return nil } - rsp.FileID = microCreateRsp.FileID + + //add new file + if utils.RequireParam(req.Content, req.Type) { + microCreateRsp, err := srv.Create(context.TODO(), &file.FileCreateRequest{ + File: req.Content, + }) + if utils.LogContinue(err, utils.Warning) || microDeleteRsp.Status != file.FileDeleteResponse_SUCCESS { + rsp.Status = content.ContentUpdateResponse_FAILED + return nil + } + fid, err = primitive.ObjectIDFromHex(microCreateRsp.FileID) + if utils.LogContinue(err, utils.Warning) { + rsp.Status = content.ContentUpdateResponse_FAILED + return nil + } + + _, err = collection.UpdateOne(ctx, bson.D{ + {"_id", rid}, + {"token", req.ContentToken}, + }, bson.D{ + {"$push", bson.D{ + {"files", bson.D{ + {"fileID", fid}, + {"type", req.Type}, + }}, + }}, + }) + if utils.LogContinue(err, utils.Warning) { + rsp.Status = content.ContentUpdateResponse_FAILED + return nil + } + rsp.FileID = microCreateRsp.FileID + } + } + + //update tags + _, err = collection.UpdateOne(ctx, bson.D{ + {"_id", rid}, + {"token", req.ContentToken}, + }, bson.D{ + {"$set", bson.D{ + {"tags", req.Tags}, + }}, + }) + if utils.LogContinue(err, utils.Warning) { + rsp.Status = content.ContentUpdateResponse_FAILED + return nil } + rsp.Status = content.ContentUpdateResponse_SUCCESS return nil } @@ -309,6 +343,7 @@ func (a *srv) Delete(ctx context.Context, req *content.ContentDeleteRequest, rsp * @apiSuccess {int32} status -1 for invalid param
1 for success
2 for not found * @apiSuccess {string} contentToken content token * @apiSuccess {list} files {string} fileID : file id
{int32} type : file type 1 for picture, 2 for video + * @apiSuccess {list} tags {string} tag : tag name * @apiUse DBServerDown */ func (a *srv) Query(ctx context.Context, req *content.ContentQueryRequest, rsp *content.ContentQueryResponse) error { @@ -317,13 +352,14 @@ func (a *srv) Query(ctx context.Context, req *content.ContentQueryRequest, rsp * return nil } type files struct { - FileID primitive.ObjectID `bson:"fileID"` - Type content.ContentMsg_Type `bson:"type"` + FileID primitive.ObjectID `bson:"fileID"` + Type content.FileMsg_Type `bson:"type"` } type result struct { ID primitive.ObjectID `bson:"_id"` Token string `bson:"token"` Files []files `bson:"files"` + Tags []string `bson:"tags"` } ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) @@ -345,11 +381,12 @@ func (a *srv) Query(ctx context.Context, req *content.ContentQueryRequest, rsp * rsp.ContentToken = res.Token for _, v := range res.Files { - rsp.Files = append(rsp.Files, &content.ContentMsg{ + rsp.Files = append(rsp.Files, &content.FileMsg{ FileID: v.FileID.Hex(), Type: v.Type, }) } + rsp.Tags = res.Tags rsp.Status = content.ContentQueryResponse_SUCCESS return nil } diff --git a/backend/srv/content/proto/content.pb.go b/backend/srv/content/proto/content.pb.go index 4acf71f..3f36a75 100644 --- a/backend/srv/content/proto/content.pb.go +++ b/backend/srv/content/proto/content.pb.go @@ -181,31 +181,31 @@ func (ContentDeleteResponse_Status) EnumDescriptor() ([]byte, []int) { return fileDescriptor_61cc9617ce0cf609, []int{5, 0} } -type ContentMsg_Type int32 +type FileMsg_Type int32 const ( - ContentMsg_UNKNOWN ContentMsg_Type = 0 - ContentMsg_PICTURE ContentMsg_Type = 1 - ContentMsg_VIDEO ContentMsg_Type = 2 + FileMsg_UNKNOWN FileMsg_Type = 0 + FileMsg_PICTURE FileMsg_Type = 1 + FileMsg_VIDEO FileMsg_Type = 2 ) -var ContentMsg_Type_name = map[int32]string{ +var FileMsg_Type_name = map[int32]string{ 0: "UNKNOWN", 1: "PICTURE", 2: "VIDEO", } -var ContentMsg_Type_value = map[string]int32{ +var FileMsg_Type_value = map[string]int32{ "UNKNOWN": 0, "PICTURE": 1, "VIDEO": 2, } -func (x ContentMsg_Type) String() string { - return proto.EnumName(ContentMsg_Type_name, int32(x)) +func (x FileMsg_Type) String() string { + return proto.EnumName(FileMsg_Type_name, int32(x)) } -func (ContentMsg_Type) EnumDescriptor() ([]byte, []int) { +func (FileMsg_Type) EnumDescriptor() ([]byte, []int) { return fileDescriptor_61cc9617ce0cf609, []int{6, 0} } @@ -403,6 +403,7 @@ type ContentUpdateRequest struct { FileID string `protobuf:"bytes,3,opt,name=fileID,proto3" json:"fileID,omitempty"` Content []byte `protobuf:"bytes,4,opt,name=content,proto3" json:"content,omitempty"` Type ContentUpdateRequest_Type `protobuf:"varint,5,opt,name=type,proto3,enum=ContentUpdateRequest_Type" json:"type,omitempty"` + Tags []string `protobuf:"bytes,6,rep,name=tags,proto3" json:"tags,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -468,6 +469,13 @@ func (m *ContentUpdateRequest) GetType() ContentUpdateRequest_Type { return ContentUpdateRequest_UNKNOWN } +func (m *ContentUpdateRequest) GetTags() []string { + if m != nil { + return m.Tags + } + return nil +} + type ContentUpdateResponse struct { Status ContentUpdateResponse_Status `protobuf:"varint,1,opt,name=status,proto3,enum=ContentUpdateResponse_Status" json:"status,omitempty"` FileID string `protobuf:"bytes,2,opt,name=fileID,proto3" json:"fileID,omitempty"` @@ -601,51 +609,51 @@ func (m *ContentDeleteResponse) GetStatus() ContentDeleteResponse_Status { return ContentDeleteResponse_UNKNOWN } -type ContentMsg struct { - FileID string `protobuf:"bytes,1,opt,name=fileID,proto3" json:"fileID,omitempty"` - Type ContentMsg_Type `protobuf:"varint,2,opt,name=type,proto3,enum=ContentMsg_Type" json:"type,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` +type FileMsg struct { + FileID string `protobuf:"bytes,1,opt,name=fileID,proto3" json:"fileID,omitempty"` + Type FileMsg_Type `protobuf:"varint,2,opt,name=type,proto3,enum=FileMsg_Type" json:"type,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } -func (m *ContentMsg) Reset() { *m = ContentMsg{} } -func (m *ContentMsg) String() string { return proto.CompactTextString(m) } -func (*ContentMsg) ProtoMessage() {} -func (*ContentMsg) Descriptor() ([]byte, []int) { +func (m *FileMsg) Reset() { *m = FileMsg{} } +func (m *FileMsg) String() string { return proto.CompactTextString(m) } +func (*FileMsg) ProtoMessage() {} +func (*FileMsg) Descriptor() ([]byte, []int) { return fileDescriptor_61cc9617ce0cf609, []int{6} } -func (m *ContentMsg) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ContentMsg.Unmarshal(m, b) +func (m *FileMsg) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_FileMsg.Unmarshal(m, b) } -func (m *ContentMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ContentMsg.Marshal(b, m, deterministic) +func (m *FileMsg) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_FileMsg.Marshal(b, m, deterministic) } -func (m *ContentMsg) XXX_Merge(src proto.Message) { - xxx_messageInfo_ContentMsg.Merge(m, src) +func (m *FileMsg) XXX_Merge(src proto.Message) { + xxx_messageInfo_FileMsg.Merge(m, src) } -func (m *ContentMsg) XXX_Size() int { - return xxx_messageInfo_ContentMsg.Size(m) +func (m *FileMsg) XXX_Size() int { + return xxx_messageInfo_FileMsg.Size(m) } -func (m *ContentMsg) XXX_DiscardUnknown() { - xxx_messageInfo_ContentMsg.DiscardUnknown(m) +func (m *FileMsg) XXX_DiscardUnknown() { + xxx_messageInfo_FileMsg.DiscardUnknown(m) } -var xxx_messageInfo_ContentMsg proto.InternalMessageInfo +var xxx_messageInfo_FileMsg proto.InternalMessageInfo -func (m *ContentMsg) GetFileID() string { +func (m *FileMsg) GetFileID() string { if m != nil { return m.FileID } return "" } -func (m *ContentMsg) GetType() ContentMsg_Type { +func (m *FileMsg) GetType() FileMsg_Type { if m != nil { return m.Type } - return ContentMsg_UNKNOWN + return FileMsg_UNKNOWN } type ContentQueryRequest struct { @@ -690,7 +698,8 @@ func (m *ContentQueryRequest) GetContentID() string { type ContentQueryResponse struct { Status ContentQueryResponse_Status `protobuf:"varint,1,opt,name=status,proto3,enum=ContentQueryResponse_Status" json:"status,omitempty"` ContentToken string `protobuf:"bytes,2,opt,name=contentToken,proto3" json:"contentToken,omitempty"` - Files []*ContentMsg `protobuf:"bytes,3,rep,name=files,proto3" json:"files,omitempty"` + Files []*FileMsg `protobuf:"bytes,3,rep,name=files,proto3" json:"files,omitempty"` + Tags []string `protobuf:"bytes,4,rep,name=tags,proto3" json:"tags,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -735,13 +744,20 @@ func (m *ContentQueryResponse) GetContentToken() string { return "" } -func (m *ContentQueryResponse) GetFiles() []*ContentMsg { +func (m *ContentQueryResponse) GetFiles() []*FileMsg { if m != nil { return m.Files } return nil } +func (m *ContentQueryResponse) GetTags() []string { + if m != nil { + return m.Tags + } + return nil +} + type ContentCheckRequest struct { ContentID string `protobuf:"bytes,1,opt,name=contentID,proto3" json:"contentID,omitempty"` ContentToken string `protobuf:"bytes,2,opt,name=contentToken,proto3" json:"contentToken,omitempty"` @@ -834,7 +850,7 @@ func init() { proto.RegisterEnum("ContentUpdateRequest_Type", ContentUpdateRequest_Type_name, ContentUpdateRequest_Type_value) proto.RegisterEnum("ContentUpdateResponse_Status", ContentUpdateResponse_Status_name, ContentUpdateResponse_Status_value) proto.RegisterEnum("ContentDeleteResponse_Status", ContentDeleteResponse_Status_name, ContentDeleteResponse_Status_value) - proto.RegisterEnum("ContentMsg_Type", ContentMsg_Type_name, ContentMsg_Type_value) + proto.RegisterEnum("FileMsg_Type", FileMsg_Type_name, FileMsg_Type_value) proto.RegisterEnum("ContentQueryResponse_Status", ContentQueryResponse_Status_name, ContentQueryResponse_Status_value) proto.RegisterEnum("ContentCheckResponse_Status", ContentCheckResponse_Status_name, ContentCheckResponse_Status_value) proto.RegisterType((*ContentCreateRequest)(nil), "ContentCreateRequest") @@ -843,7 +859,7 @@ func init() { proto.RegisterType((*ContentUpdateResponse)(nil), "ContentUpdateResponse") proto.RegisterType((*ContentDeleteRequest)(nil), "ContentDeleteRequest") proto.RegisterType((*ContentDeleteResponse)(nil), "ContentDeleteResponse") - proto.RegisterType((*ContentMsg)(nil), "ContentMsg") + proto.RegisterType((*FileMsg)(nil), "FileMsg") proto.RegisterType((*ContentQueryRequest)(nil), "ContentQueryRequest") proto.RegisterType((*ContentQueryResponse)(nil), "ContentQueryResponse") proto.RegisterType((*ContentCheckRequest)(nil), "ContentCheckRequest") @@ -853,44 +869,45 @@ func init() { func init() { proto.RegisterFile("content.proto", fileDescriptor_61cc9617ce0cf609) } var fileDescriptor_61cc9617ce0cf609 = []byte{ - // 609 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x56, 0x4f, 0x6f, 0xda, 0x30, - 0x1c, 0x5d, 0x12, 0x12, 0xc4, 0x0f, 0xa8, 0x3c, 0xaf, 0x54, 0x11, 0xea, 0x24, 0x66, 0xed, 0x80, - 0x34, 0x29, 0x07, 0xda, 0xa9, 0x67, 0x94, 0xa4, 0x52, 0xd4, 0x12, 0x68, 0x80, 0x76, 0x3b, 0x55, - 0x1d, 0xf3, 0xfe, 0xa8, 0x15, 0x30, 0x12, 0x34, 0x71, 0xd9, 0x37, 0xd8, 0x79, 0xd7, 0xed, 0x13, - 0xed, 0x3b, 0xec, 0xb0, 0x7d, 0x8c, 0x4d, 0x71, 0x0c, 0x8e, 0xb3, 0x4c, 0x74, 0x6d, 0xb8, 0xfd, - 0x9c, 0xf7, 0x6c, 0xff, 0xde, 0x7b, 0xb6, 0x81, 0xfa, 0x64, 0x36, 0x8d, 0xe8, 0x34, 0xb2, 0xe6, - 0x8b, 0x59, 0x34, 0x23, 0xdf, 0x15, 0xd8, 0xb5, 0x93, 0x11, 0x7b, 0x41, 0xaf, 0x22, 0x1a, 0xd0, - 0x0f, 0x4b, 0x1a, 0x46, 0x78, 0x1f, 0x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 0x8b, 0x14, 0x57, 0x95, 0x5c, 0x6c, 0x94, 0xb1, 0xdf, 0xd1, 0xc9, 0x75, 0x71, 0x79, 0xfc, - 0x92, 0x7a, 0x9e, 0x92, 0x99, 0xb7, 0xa9, 0x27, 0xc1, 0xb2, 0x69, 0xf4, 0xfe, 0xbf, 0xed, 0xd8, - 0xff, 0xf8, 0x0b, 0x62, 0x0a, 0x70, 0x18, 0x52, 0x3b, 0x5f, 0x55, 0x28, 0xf3, 0x25, 0xf1, 0x11, - 0x18, 0xc9, 0x13, 0x82, 0x1b, 0xb9, 0x6f, 0x59, 0x73, 0x2f, 0xff, 0xa5, 0x89, 0x89, 0xc9, 0x0d, - 0x24, 0x88, 0xd2, 0x55, 0x28, 0x88, 0x99, 0x0b, 0xed, 0x08, 0x8c, 0xe4, 0xdc, 0x09, 0xa2, 0x74, - 0x15, 0x08, 0x62, 0xe6, 0x18, 0x1f, 0x82, 0xce, 0xf2, 0x85, 0x77, 0xad, 0x9c, 0x2c, 0x37, 0x1b, - 0xd6, 0x3f, 0xb2, 0xaa, 0x33, 0x5d, 0x05, 0x2b, 0xed, 0xb3, 0x60, 0x49, 0xe2, 0xbf, 0x32, 0xd8, - 0x5f, 0x8c, 0x83, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x65, 0x02, 0xc4, 0x92, 0x73, 0x08, 0x00, - 0x00, + // 632 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x56, 0xcd, 0x6e, 0xda, 0x40, + 0x10, 0xae, 0x7f, 0xa9, 0x27, 0x21, 0xda, 0x6e, 0x43, 0x64, 0xa1, 0xb4, 0xa2, 0x7b, 0x42, 0xaa, + 0xe4, 0x03, 0x49, 0x95, 0x33, 0xb2, 0x8d, 0x64, 0x25, 0x18, 0x62, 0x20, 0x69, 0x4f, 0x11, 0xa5, + 0xdb, 0x34, 0x0a, 0x02, 0x82, 0xcd,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 0x17, 0xf3, 0x6a, 0x09, 0xaf, 0x3c, 0x2b, 0xab, + 0x33, 0xcf, 0x12, 0xc8, 0x7f, 0xab, 0x27, 0xff, 0x40, 0x8e, 0x7e, 0x07, 0x00, 0x00, 0xff, 0xff, + 0xeb, 0x19, 0xe9, 0xd3, 0x92, 0x08, 0x00, 0x00, } diff --git a/backend/srv/content/proto/content.proto b/backend/srv/content/proto/content.proto index 55b4e12..46b6f40 100644 --- a/backend/srv/content/proto/content.proto +++ b/backend/srv/content/proto/content.proto @@ -45,6 +45,7 @@ message ContentUpdateRequest { string fileID = 3; bytes content = 4; Type type = 5; + repeated string tags = 6; } message ContentUpdateResponse { @@ -76,7 +77,7 @@ message ContentDeleteResponse { Status status = 1; } -message ContentMsg { +message FileMsg { enum Type { UNKNOWN = 0; PICTURE = 1; @@ -99,7 +100,8 @@ message ContentQueryResponse { } Status status = 1; string contentToken = 2; - repeated ContentMsg files = 3; + repeated FileMsg files = 3; + repeated string tags = 4; } message ContentCheckRequest { From 231bc69b3211c3db878ac7f19dfcca17a7b844a8 Mon Sep 17 00:00:00 2001 From: Kang Huquan <799385272@qq.com> Date: Tue, 30 Jul 2019 15:56:08 +0800 Subject: [PATCH 02/12] Revert part of "add tags" This reverts commit 309be426 --- backend/srv/content/main.go | 69 +++++++++++++++---------------------- 1 file changed, 28 insertions(+), 41 deletions(-) diff --git a/backend/srv/content/main.go b/backend/srv/content/main.go index 0500016..361fd89 100644 --- a/backend/srv/content/main.go +++ b/backend/srv/content/main.go @@ -28,12 +28,12 @@ type srv struct{} * * @apiParam {string} [contentID] 24 bytes content id, left empty for first upload * @apiParam {string} [contentToken] content token, left empty for first upload - * @apiParam {bytes} [content] binary bytes, file accept [image](https://github.com/h2non/filetype#image) and [video](https://github.com/h2non/filetype#video) - * @apiParam {int32} [type] 1 for picture
2 for video + * @apiParam {bytes} content binary bytes, file accept [image](https://github.com/h2non/filetype#image) and [video](https://github.com/h2non/filetype#video) + * @apiParam {int32} type 1 for picture
2 for video * @apiSuccess {int32} status -1 for invalid param
1 for success
2 for invalid token
2 for invalid type * @apiSuccess {string} contentID 24 bytes contentID * @apiSuccess {string} contentToken random uuid content token - * @apiSuccess {string} [fileID] 24 bytes fileID, return if content and type not empty + * @apiSuccess {string} fileID 24 bytes fileID * @apiUse DBServerDown */ func (a *srv) Create(ctx context.Context, req *content.ContentCreateRequest, rsp *content.ContentCreateResponse) error { @@ -57,55 +57,42 @@ func (a *srv) Create(ctx context.Context, req *content.ContentCreateRequest, rsp } // check param + if !utils.RequireParam(req.Content, req.Type) { + rsp.Status = content.ContentCreateResponse_INVALID_PARAM + return nil + } + if !utils.CheckInTest() && !filetype.IsImage(req.Content) && !filetype.IsVideo(req.Content) { rsp.Status = content.ContentCreateResponse_INVALID_TYPE return nil } if utils.IsEmpty(req.ContentID) && utils.IsEmpty(req.ContentToken) { // create new + objID, err := upload() + if utils.LogContinue(err, utils.Warning) { + return err + } + token := uuid.NewV4().String() ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() collection := db.MongoDatabase.Collection("sellinfo") - - if utils.RequireParam(req.Content, req.Type) { // add file - objID, err := upload() - if utils.LogContinue(err, utils.Warning) { - return err - } - - res, err := collection.InsertOne(ctx, bson.M{ - "token": token, - "files": bson.A{ - bson.M{ - "fileID": objID, - "type": req.Type, - }, - }, - "tags": bson.A{}, - }) - if utils.LogContinue(err, utils.Warning) { - return err - } - - rsp.ContentID = res.InsertedID.(primitive.ObjectID).Hex() - rsp.ContentToken = token - rsp.FileID = objID.Hex() - rsp.Status = content.ContentCreateResponse_SUCCESS - } else { // empty content - res, err := collection.InsertOne(ctx, bson.M{ - "token": token, - "files": bson.A{}, - "tags": bson.A{}, - }) - if utils.LogContinue(err, utils.Warning) { - return err - } - - rsp.ContentID = res.InsertedID.(primitive.ObjectID).Hex() - rsp.ContentToken = token - rsp.Status = content.ContentCreateResponse_SUCCESS + res, err := collection.InsertOne(ctx, bson.M{ + "token": token, + "files": bson.A{ + bson.M{ + "fileID": objID, + "type": req.Type, + }}, + }) + if utils.LogContinue(err, utils.Warning) { + return err } + + rsp.ContentID = res.InsertedID.(primitive.ObjectID).Hex() + rsp.ContentToken = token + rsp.FileID = objID.Hex() + rsp.Status = content.ContentCreateResponse_SUCCESS } else if !utils.IsEmpty(req.ContentID) && !utils.IsEmpty(req.ContentToken) { // add exist one if !validCheck(req.ContentID, req.ContentToken) { rsp.Status = content.ContentCreateResponse_INVALID_TOKEN From 9b113b695c385bfa4138c4307d959803622796b6 Mon Sep 17 00:00:00 2001 From: Kang Huquan <799385272@qq.com> Date: Tue, 30 Jul 2019 16:35:08 +0800 Subject: [PATCH 03/12] createTag srv --- backend/srv/content/main.go | 73 ++++++ backend/srv/content/proto/content.micro.go | 17 ++ backend/srv/content/proto/content.pb.go | 262 ++++++++++++++++----- backend/srv/content/proto/content.proto | 20 ++ 4 files changed, 316 insertions(+), 56 deletions(-) diff --git a/backend/srv/content/main.go b/backend/srv/content/main.go index 361fd89..1a47c2a 100644 --- a/backend/srv/content/main.go +++ b/backend/srv/content/main.go @@ -136,6 +136,79 @@ func (a *srv) Create(ctx context.Context, req *content.ContentCreateRequest, rsp return nil } +/** + * @api {rpc} /rpc Content.CreateTag + * @apiVersion 1.0.0 + * @apiGroup Service + * @apiName Content.CreateTag + * @apiDescription create tags + * + * @apiParam {string} [contentID] 24 bytes content id, left empty for first upload + * @apiParam {string} [contentToken] content token, left empty for first upload + * @apiParam {list} tags {string} tag + * @apiSuccess {int32} status -1 for invalid param
1 for success
2 for invalid token
2 for invalid type + * @apiSuccess {string} contentID 24 bytes contentID + * @apiSuccess {string} contentToken random uuid content token + * @apiUse DBServerDown + */ +func (a *srv) CreateTag(ctx context.Context, req *content.ContentCreateTagRequest, rsp *content.ContentCreateTagResponse) error { + // check param + if !utils.RequireParam(req.Tags) { + rsp.Status = content.ContentCreateTagResponse_INVALID_PARAM + return nil + } + + if utils.IsEmpty(req.ContentID) && utils.IsEmpty(req.ContentToken) { // create new + token := uuid.NewV4().String() + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + collection := db.MongoDatabase.Collection("sellinfo") + res, err := collection.InsertOne(ctx, bson.M{ + "token": token, + "tags": req.Tags, + }) + if utils.LogContinue(err, utils.Warning) { + return err + } + + rsp.ContentID = res.InsertedID.(primitive.ObjectID).Hex() + rsp.ContentToken = token + rsp.Status = content.ContentCreateTagResponse_SUCCESS + } else if !utils.IsEmpty(req.ContentID) && !utils.IsEmpty(req.ContentToken) { // add exist one + if !validCheck(req.ContentID, req.ContentToken) { + rsp.Status = content.ContentCreateTagResponse_INVALID_TOKEN + return nil + } + + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + collection := db.MongoDatabase.Collection("sellinfo") + rid, err := primitive.ObjectIDFromHex(req.ContentID) + if utils.LogContinue(err, utils.Warning) { + rsp.Status = content.ContentCreateTagResponse_INVALID_TOKEN + return nil + } + _, err = collection.UpdateOne(ctx, bson.D{ + {"_id", rid}, + {"token", req.ContentToken}, + }, + bson.D{ + {"$setOnInsert", bson.D{ + {"tags", req.Tags}, + }}, + }) + if utils.LogContinue(err, utils.Warning) { + return err + } + rsp.ContentID = req.ContentID + rsp.ContentToken = req.ContentToken + rsp.Status = content.ContentCreateTagResponse_SUCCESS + } else { + rsp.Status = content.ContentCreateTagResponse_INVALID_PARAM + } + return nil +} + /** * @api {rpc} /rpc Content.Update * @apiVersion 1.0.0 diff --git a/backend/srv/content/proto/content.micro.go b/backend/srv/content/proto/content.micro.go index a817d00..c02e489 100644 --- a/backend/srv/content/proto/content.micro.go +++ b/backend/srv/content/proto/content.micro.go @@ -35,6 +35,7 @@ var _ server.Option type ContentService interface { Create(ctx context.Context, in *ContentCreateRequest, opts ...client.CallOption) (*ContentCreateResponse, error) + CreateTag(ctx context.Context, in *ContentCreateTagRequest, opts ...client.CallOption) (*ContentCreateTagResponse, error) Update(ctx context.Context, in *ContentUpdateRequest, opts ...client.CallOption) (*ContentUpdateResponse, error) Delete(ctx context.Context, in *ContentDeleteRequest, opts ...client.CallOption) (*ContentDeleteResponse, error) Query(ctx context.Context, in *ContentQueryRequest, opts ...client.CallOption) (*ContentQueryResponse, error) @@ -69,6 +70,16 @@ func (c *contentService) Create(ctx context.Context, in *ContentCreateRequest, o return out, nil } +func (c *contentService) CreateTag(ctx context.Context, in *ContentCreateTagRequest, opts ...client.CallOption) (*ContentCreateTagResponse, error) { + req := c.c.NewRequest(c.name, "Content.CreateTag", in) + out := new(ContentCreateTagResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *contentService) Update(ctx context.Context, in *ContentUpdateRequest, opts ...client.CallOption) (*ContentUpdateResponse, error) { req := c.c.NewRequest(c.name, "Content.Update", in) out := new(ContentUpdateResponse) @@ -113,6 +124,7 @@ func (c *contentService) Check(ctx context.Context, in *ContentCheckRequest, opt type ContentHandler interface { Create(context.Context, *ContentCreateRequest, *ContentCreateResponse) error + CreateTag(context.Context, *ContentCreateTagRequest, *ContentCreateTagResponse) error Update(context.Context, *ContentUpdateRequest, *ContentUpdateResponse) error Delete(context.Context, *ContentDeleteRequest, *ContentDeleteResponse) error Query(context.Context, *ContentQueryRequest, *ContentQueryResponse) error @@ -122,6 +134,7 @@ type ContentHandler interface { func RegisterContentHandler(s server.Server, hdlr ContentHandler, opts ...server.HandlerOption) error { type content interface { Create(ctx context.Context, in *ContentCreateRequest, out *ContentCreateResponse) error + CreateTag(ctx context.Context, in *ContentCreateTagRequest, out *ContentCreateTagResponse) error Update(ctx context.Context, in *ContentUpdateRequest, out *ContentUpdateResponse) error Delete(ctx context.Context, in *ContentDeleteRequest, out *ContentDeleteResponse) error Query(ctx context.Context, in *ContentQueryRequest, out *ContentQueryResponse) error @@ -142,6 +155,10 @@ func (h *contentHandler) Create(ctx context.Context, in *ContentCreateRequest, o return h.ContentHandler.Create(ctx, in, out) } +func (h *contentHandler) CreateTag(ctx context.Context, in *ContentCreateTagRequest, out *ContentCreateTagResponse) error { + return h.ContentHandler.CreateTag(ctx, in, out) +} + func (h *contentHandler) Update(ctx context.Context, in *ContentUpdateRequest, out *ContentUpdateResponse) error { return h.ContentHandler.Update(ctx, in, out) } diff --git a/backend/srv/content/proto/content.pb.go b/backend/srv/content/proto/content.pb.go index 3f36a75..f4101d2 100644 --- a/backend/srv/content/proto/content.pb.go +++ b/backend/srv/content/proto/content.pb.go @@ -82,6 +82,40 @@ func (ContentCreateResponse_Status) EnumDescriptor() ([]byte, []int) { return fileDescriptor_61cc9617ce0cf609, []int{1, 0} } +type ContentCreateTagResponse_Status int32 + +const ( + ContentCreateTagResponse_UNKNOWN ContentCreateTagResponse_Status = 0 + ContentCreateTagResponse_INVALID_PARAM ContentCreateTagResponse_Status = -1 + ContentCreateTagResponse_SUCCESS ContentCreateTagResponse_Status = 1 + ContentCreateTagResponse_INVALID_TOKEN ContentCreateTagResponse_Status = 2 + ContentCreateTagResponse_INVALID_TYPE ContentCreateTagResponse_Status = 3 +) + +var ContentCreateTagResponse_Status_name = map[int32]string{ + 0: "UNKNOWN", + -1: "INVALID_PARAM", + 1: "SUCCESS", + 2: "INVALID_TOKEN", + 3: "INVALID_TYPE", +} + +var ContentCreateTagResponse_Status_value = map[string]int32{ + "UNKNOWN": 0, + "INVALID_PARAM": -1, + "SUCCESS": 1, + "INVALID_TOKEN": 2, + "INVALID_TYPE": 3, +} + +func (x ContentCreateTagResponse_Status) String() string { + return proto.EnumName(ContentCreateTagResponse_Status_name, int32(x)) +} + +func (ContentCreateTagResponse_Status) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_61cc9617ce0cf609, []int{3, 0} +} + type ContentUpdateRequest_Type int32 const ( @@ -107,7 +141,7 @@ func (x ContentUpdateRequest_Type) String() string { } func (ContentUpdateRequest_Type) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_61cc9617ce0cf609, []int{2, 0} + return fileDescriptor_61cc9617ce0cf609, []int{4, 0} } type ContentUpdateResponse_Status int32 @@ -147,7 +181,7 @@ func (x ContentUpdateResponse_Status) String() string { } func (ContentUpdateResponse_Status) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_61cc9617ce0cf609, []int{3, 0} + return fileDescriptor_61cc9617ce0cf609, []int{5, 0} } type ContentDeleteResponse_Status int32 @@ -178,7 +212,7 @@ func (x ContentDeleteResponse_Status) String() string { } func (ContentDeleteResponse_Status) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_61cc9617ce0cf609, []int{5, 0} + return fileDescriptor_61cc9617ce0cf609, []int{7, 0} } type FileMsg_Type int32 @@ -206,7 +240,7 @@ func (x FileMsg_Type) String() string { } func (FileMsg_Type) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_61cc9617ce0cf609, []int{6, 0} + return fileDescriptor_61cc9617ce0cf609, []int{8, 0} } type ContentQueryResponse_Status int32 @@ -237,7 +271,7 @@ func (x ContentQueryResponse_Status) String() string { } func (ContentQueryResponse_Status) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_61cc9617ce0cf609, []int{8, 0} + return fileDescriptor_61cc9617ce0cf609, []int{10, 0} } type ContentCheckResponse_Status int32 @@ -268,7 +302,7 @@ func (x ContentCheckResponse_Status) String() string { } func (ContentCheckResponse_Status) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_61cc9617ce0cf609, []int{10, 0} + return fileDescriptor_61cc9617ce0cf609, []int{12, 0} } type ContentCreateRequest struct { @@ -397,6 +431,116 @@ func (m *ContentCreateResponse) GetFileID() string { return "" } +type ContentCreateTagRequest struct { + ContentID string `protobuf:"bytes,1,opt,name=contentID,proto3" json:"contentID,omitempty"` + ContentToken string `protobuf:"bytes,2,opt,name=contentToken,proto3" json:"contentToken,omitempty"` + Tags []string `protobuf:"bytes,4,rep,name=tags,proto3" json:"tags,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ContentCreateTagRequest) Reset() { *m = ContentCreateTagRequest{} } +func (m *ContentCreateTagRequest) String() string { return proto.CompactTextString(m) } +func (*ContentCreateTagRequest) ProtoMessage() {} +func (*ContentCreateTagRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_61cc9617ce0cf609, []int{2} +} + +func (m *ContentCreateTagRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ContentCreateTagRequest.Unmarshal(m, b) +} +func (m *ContentCreateTagRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ContentCreateTagRequest.Marshal(b, m, deterministic) +} +func (m *ContentCreateTagRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ContentCreateTagRequest.Merge(m, src) +} +func (m *ContentCreateTagRequest) XXX_Size() int { + return xxx_messageInfo_ContentCreateTagRequest.Size(m) +} +func (m *ContentCreateTagRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ContentCreateTagRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ContentCreateTagRequest proto.InternalMessageInfo + +func (m *ContentCreateTagRequest) GetContentID() string { + if m != nil { + return m.ContentID + } + return "" +} + +func (m *ContentCreateTagRequest) GetContentToken() string { + if m != nil { + return m.ContentToken + } + return "" +} + +func (m *ContentCreateTagRequest) GetTags() []string { + if m != nil { + return m.Tags + } + return nil +} + +type ContentCreateTagResponse struct { + Status ContentCreateTagResponse_Status `protobuf:"varint,1,opt,name=status,proto3,enum=ContentCreateTagResponse_Status" json:"status,omitempty"` + ContentID string `protobuf:"bytes,2,opt,name=contentID,proto3" json:"contentID,omitempty"` + ContentToken string `protobuf:"bytes,3,opt,name=contentToken,proto3" json:"contentToken,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ContentCreateTagResponse) Reset() { *m = ContentCreateTagResponse{} } +func (m *ContentCreateTagResponse) String() string { return proto.CompactTextString(m) } +func (*ContentCreateTagResponse) ProtoMessage() {} +func (*ContentCreateTagResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_61cc9617ce0cf609, []int{3} +} + +func (m *ContentCreateTagResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ContentCreateTagResponse.Unmarshal(m, b) +} +func (m *ContentCreateTagResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ContentCreateTagResponse.Marshal(b, m, deterministic) +} +func (m *ContentCreateTagResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_ContentCreateTagResponse.Merge(m, src) +} +func (m *ContentCreateTagResponse) XXX_Size() int { + return xxx_messageInfo_ContentCreateTagResponse.Size(m) +} +func (m *ContentCreateTagResponse) XXX_DiscardUnknown() { + xxx_messageInfo_ContentCreateTagResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_ContentCreateTagResponse proto.InternalMessageInfo + +func (m *ContentCreateTagResponse) GetStatus() ContentCreateTagResponse_Status { + if m != nil { + return m.Status + } + return ContentCreateTagResponse_UNKNOWN +} + +func (m *ContentCreateTagResponse) GetContentID() string { + if m != nil { + return m.ContentID + } + return "" +} + +func (m *ContentCreateTagResponse) GetContentToken() string { + if m != nil { + return m.ContentToken + } + return "" +} + type ContentUpdateRequest struct { ContentID string `protobuf:"bytes,1,opt,name=contentID,proto3" json:"contentID,omitempty"` ContentToken string `protobuf:"bytes,2,opt,name=contentToken,proto3" json:"contentToken,omitempty"` @@ -413,7 +557,7 @@ func (m *ContentUpdateRequest) Reset() { *m = ContentUpdateRequest{} } func (m *ContentUpdateRequest) String() string { return proto.CompactTextString(m) } func (*ContentUpdateRequest) ProtoMessage() {} func (*ContentUpdateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_61cc9617ce0cf609, []int{2} + return fileDescriptor_61cc9617ce0cf609, []int{4} } func (m *ContentUpdateRequest) XXX_Unmarshal(b []byte) error { @@ -488,7 +632,7 @@ func (m *ContentUpdateResponse) Reset() { *m = ContentUpdateResponse{} } func (m *ContentUpdateResponse) String() string { return proto.CompactTextString(m) } func (*ContentUpdateResponse) ProtoMessage() {} func (*ContentUpdateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_61cc9617ce0cf609, []int{3} + return fileDescriptor_61cc9617ce0cf609, []int{5} } func (m *ContentUpdateResponse) XXX_Unmarshal(b []byte) error { @@ -535,7 +679,7 @@ func (m *ContentDeleteRequest) Reset() { *m = ContentDeleteRequest{} } func (m *ContentDeleteRequest) String() string { return proto.CompactTextString(m) } func (*ContentDeleteRequest) ProtoMessage() {} func (*ContentDeleteRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_61cc9617ce0cf609, []int{4} + return fileDescriptor_61cc9617ce0cf609, []int{6} } func (m *ContentDeleteRequest) XXX_Unmarshal(b []byte) error { @@ -581,7 +725,7 @@ func (m *ContentDeleteResponse) Reset() { *m = ContentDeleteResponse{} } func (m *ContentDeleteResponse) String() string { return proto.CompactTextString(m) } func (*ContentDeleteResponse) ProtoMessage() {} func (*ContentDeleteResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_61cc9617ce0cf609, []int{5} + return fileDescriptor_61cc9617ce0cf609, []int{7} } func (m *ContentDeleteResponse) XXX_Unmarshal(b []byte) error { @@ -621,7 +765,7 @@ func (m *FileMsg) Reset() { *m = FileMsg{} } func (m *FileMsg) String() string { return proto.CompactTextString(m) } func (*FileMsg) ProtoMessage() {} func (*FileMsg) Descriptor() ([]byte, []int) { - return fileDescriptor_61cc9617ce0cf609, []int{6} + return fileDescriptor_61cc9617ce0cf609, []int{8} } func (m *FileMsg) XXX_Unmarshal(b []byte) error { @@ -667,7 +811,7 @@ func (m *ContentQueryRequest) Reset() { *m = ContentQueryRequest{} } func (m *ContentQueryRequest) String() string { return proto.CompactTextString(m) } func (*ContentQueryRequest) ProtoMessage() {} func (*ContentQueryRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_61cc9617ce0cf609, []int{7} + return fileDescriptor_61cc9617ce0cf609, []int{9} } func (m *ContentQueryRequest) XXX_Unmarshal(b []byte) error { @@ -709,7 +853,7 @@ func (m *ContentQueryResponse) Reset() { *m = ContentQueryResponse{} } func (m *ContentQueryResponse) String() string { return proto.CompactTextString(m) } func (*ContentQueryResponse) ProtoMessage() {} func (*ContentQueryResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_61cc9617ce0cf609, []int{8} + return fileDescriptor_61cc9617ce0cf609, []int{10} } func (m *ContentQueryResponse) XXX_Unmarshal(b []byte) error { @@ -770,7 +914,7 @@ func (m *ContentCheckRequest) Reset() { *m = ContentCheckRequest{} } func (m *ContentCheckRequest) String() string { return proto.CompactTextString(m) } func (*ContentCheckRequest) ProtoMessage() {} func (*ContentCheckRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_61cc9617ce0cf609, []int{9} + return fileDescriptor_61cc9617ce0cf609, []int{11} } func (m *ContentCheckRequest) XXX_Unmarshal(b []byte) error { @@ -816,7 +960,7 @@ func (m *ContentCheckResponse) Reset() { *m = ContentCheckResponse{} } func (m *ContentCheckResponse) String() string { return proto.CompactTextString(m) } func (*ContentCheckResponse) ProtoMessage() {} func (*ContentCheckResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_61cc9617ce0cf609, []int{10} + return fileDescriptor_61cc9617ce0cf609, []int{12} } func (m *ContentCheckResponse) XXX_Unmarshal(b []byte) error { @@ -847,6 +991,7 @@ func (m *ContentCheckResponse) GetStatus() ContentCheckResponse_Status { func init() { proto.RegisterEnum("ContentCreateRequest_Type", ContentCreateRequest_Type_name, ContentCreateRequest_Type_value) proto.RegisterEnum("ContentCreateResponse_Status", ContentCreateResponse_Status_name, ContentCreateResponse_Status_value) + proto.RegisterEnum("ContentCreateTagResponse_Status", ContentCreateTagResponse_Status_name, ContentCreateTagResponse_Status_value) proto.RegisterEnum("ContentUpdateRequest_Type", ContentUpdateRequest_Type_name, ContentUpdateRequest_Type_value) proto.RegisterEnum("ContentUpdateResponse_Status", ContentUpdateResponse_Status_name, ContentUpdateResponse_Status_value) proto.RegisterEnum("ContentDeleteResponse_Status", ContentDeleteResponse_Status_name, ContentDeleteResponse_Status_value) @@ -855,6 +1000,8 @@ func init() { proto.RegisterEnum("ContentCheckResponse_Status", ContentCheckResponse_Status_name, ContentCheckResponse_Status_value) proto.RegisterType((*ContentCreateRequest)(nil), "ContentCreateRequest") proto.RegisterType((*ContentCreateResponse)(nil), "ContentCreateResponse") + proto.RegisterType((*ContentCreateTagRequest)(nil), "ContentCreateTagRequest") + proto.RegisterType((*ContentCreateTagResponse)(nil), "ContentCreateTagResponse") proto.RegisterType((*ContentUpdateRequest)(nil), "ContentUpdateRequest") proto.RegisterType((*ContentUpdateResponse)(nil), "ContentUpdateResponse") proto.RegisterType((*ContentDeleteRequest)(nil), "ContentDeleteRequest") @@ -869,45 +1016,48 @@ func init() { func init() { proto.RegisterFile("content.proto", fileDescriptor_61cc9617ce0cf609) } var fileDescriptor_61cc9617ce0cf609 = []byte{ - // 632 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x56, 0xcd, 0x6e, 0xda, 0x40, - 0x10, 0xae, 0x7f, 0xa9, 0x27, 0x21, 0xda, 0x6e, 0x43, 0x64, 0xa1, 0xb4, 0xa2, 0x7b, 0x42, 0xaa, - 0xe4, 0x03, 0x49, 0x95, 0x33, 0xb2, 0x8d, 0x64, 0x25, 0x18, 0x62, 0x20, 0x69, 0x4f, 0x11, 0xa5, - 0xdb, 0x34, 0x0a, 0x02, 0x82, 0xcd, 0x81, 0x4b, 0xdf, 0xa0, 0xe7, 0x5e, 0xdb, 0x27, 0xea, 0x5b, - 0xf4, 0x05, 0x7a, 0xec, 0xa1, 0x95, 0xed, 0x85, 0xf5, 0xba, 0xae, 0x48, 0x5a, 0x38, 0x31, 0xcb, - 0x37, 0xbb, 0x3b, 0xdf, 0xf7, 0xcd, 0x2c, 0x50, 0x1e, 0x4d, 0x27, 0x11, 0x9d, 0x44, 0xd6, 0x6c, - 0x3e, 0x8d, 0xa6, 0xe4, 0x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, 0xa8, 0x3c, 0xce, 0x51, 0x79, 0x68, 0x15, 0xc1, 0xf2, 0x66, 0xbc, 0x4f, 0x93, 0x3e, 0x07, - 0x2d, 0x66, 0x20, 0x34, 0x95, 0x9a, 0x52, 0xdf, 0x69, 0x3c, 0x5e, 0x15, 0x1e, 0xa4, 0xcb, 0xeb, - 0x16, 0x53, 0x33, 0x2d, 0xd6, 0xfe, 0x4f, 0x85, 0x04, 0xe7, 0xca, 0xe4, 0x72, 0x4d, 0x95, 0xfd, - 0x81, 0x8e, 0x6e, 0xb7, 0x67, 0xcd, 0xcf, 0x99, 0xd7, 0x2b, 0xdd, 0x79, 0x13, 0x9d, 0x02, 0x2c, - 0x6f, 0x4c, 0xef, 0xe1, 0x65, 0xc7, 0x86, 0x88, 0x7f, 0x41, 0x09, 0x03, 0x0c, 0x86, 0xe4, 0xc6, - 0x17, 0x19, 0x4a, 0xec, 0x48, 0x7c, 0x02, 0x7a, 0xfa, 0xc2, 0xe0, 0x4a, 0xe1, 0x53, 0x57, 0x3d, - 0x28, 0x7e, 0x88, 0xe2, 0xc4, 0x74, 0x18, 0xf1, 0x44, 0x61, 0x52, 0xf2, 0xc4, 0xdc, 0x6c, 0x3b, - 0x01, 0x3d, 0x6d, 0x41, 0x9e, 0x28, 0x4c, 0x05, 0x9e, 0x98, 0xeb, 0xe8, 0x63, 0xd0, 0x12, 0xc3, - 0xe1, 0x7d, 0xab, 0xc0, 0xdc, 0xd5, 0x8a, 0xf5, 0x17, 0xf3, 0x6a, 0x09, 0xaf, 0x3c, 0x2b, 0xab, - 0x33, 0xcf, 0x12, 0xc8, 0x7f, 0xab, 0x27, 0xff, 0x40, 0x8e, 0x7e, 0x07, 0x00, 0x00, 0xff, 0xff, - 0xeb, 0x19, 0xe9, 0xd3, 0x92, 0x08, 0x00, 0x00, + // 685 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x56, 0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 0x21, 0x79, + 0xf2, 0x3c, 0x3a, 0x25, 0x58, 0xde, 0x98, 0xce, 0xfd, 0xdb, 0x8e, 0x0c, 0x11, 0xfd, 0x82, 0x62, + 0x06, 0x38, 0x0c, 0xa9, 0xad, 0x1f, 0x2a, 0x54, 0x79, 0x49, 0xbc, 0x09, 0x46, 0x72, 0x99, 0xe0, + 0x95, 0xc2, 0x2f, 0x8b, 0xfa, 0x6a, 0xf1, 0xbd, 0x8f, 0xdf, 0x80, 0x99, 0xde, 0x42, 0xd8, 0xa2, + 0x33, 0x6e, 0xcd, 0xfa, 0xd3, 0x99, 0x57, 0x56, 0x54, 0x3a, 0x19, 0x67, 0xa2, 0xb4, 0x34, 0x6b, + 0x45, 0xe9, 0xdc, 0x74, 0xdc, 0x04, 0x23, 0x09, 0xb1, 0x38, 0x28, 0xcd, 0x15, 0x71, 0x30, 0x37, + 0x13, 0x36, 0xa0, 0x12, 0x5b, 0x16, 0x2f, 0xd3, 0x82, 0x78, 0xd4, 0x57, 0xe8, 0x0c, 0xfb, 0x57, + 0x62, 0x65, 0xc4, 0xa9, 0xac, 0x53, 0xc4, 0x29, 0x49, 0xbe, 0xf7, 0x46, 0xfc, 0xc9, 0xb8, 0xfe, + 0x27, 0x00, 0x00, 0xff, 0xff, 0x37, 0x4d, 0xbb, 0xee, 0x43, 0x0a, 0x00, 0x00, } diff --git a/backend/srv/content/proto/content.proto b/backend/srv/content/proto/content.proto index 46b6f40..3d6b354 100644 --- a/backend/srv/content/proto/content.proto +++ b/backend/srv/content/proto/content.proto @@ -2,6 +2,7 @@ syntax = "proto3"; service Content { rpc Create (ContentCreateRequest) returns (ContentCreateResponse); + rpc CreateTag(ContentCreateTagRequest)returns (ContentCreateTagResponse); rpc Update (ContentUpdateRequest) returns (ContentUpdateResponse); rpc Delete (ContentDeleteRequest) returns (ContentDeleteResponse); rpc Query (ContentQueryRequest) returns (ContentQueryResponse); @@ -34,6 +35,25 @@ message ContentCreateResponse { string fileID = 4; } +message ContentCreateTagRequest{ + string contentID = 1; + string contentToken = 2; + repeated string tags = 4; +} + +message ContentCreateTagResponse{ + enum Status { + UNKNOWN = 0; + INVALID_PARAM = -1; + SUCCESS = 1; + INVALID_TOKEN = 2; + INVALID_TYPE = 3; + } + Status status = 1; + string contentID = 2; + string contentToken = 3; +} + message ContentUpdateRequest { enum Type { UNKNOWN = 0; From b749120d3f6a0c6ae54ce3b950009721f4af47d7 Mon Sep 17 00:00:00 2001 From: Kang Huquan <799385272@qq.com> Date: Tue, 30 Jul 2019 17:08:00 +0800 Subject: [PATCH 04/12] update sellInfo Tag --- backend/api/buyinfo/main.go | 16 ++-- backend/api/sellinfo/main.go | 16 ++-- backend/srv/buyinfo/main.go | 22 ++++-- backend/srv/buyinfo/proto/buyinfo.pb.go | 89 +++++++++++++---------- backend/srv/buyinfo/proto/buyinfo.proto | 1 + backend/srv/sellinfo/main.go | 22 ++++-- backend/srv/sellinfo/proto/sellinfo.pb.go | 89 +++++++++++++---------- backend/srv/sellinfo/proto/sellinfo.proto | 1 + 8 files changed, 152 insertions(+), 104 deletions(-) diff --git a/backend/api/buyinfo/main.go b/backend/api/buyinfo/main.go index b1977cf..99b3fda 100644 --- a/backend/api/buyinfo/main.go +++ b/backend/api/buyinfo/main.go @@ -73,13 +73,14 @@ func getBuyInfo(c *gin.Context) { */ func addBuyInfo(c *gin.Context) { type param struct { - ValidTime int64 `form:"validTime" binding:"required"` - GoodName string `form:"goodName" binding:"required"` - Price float64 `form:"price"` - Description string `form:"description"` - ContentID string `form:"contentID"` - ContentToken string `form:"contentToken"` - UserID int32 `form:"userID" binding:"required"` + ValidTime int64 `form:"validTime" binding:"required"` + GoodName string `form:"goodName" binding:"required"` + Price float64 `form:"price"` + Description string `form:"description"` + ContentID string `form:"contentID"` + ContentToken string `form:"contentToken"` + UserID int32 `form:"userID" binding:"required"` + Tags []string `form:"tags"` } var p param if !utils.LogContinue(c.ShouldBind(&p), utils.Warning) { @@ -104,6 +105,7 @@ func addBuyInfo(c *gin.Context) { ContentID: p.ContentID, ContentToken: p.ContentToken, UserID: p.UserID, + Tags: p.Tags, }) if utils.LogContinue(err, utils.Warning, "BuyInfo service error: %v", err) { c.JSON(500, err) diff --git a/backend/api/sellinfo/main.go b/backend/api/sellinfo/main.go index fd11f18..28f698d 100644 --- a/backend/api/sellinfo/main.go +++ b/backend/api/sellinfo/main.go @@ -73,13 +73,14 @@ func getSellInfo(c *gin.Context) { */ func addSellInfo(c *gin.Context) { type param struct { - ValidTime int64 `form:"validTime" binding:"required"` - GoodName string `form:"goodName" binding:"required"` - Price float64 `form:"price"` - Description string `form:"description"` - ContentID string `form:"contentID"` - ContentToken string `form:"contentToken"` - UserID int32 `form:"userID" binding:"required"` + ValidTime int64 `form:"validTime" binding:"required"` + GoodName string `form:"goodName" binding:"required"` + Price float64 `form:"price"` + Description string `form:"description"` + ContentID string `form:"contentID"` + ContentToken string `form:"contentToken"` + UserID int32 `form:"userID" binding:"required"` + Tags []string `form:"tags"` } var p param if !utils.LogContinue(c.ShouldBind(&p), utils.Warning) { @@ -104,6 +105,7 @@ func addSellInfo(c *gin.Context) { ContentID: p.ContentID, ContentToken: p.ContentToken, UserID: p.UserID, + Tags: p.Tags, }) if utils.LogContinue(err, utils.Warning, "SellInfo service error: %v", err) { c.JSON(500, err) diff --git a/backend/srv/buyinfo/main.go b/backend/srv/buyinfo/main.go index bb32ee1..34fe530 100644 --- a/backend/srv/buyinfo/main.go +++ b/backend/srv/buyinfo/main.go @@ -84,6 +84,7 @@ func (a *srv) Query(ctx context.Context, req *buyinfo.BuyInfoQueryRequest, rsp * * @apiParam {double} [price] good price * @apiParam {string} [contentID] content id of good * @apiParam {string} [contentToken] content token + * @apiParam {list} [tags] {string} tag * @apiSuccess {int32} status -1 for invalid param
1 for success
2 for invalid token * @apiSuccess {int32} buyInfoID created buyInfoID * @apiUse DBServerDown @@ -130,6 +131,22 @@ func (a *srv) Create(ctx context.Context, req *buyinfo.BuyInfoCreateRequest, rsp return info.ID, nil } + srv := utils.CallMicroService("content", func(name string, c client.Client) interface{} { return content.NewContentService(name, c) }, + func() interface{} { return mock.NewContentService() }).(content.ContentService) + if utils.RequireParam(req.Tags) { + microRsp, err := srv.CreateTag(context.TODO(), &content.ContentCreateTagRequest{ + ContentID: req.ContentID, + ContentToken: req.ContentToken, + Tags: req.Tags, + }) + if err != nil || microRsp.Status != content.ContentCreateTagResponse_SUCCESS { + rsp.Status = buyinfo.BuyInfoCreateResponse_INVALID_TOKEN + return nil + } + req.ContentID = microRsp.ContentID + req.ContentToken = microRsp.ContentToken + } + if utils.IsEmpty(req.ContentID) && utils.IsEmpty(req.ContentToken) { id, err := insert() if err != nil || id == 0 { @@ -138,11 +155,6 @@ func (a *srv) Create(ctx context.Context, req *buyinfo.BuyInfoCreateRequest, rsp rsp.Status = buyinfo.BuyInfoCreateResponse_SUCCESS rsp.BuyInfoID = id } else if !utils.IsEmpty(req.ContentID) && !utils.IsEmpty(req.ContentToken) { - srv := utils.CallMicroService("content", func(name string, c client.Client) interface{} { - return content.NewContentService(name, c) - }, func() interface{} { - return mock.NewContentService() - }).(content.ContentService) microRsp, err := srv.Check(context.TODO(), &content.ContentCheckRequest{ ContentID: req.ContentID, ContentToken: req.ContentToken, diff --git a/backend/srv/buyinfo/proto/buyinfo.pb.go b/backend/srv/buyinfo/proto/buyinfo.pb.go index d0727a4..8102d72 100644 --- a/backend/srv/buyinfo/proto/buyinfo.pb.go +++ b/backend/srv/buyinfo/proto/buyinfo.pb.go @@ -246,6 +246,7 @@ type BuyInfoCreateRequest struct { ContentID string `protobuf:"bytes,5,opt,name=contentID,proto3" json:"contentID,omitempty"` ContentToken string `protobuf:"bytes,6,opt,name=contentToken,proto3" json:"contentToken,omitempty"` UserID int32 `protobuf:"varint,7,opt,name=userID,proto3" json:"userID,omitempty"` + Tags []string `protobuf:"bytes,8,rep,name=tags,proto3" json:"tags,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -325,6 +326,13 @@ func (m *BuyInfoCreateRequest) GetUserID() int32 { return 0 } +func (m *BuyInfoCreateRequest) GetTags() []string { + if m != nil { + return m.Tags + } + return nil +} + type BuyInfoCreateResponse struct { Status BuyInfoCreateResponse_Status `protobuf:"varint,1,opt,name=status,proto3,enum=BuyInfoCreateResponse_Status" json:"status,omitempty"` BuyInfoID int32 `protobuf:"varint,2,opt,name=buyInfoID,proto3" json:"buyInfoID,omitempty"` @@ -512,44 +520,45 @@ func init() { func init() { proto.RegisterFile("buyinfo.proto", fileDescriptor_0e8250a94d2d8d95) } var fileDescriptor_0e8250a94d2d8d95 = []byte{ - // 620 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x94, 0xdd, 0x6e, 0xd3, 0x4c, - 0x10, 0x86, 0xbf, 0x8d, 0x7f, 0xe2, 0x4c, 0x9a, 0x4f, 0x66, 0x9b, 0x56, 0x96, 0x05, 0xc8, 0xb2, - 0x84, 0x64, 0xf5, 0xc0, 0x12, 0xad, 0x10, 0x27, 0x9c, 0xb4, 0xb1, 0x41, 0x56, 0x53, 0xa7, 0x5d, - 0xb7, 0x85, 0x33, 0xe4, 0x26, 0x9b, 0xd6, 0x22, 0xf1, 0x06, 0xff, 0x80, 0x72, 0x39, 0xdc, 0x05, - 0x67, 0xdc, 0x04, 0x57, 0xc0, 0x8d, 0x80, 0xbc, 0x76, 0x63, 0x27, 0x84, 0x82, 0xcf, 0xe6, 0x9d, - 0x59, 0xed, 0xce, 0xf3, 0xce, 0x18, 0x7a, 0x37, 0xf9, 0x32, 0x8a, 0xa7, 0xcc, 0x5e, 0x24, 0x2c, - 0x63, 0xe6, 0xd7, 0x16, 0xc0, 0x49, 0xbe, 0xf4, 0xe2, 0x29, 0x3b, 0x4b, 0x6f, 0xf1, 0x63, 0xe8, - 0xdc, 0x94, 0x91, 0xe7, 0x68, 0xc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0xaa, 0x5c, 0x79, 0x06, 0xed, 0x8a, 0xa6, 0x86, 0x0c, 0xc1, 0xea, 0x1e, 0x76, 0xed, - 0xfa, 0x9f, 0x40, 0xee, 0x73, 0x07, 0xd7, 0xd0, 0x59, 0xb5, 0xb5, 0x8e, 0xba, 0xc0, 0xe9, 0x0e, - 0x87, 0x9e, 0xff, 0x46, 0x45, 0x78, 0x07, 0x14, 0xe2, 0x06, 0x2e, 0xb9, 0x76, 0x1d, 0xb5, 0x85, - 0x15, 0x10, 0x9d, 0x91, 0xef, 0xaa, 0x42, 0x51, 0xe4, 0xbe, 0x3b, 0xf7, 0x88, 0xeb, 0xa8, 0x22, - 0x06, 0x90, 0x07, 0xc3, 0x51, 0xe0, 0x3a, 0xaa, 0x74, 0xf8, 0x05, 0x41, 0xbb, 0xba, 0x0f, 0x1f, - 0x80, 0xc4, 0xb7, 0x09, 0xf7, 0xed, 0x2d, 0xcb, 0xa5, 0x37, 0x1f, 0x86, 0x5f, 0x82, 0x5c, 0x8e, - 0x0d, 0xde, 0xb3, 0xb7, 0xed, 0x94, 0xbe, 0xbf, 0x7d, 0xba, 0xf0, 0x73, 0x10, 0x8b, 0xfe, 0xf1, - 0xae, 0xfd, 0xbb, 0xc7, 0x7a, 0xdf, 0xde, 0x82, 0xe8, 0x46, 0xe6, 0xbf, 0xcb, 0xa3, 0x5f, 0x01, - 0x00, 0x00, 0xff, 0xff, 0xdd, 0xbb, 0xa3, 0xbb, 0x3f, 0x05, 0x00, 0x00, + // 632 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x94, 0xcf, 0x6e, 0xd3, 0x4e, + 0x10, 0xc7, 0x7f, 0x1b, 0xff, 0x89, 0x33, 0x69, 0x7e, 0x32, 0xdb, 0xb4, 0xb2, 0x22, 0x40, 0x96, + 0x25, 0x24, 0xab, 0x07, 0x4b, 0xb4, 0x42, 0x5c, 0xb8, 0xb4, 0xb1, 0x41, 0x56, 0x53, 0xa7, 0x5d, + 0xb7, 0x85, 0x1b, 0x72, 0x93, 0x4d, 0x6a, 0x91, 0xd8, 0xc1, 0x5e, 0x83, 0xf2, 0x38, 0xbc, 0x05, + 0x37, 0x5e, 0x82, 0x67, 0xe1, 0x0a, 0xf2, 0xda, 0x8d, 0x9d, 0x10, 0x02, 0x39, 0x65, 0xbe, 0x33, + 0xab, 0xdd, 0xf9, 0x7c, 0x67, 0x0c, 0x9d, 0xbb, 0x6c, 0x19, 0x46, 0x93, 0xd8, 0x5a, 0x24, 0x31, + 0x8b, 0x8d, 0xaf, 0x0d, 0x80, 0xb3, 0x6c, 0xe9, 0x46, 0x93, 0xf8, 0x22, 0x9d, 0xe2, 0xc7, 0xd0, + 0xba, 0x2b, 0x22, 0xd7, 0xd6, 0x90, 0x8e, 0x4c, 0x89, 0x54, 0x02, 0x36, 0x40, 0x4e, 0x59, 0xc0, + 0xb2, 0x54, 0x6b, 0xe8, 0xc8, 0xfc, 0xff, 0x18, 0xac, 0xb3, 0x6c, 0xe9, 0x73, 0x85, 0x94, 0x19, + 0xac, 0x43, 0x3b, 0xa1, 0x33, 0x1a, 0xa4, 0xf4, 0x3a, 0x9c, 0x53, 0x4d, 0xd0, 0x91, 0x29, 0x90, + 0xba, 0x94, 0xdf, 0xf1, 0x29, 0x98, 0x85, 0x63, 0x9e, 0x17, 0x79, 0xbe, 0x12, 0x70, 0x0f, 0x94, + 0x69, 0x1c, 0x8f, 0xbd, 0x60, 0x4e, 0x35, 0x49, 0x47, 0x66, 0x8b, 0xac, 0x62, 0xdc, 0x05, 0x69, + 0x91, 0x84, 0x23, 0xaa, 0xc9, 0x3a, 0x32, 0x11, 0x29, 0x82, 0xfc, 0xc6, 0x31, 0x4d, 0x47, 0x49, + 0xb8, 0x60, 0x61, 0x1c, 0x69, 0x4d, 0x7e, 0xa8, 0x2e, 0xe5, 0x37, 0x8e, 0xe2, 0x88, 0xd1, 0x88, + 0xb9, 0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 0x07, 0xd6, 0xb6, + 0x3d, 0xeb, 0x1d, 0x6e, 0x9f, 0x2e, 0xfc, 0x1c, 0xc4, 0xbc, 0x7f, 0xbc, 0x6f, 0xfd, 0xee, 0x71, + 0xaf, 0x6b, 0x6d, 0x41, 0x74, 0x27, 0xf3, 0x4f, 0xe8, 0xc9, 0xaf, 0x00, 0x00, 0x00, 0xff, 0xff, + 0x18, 0x53, 0x79, 0xb8, 0x53, 0x05, 0x00, 0x00, } diff --git a/backend/srv/buyinfo/proto/buyinfo.proto b/backend/srv/buyinfo/proto/buyinfo.proto index ac09e7b..a138f81 100644 --- a/backend/srv/buyinfo/proto/buyinfo.proto +++ b/backend/srv/buyinfo/proto/buyinfo.proto @@ -41,6 +41,7 @@ message BuyInfoCreateRequest { string contentID = 5; string contentToken = 6; int32 userID = 7; + repeated string tags = 8; } message BuyInfoCreateResponse { diff --git a/backend/srv/sellinfo/main.go b/backend/srv/sellinfo/main.go index 1796635..f1707e7 100644 --- a/backend/srv/sellinfo/main.go +++ b/backend/srv/sellinfo/main.go @@ -85,6 +85,7 @@ func (a *srv) Query(ctx context.Context, req *sellinfo.SellInfoQueryRequest, rsp * @apiParam {double} [price] good price * @apiParam {string} [contentID] content id of good * @apiParam {string} [contentToken] content token + * @apiParam {list} [tags] {string} tag * @apiSuccess {int32} status -1 for invalid param
1 for success
2 for invalid token * @apiSuccess {int32} sellInfoID created sellInfoID * @apiUse DBServerDown @@ -131,6 +132,22 @@ func (a *srv) Create(ctx context.Context, req *sellinfo.SellInfoCreateRequest, r return info.ID, nil } + srv := utils.CallMicroService("content", func(name string, c client.Client) interface{} { return content.NewContentService(name, c) }, + func() interface{} { return mock.NewContentService() }).(content.ContentService) + if utils.RequireParam(req.Tags) { + microRsp, err := srv.CreateTag(context.TODO(), &content.ContentCreateTagRequest{ + ContentID: req.ContentID, + ContentToken: req.ContentToken, + Tags: req.Tags, + }) + if err != nil || microRsp.Status != content.ContentCreateTagResponse_SUCCESS { + rsp.Status = sellinfo.SellInfoCreateResponse_INVALID_TOKEN + return nil + } + req.ContentID = microRsp.ContentID + req.ContentToken = microRsp.ContentToken + } + if utils.IsEmpty(req.ContentID) && utils.IsEmpty(req.ContentToken) { id, err := insert() if err != nil || id == 0 { @@ -139,11 +156,6 @@ func (a *srv) Create(ctx context.Context, req *sellinfo.SellInfoCreateRequest, r rsp.Status = sellinfo.SellInfoCreateResponse_SUCCESS rsp.SellInfoID = id } else if !utils.IsEmpty(req.ContentID) && !utils.IsEmpty(req.ContentToken) { - srv := utils.CallMicroService("content", func(name string, c client.Client) interface{} { - return content.NewContentService(name, c) - }, func() interface{} { - return mock.NewContentService() - }).(content.ContentService) microRsp, err := srv.Check(context.TODO(), &content.ContentCheckRequest{ ContentID: req.ContentID, ContentToken: req.ContentToken, diff --git a/backend/srv/sellinfo/proto/sellinfo.pb.go b/backend/srv/sellinfo/proto/sellinfo.pb.go index 9eca6ef..7a950e1 100644 --- a/backend/srv/sellinfo/proto/sellinfo.pb.go +++ b/backend/srv/sellinfo/proto/sellinfo.pb.go @@ -246,6 +246,7 @@ type SellInfoCreateRequest struct { ContentID string `protobuf:"bytes,5,opt,name=contentID,proto3" json:"contentID,omitempty"` ContentToken string `protobuf:"bytes,6,opt,name=contentToken,proto3" json:"contentToken,omitempty"` UserID int32 `protobuf:"varint,7,opt,name=userID,proto3" json:"userID,omitempty"` + Tags []string `protobuf:"bytes,8,rep,name=tags,proto3" json:"tags,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -325,6 +326,13 @@ func (m *SellInfoCreateRequest) GetUserID() int32 { return 0 } +func (m *SellInfoCreateRequest) GetTags() []string { + if m != nil { + return m.Tags + } + return nil +} + type SellInfoCreateResponse struct { Status SellInfoCreateResponse_Status `protobuf:"varint,1,opt,name=status,proto3,enum=SellInfoCreateResponse_Status" json:"status,omitempty"` SellInfoID int32 `protobuf:"varint,2,opt,name=sellInfoID,proto3" json:"sellInfoID,omitempty"` @@ -512,44 +520,45 @@ func init() { func init() { proto.RegisterFile("sellinfo.proto", fileDescriptor_9c322b32f573704b) } var fileDescriptor_9c322b32f573704b = []byte{ - // 619 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x94, 0xcf, 0x6e, 0x9b, 0x40, - 0x10, 0xc6, 0xbb, 0xb6, 0x21, 0x78, 0x9c, 0x44, 0x74, 0x9b, 0xa4, 0xc8, 0xaa, 0x22, 0x44, 0x2f, - 0xa8, 0xaa, 0x38, 0x24, 0x52, 0xa4, 0xde, 0x1a, 0x19, 0x5a, 0xa1, 0x38, 0x38, 0x59, 0xf2, 0xa7, - 0xb7, 0x8a, 0xda, 0xeb, 0x04, 0x15, 0xb3, 0x2e, 0x8b, 0x5b, 0xe5, 0x8d, 0xfa, 0x10, 0xbd, 0xf5, - 0x1d, 0xfa, 0x02, 0x7d, 0x90, 0x56, 0x2c, 0x60, 0xc0, 0x75, 0x92, 0x72, 0x9b, 0x6f, 0x76, 0xb4, - 0x3b, 0xbf, 0x6f, 0x06, 0xd8, 0xe6, 0x34, 0x8a, 0xc2, 0x78, 0xca, 0xac, 0x79, 0xc2, 0x52, 0x66, - 0xfc, 0x68, 0x41, 0xcf, 0xa7, 0x51, 0xe4, 0xc6, 0x53, 0x76, 0xca, 0x6f, 0xf0, 0x3e, 0x00, 0x2f, - 0x42, 0xd7, 0xd6, 0x90, 0x8e, 0x4c, 0x89, 0xd4, 0x14, 0xfc, 0x12, 0x64, 0x9e, 0x06, 0xe9, 0x82, - 0x6b, 0x2d, 0x1d, 0x99, 0xdb, 0x07, 0x3d, 0x2b, 0xab, 0xf6, 0x85, 0x44, 0x8a, 0x14, 0xd6, 0xa1, - 0x97, 0xd0, 0x88, 0x06, 0x9c, 0x5e, 0x84, 0x33, 0xaa, 0xb5, 0x75, 0x64, 0xb6, 0x49, 0x5d, 0xc2, - 0x2f, 0xa0, 0xfb, 0x35, 0x88, 0xc2, 0x89, 0xc8, 0x77, 0x44, 0xbe, 0x12, 0x70, 0x1f, 0x94, 0x1b, - 0xc6, 0x26, 0x5e, 0x30, 0xa3, 0x9a, 0xa4, 0x23, 0xb3, 0x4b, 0x96, 0x31, 0xde, 0x01, 0x69, 0x9e, - 0x84, 0x63, 0xaa, 0xc9, 0x3a, 0x32, 0x11, 0xc9, 0x83, 0xec, 0xc6, 0x09, 0xe5, 0xe3, 0x24, 0x9c, - 0xa7, 0x21, 0x8b, 0xb5, 0x0d, 0x51, 0x54, 0x97, 0xb2, 0x1b, 0xc7, 0x2c, 0x4e, 0x69, 0x9c, 0xba, - 0xb6, 0xa6, 0x88, 0x7c, 0x25, 0xe0, 0x3d, 0x90, 0x17, 0x9c, 0x26, 0xae, 0xad, 0x75, 0x45, 0xcb, - 0x45, 0x94, 0xe1, 0x18, 0x47, 0x34, 0x48, 0x9c, 0xd9, 0x3c, 0xbd, 0xd3, 0xc6, 0x3a, 0x32, 0x15, - 0x52, 0x53, 0x8c, 0x23, 0xd8, 0x29, 0xe9, 0x9d, 0x2f, 0x68, 0x72, 0x47, 0xe8, 0x97, 0x05, 0xe5, - 0xe9, 0x63, 0x18, 0x8d, 0xdf, 0x08, 0x76, 0xcb, 0xc2, 0x41, 0x42, 0x83, 0x94, 0x96, 0x95, 0x0d, - 0x32, 0xe8, 0x21, 0x32, 0xad, 0xfb, 0xc8, 0xb4, 0x1f, 0x20, 0xd3, 0x79, 0x84, 0x8c, 0xb4, 0x4a, - 0xc6, 0x80, 0xcd, 0x22, 0xb8, 0x60, 0x9f, 0x69, 0x2c, 0xb0, 0x77, 0x49, 0x43, 0xab, 0xd1, 0xdb, - 0xa8, 0xd3, 0x33, 0x7e, 0x22, 0xd8, 0x5b, 0xed, 0x92, 0xcf, 0x59, 0xcc, 0x29, 0x3e, 0x5a, 0xce, - 0x11, 0x12, 0x73, 0xb4, 0x6f, 0xad, 0x3f, 0x68, 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- 0xec, 0x91, 0xe7, 0xa8, 0xed, 0xec, 0x90, 0xf3, 0xe1, 0xcc, 0x25, 0x8e, 0xad, 0x76, 0x30, 0x80, - 0x3c, 0x18, 0x8e, 0x7c, 0xc7, 0x56, 0xa5, 0x83, 0xef, 0x08, 0x94, 0xf2, 0x4a, 0xfc, 0x1a, 0x24, - 0xb1, 0x5c, 0x78, 0xd7, 0x5a, 0xb7, 0x6c, 0xfd, 0xc6, 0xeb, 0xf0, 0x1b, 0x90, 0xf3, 0x11, 0xc2, - 0x7b, 0xd6, 0xda, 0x15, 0xeb, 0x3f, 0xbf, 0x67, 0xd6, 0xf0, 0x21, 0x74, 0x32, 0x10, 0x78, 0xc7, - 0x5a, 0xe3, 0x77, 0x7f, 0xd7, 0x5a, 0x47, 0xeb, 0x93, 0x2c, 0x7e, 0xa4, 0x87, 0x7f, 0x03, 0x00, - 0x00, 0xff, 0xff, 0x54, 0x85, 0xc2, 0x79, 0x5a, 0x05, 0x00, 0x00, + // 630 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x94, 0xcd, 0x6e, 0xd3, 0x40, + 0x14, 0x85, 0x99, 0xf8, 0xa7, 0xce, 0x4d, 0x5b, 0x99, 0xa1, 0x2d, 0x56, 0x84, 0x2a, 0xcb, 0x6c, + 0x2c, 0x84, 0xbc, 0x68, 0xa5, 0x4a, 0xec, 0xa8, 0x62, 0x83, 0xac, 0xa6, 0x4e, 0x3b, 0x4e, 0x5b, + 0x76, 0xc8, 0x24, 0x93, 0xd4, 0xc2, 0xb1, 0x83, 0xc7, 0x01, 0xf5, 0x8d, 0x78, 0x08, 0x76, 0xbc, + 0x03, 0xaf, 0xc2, 0x12, 0xe4, 0x89, 0x1d, 0xdb, 0x21, 0x6d, 0xc9, 0x2a, 0xe7, 0xdc, 0xb9, 0x9a, + 0x99, 0xef, 0xdc, 0x31, 0xec, 0x32, 0x1a, 0x45, 0x61, 0x3c, 0x49, 0xac, 0x79, 0x9a, 0x64, 0x89, + 0xf1, 0xa3, 0x05, 0x1d, 0x9f, 0x46, 0x91, 0x1b, 0x4f, 0x92, 0x73, 0x36, 0xc5, 0x87, 0x00, 0xac, + 0x90, 0xae, 0xad, 0x21, 0x1d, 0x99, 0x12, 0xa9, 0x39, 0xf8, 0x25, 0xc8, 0x2c, 0x0b, 0xb2, 0x05, + 0xd3, 0x5a, 0x3a, 0x32, 0x77, 0x8f, 0x3a, 0x56, 0xde, 0xed, 0x73, 0x8b, 0x14, 0x25, 0xac, 0x43, + 0x27, 0xa5, 0x11, 0x0d, 0x18, 0x1d, 0x86, 0x33, 0xaa, 0x09, 0x3a, 0x32, 0x05, 0x52, 0xb7, 0xf0, + 0x0b, 0x68, 0x7f, 0x0d, 0xa2, 0x70, 0xcc, 0xeb, 0x22, 0xaf, 0x57, 0x06, 0xee, 0x82, 0x32, 0x4d, + 0x92, 0xb1, 0x17, 0xcc, 0xa8, 0x26, 0xe9, 0xc8, 0x6c, 0x93, 0x95, 0xc6, 0x7b, 0x20, 0xcd, 0xd3, + 0x70, 0x44, 0x35, 0x59, 0x47, 0x26, 0x22, 0x4b, 0x91, 0xef, 0x38, 0xa6, 0x6c, 0x94, 0x86, 0xf3, + 0x2c, 0x4c, 0x62, 0x6d, 0x8b, 0x37, 0xd5, 0xad, 0x7c, 0xc7, 0x51, 0x12, 0x67, 0x34, 0xce, 0x5c, + 0x5b, 0x53, 0x78, 0xbd, 0x32, 0xf0, 0x01, 0xc8, 0x0b, 0x46, 0x53, 0xd7, 0xd6, 0xda, 0xfc, 0xca, + 0x85, 0xca, 0x71, 0x8c, 0x22, 0x1a, 0xa4, 0xce, 0x6c, 0x9e, 0xdd, 0x69, 0x23, 0x1d, 0x99, 0x0a, + 0xa9, 0x39, 0xc6, 0x09, 0xec, 0x95, 0xf4, 0x2e, 0x17, 0x34, 0xbd, 0x23, 0xf4, 0xcb, 0x82, 0xb2, + 0xec, 0x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0x86, 0xd3, 0xdb, 0x65, 0x51, 0xe2, 0xc5, 0xca, 0xc8, + 0xc7, 0x22, 0x0a, 0x67, 0x61, 0xc6, 0x93, 0xdb, 0x21, 0x4b, 0x91, 0x1f, 0x34, 0x99, 0x4c, 0x18, + 0xcd, 0x78, 0x64, 0x3b, 0xa4, 0x50, 0xc6, 0xdb, 0x6a, 0xa0, 0x97, 0xf7, 0x2a, 0xb2, 0x31, 0x41, + 0x29, 0x89, 0x6a, 0x48, 0x17, 0xcc, 0xce, 0xd1, 0xb6, 0x55, 0xfb, 0x6e, 0x90, 0x55, 0xf5, 0xd5, + 0x0d, 0x40, 0x75, 0xb7, 0x26, 0xf1, 0x9c, 0xaa, 0xd3, 0xef, 0xbb, 0xde, 0x7b, 0x15, 0xe1, 0x6d, + 0x50, 0x88, 0xe3, 0x3b, 0xe4, 0xda, 0xb1, 0xd5, 0x16, 0x56, 0x40, 0xb4, 0x07, 0x9e, 0xa3, 0x0a, + 0xf9, 0x22, 0xe7, 0xc3, 0x85, 0x4b, 0x1c, 0x5b, 0x15, 0x31, 0x80, 0xdc, 0xeb, 0x0f, 0x7c, 0xc7, + 0x56, 0xa5, 0xa3, 0xef, 0x08, 0x94, 0x72, 0x4b, 0xfc, 0x1a, 0x24, 0xfe, 0xe0, 0xf0, 0xbe, 0xb5, + 0xe9, 0x01, 0x76, 0x1b, 0xa7, 0xc3, 0x6f, 0x40, 0x5e, 0x8e, 0x10, 0x3e, 0xb0, 0x36, 0x3e, 0xbb, + 0xee, 0xf3, 0x7b, 0x66, 0x0d, 0x1f, 0x83, 0x98, 0x83, 0xc0, 0x7b, 0xd6, 0x86, 0xbc, 0xbb, 0xfb, + 0xd6, 0x26, 0x5a, 0x9f, 0x64, 0xfe, 0x71, 0x3d, 0xfe, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x86, 0xe9, + 0x30, 0xdd, 0x6e, 0x05, 0x00, 0x00, } diff --git a/backend/srv/sellinfo/proto/sellinfo.proto b/backend/srv/sellinfo/proto/sellinfo.proto index 8f56977..f5af068 100644 --- a/backend/srv/sellinfo/proto/sellinfo.proto +++ b/backend/srv/sellinfo/proto/sellinfo.proto @@ -41,6 +41,7 @@ message SellInfoCreateRequest { string contentID = 5; string contentToken = 6; int32 userID = 7; + repeated string tags = 8; } message SellInfoCreateResponse { From 7c098eac9f93104192a073cf1ad73262e1784556 Mon Sep 17 00:00:00 2001 From: Kang Huquan <799385272@qq.com> Date: Tue, 30 Jul 2019 17:11:22 +0800 Subject: [PATCH 05/12] update tag doc --- backend/doc/api_data.js | 112 +++++++++++++++++++++++++++++++++++ backend/doc/api_data.json | 112 +++++++++++++++++++++++++++++++++++ backend/doc/api_project.js | 2 +- backend/doc/api_project.json | 2 +- 4 files changed, 226 insertions(+), 2 deletions(-) diff --git a/backend/doc/api_data.js b/backend/doc/api_data.js index 3aba1f0..163776f 100644 --- a/backend/doc/api_data.js +++ b/backend/doc/api_data.js @@ -1016,6 +1016,13 @@ define({ "api": [ "optional": true, "field": "contentToken", "description": "

content token

" + }, + { + "group": "Parameter", + "type": "list", + "optional": true, + "field": "tags", + "description": "

{string} tag

" } ] } @@ -1354,6 +1361,90 @@ define({ "api": [ ] } }, + "success": { + "fields": { + "Success 200": [ + { + "group": "Success 200", + "type": "int32", + "optional": false, + "field": "status", + "description": "

-1 for invalid param
1 for success
2 for invalid token
2 for invalid type

" + }, + { + "group": "Success 200", + "type": "string", + "optional": false, + "field": "contentID", + "description": "

24 bytes contentID

" + }, + { + "group": "Success 200", + "type": "string", + "optional": false, + "field": "contentToken", + "description": "

random uuid content token

" + }, + { + "group": "Success 200", + "type": "string", + "optional": false, + "field": "fileID", + "description": "

24 bytes fileID

" + } + ] + } + }, + "filename": "srv/content/main.go", + "groupTitle": "Service", + "error": { + "fields": { + "Error 500": [ + { + "group": "Error 500", + "optional": false, + "field": "DBServerDown", + "description": "

can't connect to database server

" + } + ] + } + } + }, + { + "type": "rpc", + "url": "/rpc", + "title": "Content.CreateTag", + "version": "1.0.0", + "group": "Service", + "name": "Content_CreateTag", + "description": "

create tags

", + "parameter": { + "fields": { + "Parameter": [ + { + "group": "Parameter", + "type": "string", + "optional": true, + "field": "contentID", + "description": "

24 bytes content id, left empty for first upload

" + }, + { + "group": "Parameter", + "type": "string", + "optional": true, + "field": "contentToken", + "description": "

content token, left empty for first upload

" + }, + { + "group": "Parameter", + "type": "list", + "optional": false, + "field": "tags", + "description": "

{string} tag

" + } + ] + } + }, "success": { "fields": { "Success 200": [ @@ -1496,6 +1587,13 @@ define({ "api": [ "optional": false, "field": "files", "description": "

{string} fileID : file id
{int32} type : file type 1 for picture, 2 for video

" + }, + { + "group": "Success 200", + "type": "list", + "optional": false, + "field": "tags", + "description": "

{string} tag : tag name

" } ] } @@ -1560,6 +1658,13 @@ define({ "api": [ "optional": true, "field": "type", "description": "

1 for picture
2 for video (note: only delete the file if empty)

" + }, + { + "group": "Parameter", + "type": "array", + "optional": false, + "field": "tags", + "description": "

string array tags, simply overwrite original tags, clear if empty

" } ] } @@ -1826,6 +1931,13 @@ define({ "api": [ "optional": true, "field": "contentToken", "description": "

content token

" + }, + { + "group": "Parameter", + "type": "list", + "optional": true, + "field": "tags", + "description": "

{string} tag

" } ] } diff --git a/backend/doc/api_data.json b/backend/doc/api_data.json index 99f4c37..94a1810 100644 --- a/backend/doc/api_data.json +++ b/backend/doc/api_data.json @@ -1016,6 +1016,13 @@ "optional": true, "field": "contentToken", "description": "

content token

" + }, + { + "group": "Parameter", + "type": "list", + "optional": true, + "field": "tags", + "description": "

{string} tag

" } ] } @@ -1354,6 +1361,90 @@ ] } }, + "success": { + "fields": { + "Success 200": [ + { + "group": "Success 200", + "type": "int32", + "optional": false, + "field": "status", + "description": "

-1 for invalid param
1 for success
2 for invalid token
2 for invalid type

" + }, + { + "group": "Success 200", + "type": "string", + "optional": false, + "field": "contentID", + "description": "

24 bytes contentID

" + }, + { + "group": "Success 200", + "type": "string", + "optional": false, + "field": "contentToken", + "description": "

random uuid content token

" + }, + { + "group": "Success 200", + "type": "string", + "optional": false, + "field": "fileID", + "description": "

24 bytes fileID

" + } + ] + } + }, + "filename": "srv/content/main.go", + "groupTitle": "Service", + "error": { + "fields": { + "Error 500": [ + { + "group": "Error 500", + "optional": false, + "field": "DBServerDown", + "description": "

can't connect to database server

" + } + ] + } + } + }, + { + "type": "rpc", + "url": "/rpc", + "title": "Content.CreateTag", + "version": "1.0.0", + "group": "Service", + "name": "Content_CreateTag", + "description": "

create tags

", + "parameter": { + "fields": { + "Parameter": [ + { + "group": "Parameter", + "type": "string", + "optional": true, + "field": "contentID", + "description": "

24 bytes content id, left empty for first upload

" + }, + { + "group": "Parameter", + "type": "string", + "optional": true, + "field": "contentToken", + "description": "

content token, left empty for first upload

" + }, + { + "group": "Parameter", + "type": "list", + "optional": false, + "field": "tags", + "description": "

{string} tag

" + } + ] + } + }, "success": { "fields": { "Success 200": [ @@ -1496,6 +1587,13 @@ "optional": false, "field": "files", "description": "

{string} fileID : file id
{int32} type : file type 1 for picture, 2 for video

" + }, + { + "group": "Success 200", + "type": "list", + "optional": false, + "field": "tags", + "description": "

{string} tag : tag name

" } ] } @@ -1560,6 +1658,13 @@ "optional": true, "field": "type", "description": "

1 for picture
2 for video (note: only delete the file if empty)

" + }, + { + "group": "Parameter", + "type": "array", + "optional": false, + "field": "tags", + "description": "

string array tags, simply overwrite original tags, clear if empty

" } ] } @@ -1826,6 +1931,13 @@ "optional": true, "field": "contentToken", "description": "

content token

" + }, + { + "group": "Parameter", + "type": "list", + "optional": true, + "field": "tags", + "description": "

{string} tag

" } ] } diff --git a/backend/doc/api_project.js b/backend/doc/api_project.js index 71b19d6..106cb34 100644 --- a/backend/doc/api_project.js +++ b/backend/doc/api_project.js @@ -20,7 +20,7 @@ define({ "apidoc": "0.3.0", "generator": { "name": "apidoc", - "time": "2019-07-29T12:32:59.009Z", + "time": "2019-07-30T09:08:33.007Z", "url": "http://apidocjs.com", "version": "0.17.7" } diff --git a/backend/doc/api_project.json b/backend/doc/api_project.json index 9a7ed28..8c6c1e6 100644 --- a/backend/doc/api_project.json +++ b/backend/doc/api_project.json @@ -20,7 +20,7 @@ "apidoc": "0.3.0", "generator": { "name": "apidoc", - "time": "2019-07-29T12:32:59.009Z", + "time": "2019-07-30T09:08:33.007Z", "url": "http://apidocjs.com", "version": "0.17.7" } From 19c49112d4a3a493cb7b67f1ee13a55a5fdf596e Mon Sep 17 00:00:00 2001 From: sjtuzwj Date: Tue, 30 Jul 2019 17:24:36 +0800 Subject: [PATCH 06/12] feat: media layout + dynamic statistic graph | bug fix: has been issued on github --- .../app/dashboard/dashboard.component.html | 6 ++- .../src/app/dashboard/dashboard.component.ts | 14 +++--- .../info-statistic.component.ts | 44 ++++++++++++++----- admin-frontend/src/app/info.service.ts | 1 + .../app/info/buy-info/buy-info.component.html | 2 +- .../info/buy-info/buy-info.component.spec.ts | 1 + .../app/info/buy-info/buy-info.component.ts | 3 +- .../info/sell-info/sell-info.component.html | 2 +- .../sell-info/sell-info.component.spec.ts | 1 + .../app/infodetail/infodetail.component.css | 6 ++- .../app/infodetail/infodetail.component.html | 28 ++++++------ .../app/infodetail/infodetail.component.ts | 3 ++ admin-frontend/src/app/user.service.ts | 2 +- .../src/app/user/user.component.html | 2 +- .../app/userdetail/userdetail.component.ts | 3 +- 15 files changed, 76 insertions(+), 42 deletions(-) diff --git a/admin-frontend/src/app/dashboard/dashboard.component.html b/admin-frontend/src/app/dashboard/dashboard.component.html index 5eb35cb..7ab487b 100644 --- a/admin-frontend/src/app/dashboard/dashboard.component.html +++ b/admin-frontend/src/app/dashboard/dashboard.component.html @@ -1,5 +1,4 @@ - - + + + diff --git a/admin-frontend/src/app/dashboard/dashboard.component.ts b/admin-frontend/src/app/dashboard/dashboard.component.ts index e80722f..8ac875e 100644 --- a/admin-frontend/src/app/dashboard/dashboard.component.ts +++ b/admin-frontend/src/app/dashboard/dashboard.component.ts @@ -16,18 +16,20 @@ export class DashboardComponent implements OnInit { site : any; hst: any[]; + /* userNum: number; infoNum: number; acInfoNum: number; + */ ngOnInit() { this.getHistory(); this.wbService.getSite().subscribe(s => this.site= s); - this.usService.getUsers().subscribe( e =>this.userNum = e.user.length); - this.ifService.getSellInfos().subscribe( e => { - this.infoNum = e.sellInfo.length; - this.acInfoNum = e.sellInfo.filter( e => e.status < 3).length; - } - ); + //this.usService.getUsers().subscribe( e =>this.userNum = e.user.length); + //this.ifService.getSellInfos().subscribe( e => { + // this.infoNum = e.sellInfo.length; + //this.acInfoNum = e.sellInfo.filter( e => e.status < 3).length; + //} + // ); } getHistory(){ this.wbService.getSiteHistory().subscribe( s =>this.hst =s.sort((a,b)=> a.time-b.time)); diff --git a/admin-frontend/src/app/info-statistic/info-statistic.component.ts b/admin-frontend/src/app/info-statistic/info-statistic.component.ts index 858a289..11fb805 100644 --- a/admin-frontend/src/app/info-statistic/info-statistic.component.ts +++ b/admin-frontend/src/app/info-statistic/info-statistic.component.ts @@ -32,9 +32,32 @@ export class InfoStatisticComponent implements OnInit { this.ts(); this.lq(); this.good(); + this.getMoreBuy(100); + this.getMoreSell(100); } );}) } + getMoreBuy(offset){ + if(!(this.bi.length%100)) + this.is.getBuyInfos(null,null,null,null,offset).subscribe( + e => { + this.bi=this.bi.concat(e.buyInfo); + this.lq(); + this.getMoreBuy(offset+100); + } + ); + } + getMoreSell(offset){ + console.log(this.si.length); + if(!(this.si.length%100)) + this.is.getSellInfos(null,null,null,null,offset).subscribe( + e => { + this.si= this.si.concat(e.sellInfo); + this.lq(); + this.getMoreSell(offset+100); + } + ); + } good() { var data = prepareBoxplotData([ [850, 740, 900, 1070, 930, 850, 950, 980, 980, 880, 1000, 980, 930, 650, 760, 810, 1000, 1000, 960, 960], @@ -43,7 +66,6 @@ export class InfoStatisticComponent implements OnInit { [890, 810, 810, 820, 800, 770, 760, 740, 750, 760, 910, 920, 890, 860, 880, 720, 840, 850, 850, 780], [890, 840, 780, 810, 760, 810, 790, 810, 820, 850, 870, 870, 810, 740, 810, 940, 950, 800, 810, 870] ]); - this.goodoption = { backgroundColor: '#01193d', title: [ @@ -305,29 +327,31 @@ this.goodoption = { return [t.getFullYear(), t.getMonth() + 1, t.getDate()].join('/'); } lq() { - const bd =new Map(); + let bd =new Map(); this.bi.forEach( e => { + if(!e||e.releaseTime<0)return; const str = this.fmt(new Date(e.releaseTime*1000)); if(str in bd) bd[str]+=1; else bd[str]=1; }); - const sd =new Map(); + let sd =new Map(); this.si.forEach( e => { + if(!e||e.releaseTime<0)return; const str = this.fmt(new Date(e.releaseTime*1000)); if(str in sd) sd[str]+=1; else sd[str]=1; }); - const bdata = []; + let bdata = []; for(let i in bd){ bdata.push([i,bd[i]]); } - const sdata = []; + + let sdata = []; for(let i in sd){ - console.log(i); sdata.push([i,sd[i]]); } this.lqoption = { @@ -378,18 +402,14 @@ this.goodoption = { { name: '新增购买信息', type: 'value', - max: function(value) { - return value.max *3/2; - } + max: (value) => value.max*3/2 }, { name: '新增出售信息', nameLocation: 'start', type: 'value', inverse: true, - max: function(value) { - return value.max *3/2; - } + max: (value) => value.max*3/2 } ], series: [ diff --git a/admin-frontend/src/app/info.service.ts b/admin-frontend/src/app/info.service.ts index 100ca1d..2096e94 100644 --- a/admin-frontend/src/app/info.service.ts +++ b/admin-frontend/src/app/info.service.ts @@ -26,6 +26,7 @@ export class InfoService { catchError(this.handleError(`getInfo id=${id}`)) ); } + /** GET infos from the server */ getSellInfos(userID: string = null, status: number = null, goodName: string = null,limit:number=null, offset: number=null): Observable { let url = `${this.sellinfoUrl}?`; diff --git a/admin-frontend/src/app/info/buy-info/buy-info.component.html b/admin-frontend/src/app/info/buy-info/buy-info.component.html index be582ad..610801a 100644 --- a/admin-frontend/src/app/info/buy-info/buy-info.component.html +++ b/admin-frontend/src/app/info/buy-info/buy-info.component.html @@ -6,7 +6,7 @@
- 交易名{{info.goodName}} + 交易名{{info.goodName.length>10? info.goodName.substr(0,10)+'...':info.goodName}}
交易ID{{info.buyInfoID}} diff --git a/admin-frontend/src/app/info/buy-info/buy-info.component.spec.ts b/admin-frontend/src/app/info/buy-info/buy-info.component.spec.ts index be6a390..3c934d3 100644 --- a/admin-frontend/src/app/info/buy-info/buy-info.component.spec.ts +++ b/admin-frontend/src/app/info/buy-info/buy-info.component.spec.ts @@ -84,6 +84,7 @@ describe('BuyInfoComponent', () => { expect(c.getstate(2)).toEqual('预约'); expect(c.getstate(3)).toEqual('完成'); expect(c.getstate(4)).toEqual('失效'); + expect(c.getstate(5)).toEqual('关闭'); expect(c.stringToDate(1563134054)).toEqual('2019-07-15 03:54:14'); c.checkcount(); c.buyinfos= [new buyInfo]; diff --git a/admin-frontend/src/app/info/buy-info/buy-info.component.ts b/admin-frontend/src/app/info/buy-info/buy-info.component.ts index 456ae5f..bf0f27c 100644 --- a/admin-frontend/src/app/info/buy-info/buy-info.component.ts +++ b/admin-frontend/src/app/info/buy-info/buy-info.component.ts @@ -38,12 +38,13 @@ export class BuyInfoComponent implements OnInit { return '完成'; case 4: return '失效'; + case 5: + return '关闭'; } } stringToDate(params) { const date = new Date(params*1000); - console.log(params); return Format(date,'yyyy-MM-dd HH:mm:ss'); } diff --git a/admin-frontend/src/app/info/sell-info/sell-info.component.html b/admin-frontend/src/app/info/sell-info/sell-info.component.html index 5ca5719..1f20c64 100644 --- a/admin-frontend/src/app/info/sell-info/sell-info.component.html +++ b/admin-frontend/src/app/info/sell-info/sell-info.component.html @@ -6,7 +6,7 @@
- 交易名{{info.goodName}} + 交易名{{info.goodName.length>10? info.goodName.substr(0,10)+'...':info.goodName}}
交易ID{{info.sellInfoID}} diff --git a/admin-frontend/src/app/info/sell-info/sell-info.component.spec.ts b/admin-frontend/src/app/info/sell-info/sell-info.component.spec.ts index d67cf3c..d9bb70e 100644 --- a/admin-frontend/src/app/info/sell-info/sell-info.component.spec.ts +++ b/admin-frontend/src/app/info/sell-info/sell-info.component.spec.ts @@ -83,6 +83,7 @@ describe('SellInfoComponent', () => { expect(c.getstate(2)).toEqual('预约'); expect(c.getstate(3)).toEqual('完成'); expect(c.getstate(4)).toEqual('失效'); + expect(c.getstate(5)).toEqual('关闭'); expect(c.stringToDate(1563134054)).toEqual('2019-07-15 03:54:14'); c.checkcount(); c.searchUserID = ''; diff --git a/admin-frontend/src/app/infodetail/infodetail.component.css b/admin-frontend/src/app/infodetail/infodetail.component.css index d692455..418f6bf 100644 --- a/admin-frontend/src/app/infodetail/infodetail.component.css +++ b/admin-frontend/src/app/infodetail/infodetail.component.css @@ -38,4 +38,8 @@ #tag{ width: 50%; } - \ No newline at end of file + + #content{ + width:100%; + height:500px; + } \ No newline at end of file diff --git a/admin-frontend/src/app/infodetail/infodetail.component.html b/admin-frontend/src/app/infodetail/infodetail.component.html index ef50e79..cc25772 100644 --- a/admin-frontend/src/app/infodetail/infodetail.component.html +++ b/admin-frontend/src/app/infodetail/infodetail.component.html @@ -11,11 +11,8 @@ 交易ID{{info.sellInfoID}}
- 交易类型{{'出售'}} + 交易类型{{type=='sellInfo'?'出售':'求购'}}
-
- 交易内容(待微服务){{info.contentID}} -
@@ -72,17 +70,19 @@
-
+
- -
- - -
-
-
+ +
+ + +
+
+ +
+
创建交易 2019-07-01 diff --git a/admin-frontend/src/app/infodetail/infodetail.component.ts b/admin-frontend/src/app/infodetail/infodetail.component.ts index 620f2b3..918ff29 100644 --- a/admin-frontend/src/app/infodetail/infodetail.component.ts +++ b/admin-frontend/src/app/infodetail/infodetail.component.ts @@ -44,6 +44,7 @@ stringToDate(params) { getContent(): void { this.fileService.getContent(this.info.contentID).subscribe( e => { + console.log(e); if(e) this.contents = e.files; } @@ -60,6 +61,7 @@ stringToDate(params) { if(!info)return; this.info = info; this.deadLine = new Date(this.info.validTime*1000); + this.getContent(); }); else if(this.type === 'buyInfo') this.infoService.getBuyInfo(id) @@ -67,6 +69,7 @@ stringToDate(params) { if(!info)return; this.info = info; this.deadLine = new Date(this.info.validTime*1000); + this.getContent(); }); } diff --git a/admin-frontend/src/app/user.service.ts b/admin-frontend/src/app/user.service.ts index 7c0c881..65e341b 100644 --- a/admin-frontend/src/app/user.service.ts +++ b/admin-frontend/src/app/user.service.ts @@ -24,7 +24,7 @@ export class UserService { } /** GET users from the server */ getUsers(): Observable { - const url = `${this.usersUrl}`; + const url = `${this.usersUrl}?limit=100000`; return this.http.get(url,httpOptions) .pipe( catchError(this.handleError('getUsers')) diff --git a/admin-frontend/src/app/user/user.component.html b/admin-frontend/src/app/user/user.component.html index f4529f4..b47f2b5 100644 --- a/admin-frontend/src/app/user/user.component.html +++ b/admin-frontend/src/app/user/user.component.html @@ -30,7 +30,7 @@

用户管理

用户ID{{user.userID}}
- 用户名{{user.userName}} + 用户名{{user.userName.length>10?user.userName.substr(0,10)+'...':user.userName}}
封禁{{user.status==2?'是':'否'}} diff --git a/admin-frontend/src/app/userdetail/userdetail.component.ts b/admin-frontend/src/app/userdetail/userdetail.component.ts index 9e3d0df..1b466e2 100644 --- a/admin-frontend/src/app/userdetail/userdetail.component.ts +++ b/admin-frontend/src/app/userdetail/userdetail.component.ts @@ -112,8 +112,7 @@ this.infos.forEach(element => { title: { }, legend: { - data: ['Record'], - left: 'right' + data: ['出售', '求购'] }, polar: {}, tooltip: { From 7464a95840df2169a7c1413d55fc6be9c1b5cb32 Mon Sep 17 00:00:00 2001 From: sjtuzwj Date: Wed, 31 Jul 2019 11:43:47 +0800 Subject: [PATCH 07/12] feat: dynamic data query(double polling with different period: render/get) / pause button to pause render polling --- .../info-statistic.component.html | 6 +- .../info-statistic.component.ts | 106 +++++++----------- admin-frontend/src/app/info.service.ts | 65 +++++++++++ 3 files changed, 113 insertions(+), 64 deletions(-) diff --git a/admin-frontend/src/app/info-statistic/info-statistic.component.html b/admin-frontend/src/app/info-statistic/info-statistic.component.html index 3a3fba8..9b54ea1 100644 --- a/admin-frontend/src/app/info-statistic/info-statistic.component.html +++ b/admin-frontend/src/app/info-statistic/info-statistic.component.html @@ -16,7 +16,11 @@
-
+
+
\ No newline at end of file diff --git a/admin-frontend/src/app/info-statistic/info-statistic.component.ts b/admin-frontend/src/app/info-statistic/info-statistic.component.ts index 11fb805..8942b39 100644 --- a/admin-frontend/src/app/info-statistic/info-statistic.component.ts +++ b/admin-frontend/src/app/info-statistic/info-statistic.component.ts @@ -20,6 +20,7 @@ export class InfoStatisticComponent implements OnInit { goodoption: any; bi: buyInfo[]; si: sellInfo[]; + pl: boolean = false; constructor(private is: InfoService) { } ngOnInit() { this.is.getBuyInfos().subscribe( @@ -31,32 +32,26 @@ export class InfoStatisticComponent implements OnInit { this.fdg(); this.ts(); this.lq(); - this.good(); - this.getMoreBuy(100); - this.getMoreSell(100); + this.good(); + this.bi = this.is.getAllBuyInfo(); + this.si = this.is.getAllSellInfo(); + this.getAllInfo(); } );}) } - getMoreBuy(offset){ - if(!(this.bi.length%100)) - this.is.getBuyInfos(null,null,null,null,offset).subscribe( - e => { - this.bi=this.bi.concat(e.buyInfo); - this.lq(); - this.getMoreBuy(offset+100); - } - ); + pauseLine(){ + this.pl=!this.pl; } - getMoreSell(offset){ - console.log(this.si.length); - if(!(this.si.length%100)) - this.is.getSellInfos(null,null,null,null,offset).subscribe( - e => { - this.si= this.si.concat(e.sellInfo); - this.lq(); - this.getMoreSell(offset+100); - } - ); + getAllInfo(){ + + setTimeout(() => { + this.bi = this.is.getAllBuyInfo(); + this.bi = this.bi.sort( (a,b) => a.releaseTime - b.releaseTime); + this.si = this.is.getAllSellInfo(); + this.si = this.si.sort( (a,b) => a.releaseTime - b.releaseTime); + if(!this.pl)this.lq(); + this.getAllInfo(); + }, 10000); } good() { var data = prepareBoxplotData([ @@ -415,69 +410,54 @@ this.goodoption = { series: [ { name: '购买', - type: 'line', - animation: false, - smooth: true, - showAllSymbol: true, + yAxisIndex: 0, + type:'line', + smooth:true, symbol: 'circle', - symbolSize: 6, + symbolSize: 1, + sampling: 'average', + itemStyle: { + normal: { + color: '#d68262' + } + }, areaStyle: { normal: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, - color: 'rgba(137, 189, 27, 0.9)' + color: '#d68262' }, { - offset: 0.8, - color: 'rgba(137, 189, 27, 0)' - }], false), - shadowColor: 'rgba(0, 0, 0, 0.1)', - shadowBlur: 10 - } - }, - itemStyle: { - normal: { - color: 'rgb(137,189,27)', - borderColor: 'rgba(137,189,2,0.27)', - borderWidth: 12 + offset: 1, + color: '#ffe' + }]) } }, - lineStyle: { - width: 1 - }, data: bdata }, { name: '出售', type: 'line', yAxisIndex: 1, - animation: false, + symbolSize: 1, smooth: true, - showAllSymbol: true, symbol: 'circle', - symbolSize: 6, - areaStyle: { + sampling: 'average', + itemStyle: { normal: { - color: new echarts.graphic.LinearGradient(0, 1, 0,0 , [{ - offset: 0, - color: 'rgba(219, 50, 51, 0.9)' - }, { - offset: 0.8, - color: 'rgba(219, 50, 51, 0)' - }], false), - shadowColor: 'rgba(0, 0, 0, 0.1)', - shadowBlur: 10 + color: '#8ec6ad' } }, - itemStyle: { + areaStyle: { normal: { - color: 'rgb(219,50,51)', - borderColor: 'rgba(219,50,51,0.2)', - borderWidth: 12 + color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ + offset: 0, + color: '#8ec6ad' + }, { + offset: 1, + color: '#ffe' + }]) } }, - lineStyle: { - width: 1 - }, data: sdata } ] diff --git a/admin-frontend/src/app/info.service.ts b/admin-frontend/src/app/info.service.ts index 2096e94..7793460 100644 --- a/admin-frontend/src/app/info.service.ts +++ b/admin-frontend/src/app/info.service.ts @@ -4,6 +4,7 @@ import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable, of } from 'rxjs'; import { catchError, map, tap } from 'rxjs/operators'; import { sellInfo, buyInfo, InfoResponse } from './entity/info'; +import { query } from '\@angular/animations'; const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) @@ -17,8 +18,72 @@ export class InfoService { private sellinfoUrl = 'api/sellInfo'; // URL to web api private buyinfoUrl = 'api/buyInfo'; constructor(private http: HttpClient) { } + bi: buyInfo[]; + si: sellInfo[]; + getAllSellInfo(): sellInfo[]{ + if(!this.si) + { + this.getSellInfos().subscribe(e=> + { + this.si = e.sellInfo; + this.getMoreSell(100,false); + }) + } + return this.si; + } + + getAllBuyInfo(): buyInfo[]{ + if(!this.bi) + { + this.getBuyInfos().subscribe(e=> + { + this.bi = e.buyInfo; + this.getMoreBuy(100,false); + }) + } + return this.bi; + } + + getMoreBuy(offset, dynamic){ + if(!(this.bi.length%100) && !dynamic) + this.getBuyInfos(null,null,null,null,offset).subscribe( + e => { + this.bi=this.bi.concat(e.buyInfo); + this.getMoreBuy(offset+100, false); + } + ); + else{ + setTimeout(() => { + this.getBuyInfos(null,null,null,null,offset).subscribe( + e => { + if(e.buyInfo) + this.bi=this.bi.concat(e.buyInfo); + this.getMoreBuy(this.bi.length-1, true); + } + );}, 5000 ); + } +} +getMoreSell(offset, dynamic){ + if(!(this.si.length%100) && !dynamic) + this.getSellInfos(null,null,null,null,offset).subscribe( + e => { + this.si= this.si.concat(e.sellInfo); + this.getMoreSell(offset+100, false); + } + ); + else{ + setTimeout(() => { + this.getSellInfos(null,null,null,null,offset).subscribe( + e => { + if(e.sellInfo) + this.si=this.si.concat(e.sellInfo); + this.getMoreSell(this.si.length-1,true); + } + );}, 5000 ); + } +} /** GET info by id. Will 404 if id not found */ getSellInfo(id: string): Observable { const url = `${this.sellinfoUrl}/${id}`; From 41c808b2901a8b08831cd5d5c354417513ac1eed Mon Sep 17 00:00:00 2001 From: sjtuzwj Date: Wed, 31 Jul 2019 17:24:28 +0800 Subject: [PATCH 08/12] feat: line+calendar+force graph with dynamic data| bug need to fix: array level asyc+ avoid concat undefined --- .../info-statistic.component.css | 6 + .../info-statistic.component.html | 11 +- .../info-statistic.component.spec.ts | 4 - .../info-statistic.component.ts | 300 +++++++++++------- admin-frontend/src/app/info.service.ts | 29 +- .../app/infodetail/infodetail.component.ts | 2 +- 6 files changed, 213 insertions(+), 139 deletions(-) diff --git a/admin-frontend/src/app/info-statistic/info-statistic.component.css b/admin-frontend/src/app/info-statistic/info-statistic.component.css index ab1b79d..bc4f77b 100644 --- a/admin-frontend/src/app/info-statistic/info-statistic.component.css +++ b/admin-frontend/src/app/info-statistic/info-statistic.component.css @@ -57,3 +57,9 @@ height: 39%; background: #01193d; } + +#pause{ + position: absolute; + right: 0%; + bottom: 0%; +} \ No newline at end of file diff --git a/admin-frontend/src/app/info-statistic/info-statistic.component.html b/admin-frontend/src/app/info-statistic/info-statistic.component.html index 9b54ea1..1874670 100644 --- a/admin-frontend/src/app/info-statistic/info-statistic.component.html +++ b/admin-frontend/src/app/info-statistic/info-statistic.component.html @@ -17,10 +17,11 @@
- -
+
+
+
\ No newline at end of file diff --git a/admin-frontend/src/app/info-statistic/info-statistic.component.spec.ts b/admin-frontend/src/app/info-statistic/info-statistic.component.spec.ts index 13442b4..3f6b7ad 100644 --- a/admin-frontend/src/app/info-statistic/info-statistic.component.spec.ts +++ b/admin-frontend/src/app/info-statistic/info-statistic.component.spec.ts @@ -74,10 +74,6 @@ describe('InfoStatisticComponent', () => { expect(component).toBeTruthy(); component.bi = [ new buyInfo()]; component.si = [ new sellInfo()]; - component.good(); - component.lq(); - component.fdg(); - component.ts(); expect(component.fmt(new Date(1563134054000))).toEqual('2019/7/15'); }); }); diff --git a/admin-frontend/src/app/info-statistic/info-statistic.component.ts b/admin-frontend/src/app/info-statistic/info-statistic.component.ts index 8942b39..01994b5 100644 --- a/admin-frontend/src/app/info-statistic/info-statistic.component.ts +++ b/admin-frontend/src/app/info-statistic/info-statistic.component.ts @@ -4,6 +4,9 @@ import * as echarts from 'echarts/lib/echarts'; import { InfoService } from '../info.service'; import { buyInfo, sellInfo } from 'src/app/entity/info'; import {prepareBoxplotData} from 'echarts/extension/dataTool'; +import { Transaction } from '../entity/transaction'; +import { TransactionService } from '../transaction.service'; +import { Format } from '../Formatter/format'; const name = ['LJH', 'WXZ', 'ZWJ', 'KHQ', 'MZD', 'ZEL', 'JZM', 'HJT', 'TRUMP', 'LJH2', 'WXZ2', 'ZWJ2', 'KHQ2', 'MZD2', 'ZEL2', 'JZM2', 'HJT2', 'TRUMP2', 'LJH3', 'WXZ3', 'ZWJ3', 'KHQ3', 'MZD3', 'ZEL3', 'JZM3', 'HJT3', 'TRUMP3']; @@ -18,42 +21,57 @@ export class InfoStatisticComponent implements OnInit { tsoption: any; lqoption: any; goodoption: any; - bi: buyInfo[]; - si: sellInfo[]; + bi: buyInfo[]=[]; + si: sellInfo[]=[]; + tr: Transaction[]=[]; pl: boolean = false; - constructor(private is: InfoService) { } + constructor(private trs: TransactionService, private is: InfoService) { } ngOnInit() { this.is.getBuyInfos().subscribe( e => {this.bi = e.buyInfo; this.is.getSellInfos().subscribe( e => { this.si = e.sellInfo; - this.cld(); - this.fdg(); - this.ts(); - this.lq(); - this.good(); + this.cloudGrpah(); + this.forceGraph(); + this.calenderGraph(); + this.lineGraph(); + this.boxGraph(); + const now = new Date().getFullYear() + this.tr = this.trs.getAllTR(6,new Date(now,1,1).getTime()/1000, new Date(now+1,1,1).getTime()/1000); this.bi = this.is.getAllBuyInfo(); this.si = this.is.getAllSellInfo(); this.getAllInfo(); + this.getAllTR(new Date(now,1,1).getTime()/1000, new Date(now+1,1,1).getTime()/1000); } );}) } pauseLine(){ this.pl=!this.pl; } - getAllInfo(){ + getAllTR(beg, end){ + setTimeout(() => { + this.tr = this.trs.getAllTR(6,beg,end); + if(!this.pl){ + this.calenderGraph(); + this.forceGraph(); + } + this.getAllTR(beg,end); + }, 10000); + } + getAllInfo(){ setTimeout(() => { this.bi = this.is.getAllBuyInfo(); this.bi = this.bi.sort( (a,b) => a.releaseTime - b.releaseTime); this.si = this.is.getAllSellInfo(); this.si = this.si.sort( (a,b) => a.releaseTime - b.releaseTime); - if(!this.pl)this.lq(); + if(!this.pl)this.lineGraph(); this.getAllInfo(); }, 10000); } - good() { + + boxGraph() { var data = prepareBoxplotData([ [850, 740, 900, 1070, 930, 850, 950, 980, 980, 880, 1000, 980, 930, 650, 760, 810, 1000, 1000, 960, 960], [960, 940, 960, 940, 880, 800, 850, 880, 900, 840, 830, 790, 810, 880, 880, 830, 800, 790, 760, 800], @@ -140,7 +158,68 @@ this.goodoption = { ] }; } - ts() { + cloudGrpah() { + this.cldoption = { + backgroundColor: '#01193d', + title: { + text: 'Label WordCloud', + left: 'center', + }, + tooltip: {}, + series: [{ + type: 'wordCloud', + shape: 'circle', + + left: 'center', + top: 'center', + sizeRange: [12, 30], + rotationRange: [-90, 90], + rotationStep: 45, + gridSize: 8, + drawOutOfBound: false, + textStyle: { + normal: { + fontFamily: 'sans-serif', + fontWeight: 'bold', + color: () => { + // Random color + return 'rgb(' + [ + Math.round(Math.random() * 250), + Math.round(Math.random() * 250), + Math.round(Math.random() * 250) + ].join(',') + ')'; + } + }, + emphasis: { + shadowBlur: 10, + shadowColor: '#333' + } + }, + data: name.map( node => {return { name: node, + value: Math.round(Math.random() * 1000), + textStyle: { + normal: {}, + emphasis: {} + } + }; } + ) + }] +}; + } + calenderGraph() { + let td =new Map(); + this.tr.forEach( e => { + if(!e)return; + const str = Format(new Date(e.createTime*1000),'yyyy-MM-dd'); + if(str in td) + td[str]+=1; + else + td[str]=1; + }); + let tdata = []; + for(let i in td){ + tdata.push([i,td[i]]); + } this.tsoption = { backgroundColor: '#01193d', title: { @@ -194,134 +273,117 @@ this.goodoption = { type: 'effectScatter', coordinateSystem: 'calendar', symbolSize: (val) => { - return val[1] / 40; + return val[1]; }, showEffectOn: 'render', rippleEffect: { brushType: 'stroke' }, hoverAnimation: true, + tooltip: { + formatter:(param)=> + param.data[1] + ' completed transactions created in ' +param.data[0] + }, itemStyle: { color: '#f4e925', shadowBlur: 10, shadowColor: '#333' }, - data: [['2019-01-02', 900], ['2019-01-03', 877], ['2019-01-04', 699], ['2019-01-07', 200], ['2019-01-10', 100], - ['2019-01-10', 430], ['2019-02-01', 250], ['2019-02-10', 430], - ['2019-03-10', 430], ['2019-04-01', 250], ['2019-05-10', 430], - ['2019-08-11', 430], ['2019-07-04', 250], ['2019-03-11', 430], - ['2019-09-23', 430], ['2019-06-01', 250], ['2019-12-12', 430]] + data: tdata }] }; } - cld() { - this.cldoption = { - backgroundColor: '#01193d', - title: { - text: 'Label WordCloud', - left: 'center', - }, - tooltip: {}, - series: [{ - type: 'wordCloud', - shape: 'circle', - - left: 'center', - top: 'center', - sizeRange: [12, 30], - rotationRange: [-90, 90], - rotationStep: 45, - gridSize: 8, - drawOutOfBound: false, - textStyle: { - normal: { - fontFamily: 'sans-serif', - fontWeight: 'bold', - color: () => { - // Random color - return 'rgb(' + [ - Math.round(Math.random() * 250), - Math.round(Math.random() * 250), - Math.round(Math.random() * 250) - ].join(',') + ')'; + forceGraph() { + let td =new Map(); + this.tr.forEach( e => { + if(!e)return; + if(e.category==2) + this.is.getBuyInfo(e.infoID).subscribe(info => { + const other = info.userID; + if(e.userID in td) + if(other in td[e.userID]) + td[e.userID][td] +=1; + else td[e.userID][td] =1; + else { + td[e.userID] = new Map(); + td[e.userID][td] = 1; + } + }); + if(e.category==1) + this.is.getSellInfo(e.infoID).subscribe(info => { + const other = info.userID; + if(other in td) + if(e.userID in td[other]) + td[other][e.userID] +=1; + else td[other][e.userID] =1; + else { + td[other] = new Map(); + td[other][e.userID] = 1; + } + }); + }); + setTimeout(( )=> { + const E = []; + const V = []; + for( let i in td){ + let sum = 0; + for( let j in td[i]){ + E.push( + {source: i, target: j + , value: td[i][j], lineStyle: { + width: td[i][j] + }}); + sum += td[i][j]; + } + V.push({name: i, itemStyle: { + color: '#60acfc' + }, value : sum, symbolSize: sum*5, + draggable: true}) + } + this.fdgoption = { + backgroundColor: '#01193d', + title: { + text: 'Transaction Network', + left: 'center', + }, + tooltip: {}, + animationDurationUpdate: 1500, + animationEasingUpdate: 'quinticInOut', + series : [ + { + type: 'graph', + layout: 'force', + data: V, edges: E, + label: { + emphasis: { + position: 'right', + show: true } }, - emphasis: { - shadowBlur: 10, - shadowColor: '#333' - } - }, - data: name.map( node => {return { name: node, - value: Math.round(Math.random() * 1000), - textStyle: { - normal: {}, - emphasis: {} - } - }; } - ) - }] -}; - } - fdg() { - const E = name.map(node => { - const e = Math.floor(Math.random() * 10); - return {source: node, target: name[Math.floor(Math.random() * 27)] - , value: e, lineStyle: { - width: e * 0.3 - }}; - }).filter(node => node.source !== node.target); - const V = name.map(node => { - const v = E.filter(n => n.source === node || n.target === node ).reduce((total, currentValue, currentIndex, arr) => { - return total + currentValue.value; - }, 0); - return { name: node, - itemStyle: { - color: '#60acfc' - }, value : v, symbolSize: v, - draggable: true}; -}); - this.fdgoption = { - backgroundColor: '#01193d', - title: { - text: 'Transaction Network', - left: 'center', - }, - tooltip: {}, - animationDurationUpdate: 1500, - animationEasingUpdate: 'quinticInOut', - series : [ - { - type: 'graph', - layout: 'force', - data: V, edges: E, - label: { - emphasis: { - position: 'right', - show: true - } - }, - force: { - repulsion : 100 - }, - roam: true, - focusNodeAdjacency: true, - lineStyle: { - normal: { - color :'source', - type : 'solid', - width: 0.5, - curveness: 0.2, - opacity: 0.7 + force: { + repulsion : 100 + }, + roam: true, + focusNodeAdjacency: true, + lineStyle: { + normal: { + color :'source', + type : 'solid', + width: 0.5, + curveness: 0.2, + opacity: 0.7 + } } } - } - ] - }; + ] + }; + + },1000) } fmt(t: Date) { return [t.getFullYear(), t.getMonth() + 1, t.getDate()].join('/'); } - lq() { + lineGraph() { let bd =new Map(); this.bi.forEach( e => { if(!e||e.releaseTime<0)return; @@ -438,7 +500,7 @@ this.goodoption = { name: '出售', type: 'line', yAxisIndex: 1, - symbolSize: 1, + symbolSize: 5, smooth: true, symbol: 'circle', sampling: 'average', diff --git a/admin-frontend/src/app/info.service.ts b/admin-frontend/src/app/info.service.ts index 7793460..95b9cc9 100644 --- a/admin-frontend/src/app/info.service.ts +++ b/admin-frontend/src/app/info.service.ts @@ -27,7 +27,7 @@ export class InfoService { this.getSellInfos().subscribe(e=> { this.si = e.sellInfo; - this.getMoreSell(100,false); + this.getMoreSell(100,false); }) } return this.si; @@ -49,17 +49,22 @@ export class InfoService { if(!(this.bi.length%100) && !dynamic) this.getBuyInfos(null,null,null,null,offset).subscribe( e => { + if(e){ this.bi=this.bi.concat(e.buyInfo); - this.getMoreBuy(offset+100, false); - } + if(e.buyInfo.length!=100) + dynamic =! dynamic; + } + this.getMoreBuy(offset+100, dynamic); + } ); else{ setTimeout(() => { this.getBuyInfos(null,null,null,null,offset).subscribe( e => { - if(e.buyInfo) + if(e) this.bi=this.bi.concat(e.buyInfo); this.getMoreBuy(this.bi.length-1, true); + console.log(this.bi); } );}, 5000 ); } @@ -69,15 +74,19 @@ getMoreSell(offset, dynamic){ if(!(this.si.length%100) && !dynamic) this.getSellInfos(null,null,null,null,offset).subscribe( e => { - this.si= this.si.concat(e.sellInfo); - this.getMoreSell(offset+100, false); - } + if(e){ + this.si= this.si.concat(e.sellInfo); + if(e.sellInfo.length!=100) + dynamic=!dynamic; + } + this.getMoreSell(offset+100,dynamic) + } ); else{ setTimeout(() => { this.getSellInfos(null,null,null,null,offset).subscribe( e => { - if(e.sellInfo) + if(e) this.si=this.si.concat(e.sellInfo); this.getMoreSell(this.si.length-1,true); } @@ -85,7 +94,7 @@ getMoreSell(offset, dynamic){ } } /** GET info by id. Will 404 if id not found */ - getSellInfo(id: string): Observable { + getSellInfo(id: number): Observable { const url = `${this.sellinfoUrl}/${id}`; return this.http.get(url).pipe( catchError(this.handleError(`getInfo id=${id}`)) @@ -128,7 +137,7 @@ getMoreSell(offset, dynamic){ } /** GET info by id. Will 404 if id not found */ - getBuyInfo(id: string): Observable { + getBuyInfo(id: number): Observable { const url = `${this.buyinfoUrl}/${id}`; return this.http.get(url).pipe( catchError(this.handleError(`getBuy id=${id}`)) diff --git a/admin-frontend/src/app/infodetail/infodetail.component.ts b/admin-frontend/src/app/infodetail/infodetail.component.ts index 918ff29..0b9f46a 100644 --- a/admin-frontend/src/app/infodetail/infodetail.component.ts +++ b/admin-frontend/src/app/infodetail/infodetail.component.ts @@ -54,7 +54,7 @@ stringToDate(params) { this.location.back(); } getinfo(): void { - const id = this.route.snapshot.paramMap.get('id'); + const id = parseInt(this.route.snapshot.paramMap.get('id')); if(this.type === 'sellInfo') this.infoService.getSellInfo(id) .subscribe(info => { From 50066471a6095be57065b8e69e3a85815640d200 Mon Sep 17 00:00:00 2001 From: MXWXZ Date: Thu, 1 Aug 2019 09:57:49 +0800 Subject: [PATCH 09/12] code clean --- backend/api/auth/main.go | 4 +- backend/api/avatar/main.go | 22 +-- backend/api/buyinfo/main.go | 6 +- backend/api/content/main.go | 22 +-- backend/api/file/main.go | 4 +- backend/api/sellinfo/main.go | 6 +- backend/api/transaction/main.go | 6 +- backend/api/user/main.go | 8 +- backend/doc/api_data.js | 28 +-- backend/doc/api_data.json | 28 +-- backend/doc/api_project.js | 2 +- backend/doc/api_project.json | 2 +- backend/srv/auth/main.go | 6 +- backend/srv/avatar/main.go | 11 +- backend/srv/buyinfo/main.go | 27 +-- backend/srv/content/main.go | 166 +++++++---------- backend/srv/content/mock/mock.go | 6 + backend/srv/content/proto/content.pb.go | 233 +++++++++--------------- backend/srv/content/proto/content.proto | 25 +-- backend/srv/file/main.go | 8 +- backend/srv/sellinfo/main.go | 27 +-- backend/srv/transaction/main.go | 10 +- backend/srv/user/main.go | 10 +- backend/utils/function.go | 2 + 24 files changed, 287 insertions(+), 382 deletions(-) diff --git a/backend/api/auth/main.go b/backend/api/auth/main.go index 09cadf4..ab0bcd7 100644 --- a/backend/api/auth/main.go +++ b/backend/api/auth/main.go @@ -69,7 +69,7 @@ func getAuth(c *gin.Context) { rsp, err := srv.Auth(context.TODO(), &auth.AuthRequest{ Code: code.Code, }) - if utils.LogContinue(err, utils.Warning, "Auth service error: %v", err) { + if utils.LogContinue(err, utils.Error) { c.JSON(500, err) return } @@ -81,7 +81,7 @@ func getAuth(c *gin.Context) { StudentID: rsp.StudentID, StudentName: rsp.StudentName, }) - if utils.LogContinue(err, utils.Warning, "User service error: %v", err) { + if utils.LogContinue(err, utils.Error) { c.JSON(500, err) return } diff --git a/backend/api/avatar/main.go b/backend/api/avatar/main.go index 73fc630..3ea3b9e 100644 --- a/backend/api/avatar/main.go +++ b/backend/api/avatar/main.go @@ -35,40 +35,26 @@ func addAvatar(c *gin.Context) { } var p param - file, err := c.FormFile("file") + data, code, err := utils.GetQueryFile(c, "file", 1024*1024*5) // 5M if err == nil && !utils.LogContinue(c.ShouldBind(&p), utils.Warning) { - if file.Size > 1024*1024*5 { // 5M - c.AbortWithStatus(413) + if code != 200 { + c.AbortWithStatus(code) return } role := utils.GetRoleID(c, p.UserID) - if !role.Self && !role.Admin { c.AbortWithStatus(403) return } - f, err := file.Open() - if utils.LogContinue(err, utils.Warning) { - c.JSON(500, err) - return - } - defer f.Close() - data := make([]byte, file.Size) - _, err = f.Read(data) - if utils.LogContinue(err, utils.Warning) { - c.JSON(500, err) - return - } - srv := utils.CallMicroService("avatar", func(name string, c client.Client) interface{} { return avatar.NewAvatarService(name, c) }, func() interface{} { return mock.NewAvatarService() }).(avatar.AvatarService) rsp, err := srv.Create(context.TODO(), &avatar.AvatarCreateRequest{ UserID: p.UserID, File: data, }) - if utils.LogContinue(err, utils.Warning, "Avatar service error: %v", err) { + if utils.LogContinue(err, utils.Error) { c.JSON(500, err) return } diff --git a/backend/api/buyinfo/main.go b/backend/api/buyinfo/main.go index 99b3fda..e068935 100644 --- a/backend/api/buyinfo/main.go +++ b/backend/api/buyinfo/main.go @@ -48,7 +48,7 @@ func getBuyInfo(c *gin.Context) { rsp, err := srv.Query(context.TODO(), &buyinfo.BuyInfoQueryRequest{ BuyInfoID: p.BuyInfoID, }) - if utils.LogContinue(err, utils.Warning, "BuyInfo service error: %v", err) { + if utils.LogContinue(err, utils.Error) { c.JSON(500, err) return } @@ -107,7 +107,7 @@ func addBuyInfo(c *gin.Context) { UserID: p.UserID, Tags: p.Tags, }) - if utils.LogContinue(err, utils.Warning, "BuyInfo service error: %v", err) { + if utils.LogContinue(err, utils.Error) { c.JSON(500, err) return } @@ -154,7 +154,7 @@ func findBuyInfo(c *gin.Context) { Limit: p.Limit, Offset: p.Offset, }) - if utils.LogContinue(err, utils.Warning, "BuyInfo service error: %v", err) { + if utils.LogContinue(err, utils.Error) { c.JSON(500, err) return } diff --git a/backend/api/content/main.go b/backend/api/content/main.go index f158a2a..922b6fc 100644 --- a/backend/api/content/main.go +++ b/backend/api/content/main.go @@ -72,9 +72,9 @@ func addContent(c *gin.Context) { ContentID: p.ContentID, ContentToken: p.ContentToken, Content: data, - Type: content.ContentCreateRequest_Type(p.Type), + Type: content.Type(p.Type), }) - if utils.LogContinue(err, utils.Warning, "Content service error: %v", err) { + if utils.LogContinue(err, utils.Error) { c.JSON(500, err) return } @@ -116,7 +116,7 @@ func deleteContent(c *gin.Context) { ContentID: p.ContentID, ContentToken: p.ContentToken, }) - if utils.LogContinue(err, utils.Warning, "Content service error: %v", err) { + if utils.LogContinue(err, utils.Error) { c.JSON(500, err) return } @@ -141,11 +141,10 @@ func deleteContent(c *gin.Context) { */ func updateContent(c *gin.Context) { type param struct { - ContentID string `form:"contentID" binding:"required"` - ContentToken string `form:"contentToken" binding:"required"` - FileID string `form:"fileID" binding:"required"` - Type int32 `form:"type"` - Tags []string `form:"tags" binding:"required"` + ContentID string `form:"contentID" binding:"required"` + ContentToken string `form:"contentToken" binding:"required"` + FileID string `form:"fileID" binding:"required"` + Type int32 `form:"type"` } var p param role := utils.GetRole(c) @@ -173,10 +172,9 @@ func updateContent(c *gin.Context) { ContentToken: p.ContentToken, FileID: p.FileID, Content: data, - Type: content.ContentUpdateRequest_Type(p.Type), - Tags: p.Tags, + Type: content.Type(p.Type), }) - if utils.LogContinue(err, utils.Warning, "Content service error: %v", err) { + if utils.LogContinue(err, utils.Error) { c.JSON(500, err) return } @@ -222,7 +220,7 @@ func getContent(c *gin.Context) { rsp, err := srv.Query(context.TODO(), &content.ContentQueryRequest{ ContentID: p.ContentID, }) - if utils.LogContinue(err, utils.Warning, "Content service error: %v", err) { + if utils.LogContinue(err, utils.Error) { c.JSON(500, err) return } diff --git a/backend/api/file/main.go b/backend/api/file/main.go index 4720e7c..65d1ad3 100644 --- a/backend/api/file/main.go +++ b/backend/api/file/main.go @@ -50,7 +50,7 @@ func getFile(c *gin.Context) { rsp, err := srv.Query(context.TODO(), &file.FileRequest{ FileID: p.FileID, }) - if utils.LogContinue(err, utils.Warning, "File service error: %v", err) { + if utils.LogContinue(err, utils.Error) { c.JSON(500, err) return } @@ -58,7 +58,7 @@ func getFile(c *gin.Context) { if rsp.Status == file.FileQueryResponse_SUCCESS { if filetype.IsImage(rsp.File) || filetype.IsAudio(rsp.File) || filetype.IsVideo(rsp.File) { t, err := filetype.Match(rsp.File) - if utils.LogContinue(err, utils.Warning, "File format error: %v", err) { + if utils.LogContinue(err, utils.Error) { c.JSON(500, err) return } diff --git a/backend/api/sellinfo/main.go b/backend/api/sellinfo/main.go index 28f698d..1ae08dc 100644 --- a/backend/api/sellinfo/main.go +++ b/backend/api/sellinfo/main.go @@ -48,7 +48,7 @@ func getSellInfo(c *gin.Context) { rsp, err := srv.Query(context.TODO(), &sellinfo.SellInfoQueryRequest{ SellInfoID: p.SellInfoID, }) - if utils.LogContinue(err, utils.Warning, "SellInfo service error: %v", err) { + if utils.LogContinue(err, utils.Error) { c.JSON(500, err) return } @@ -107,7 +107,7 @@ func addSellInfo(c *gin.Context) { UserID: p.UserID, Tags: p.Tags, }) - if utils.LogContinue(err, utils.Warning, "SellInfo service error: %v", err) { + if utils.LogContinue(err, utils.Error) { c.JSON(500, err) return } @@ -154,7 +154,7 @@ func findSellInfo(c *gin.Context) { Limit: p.Limit, Offset: p.Offset, }) - if utils.LogContinue(err, utils.Warning, "SellInfo service error: %v", err) { + if utils.LogContinue(err, utils.Error) { c.JSON(500, err) return } diff --git a/backend/api/transaction/main.go b/backend/api/transaction/main.go index 41f4e08..5540ae4 100644 --- a/backend/api/transaction/main.go +++ b/backend/api/transaction/main.go @@ -73,7 +73,7 @@ func findTransaction(c *gin.Context) { Limit: p.Limit, Offset: p.Offset, }) - if utils.LogContinue(err, utils.Warning, "Transaction service error: %v", err) { + if utils.LogContinue(err, utils.Error) { c.JSON(500, err) return } @@ -117,7 +117,7 @@ func addTransaction(c *gin.Context) { Category: p.Category, FromUserID: p.FromUserID, }) - if utils.LogContinue(err, utils.Warning, "Transaction service error: %v", err) { + if utils.LogContinue(err, utils.Error) { c.JSON(500, err) return } @@ -159,7 +159,7 @@ func updateTransaction(c *gin.Context) { TransactionID: p.TransactionID, Status: p.Status, }) - if utils.LogContinue(err, utils.Warning, "Transaction service error: %v", err) { + if utils.LogContinue(err, utils.Error) { c.JSON(500, err) return } diff --git a/backend/api/user/main.go b/backend/api/user/main.go index 0225e1b..a8ba1c7 100644 --- a/backend/api/user/main.go +++ b/backend/api/user/main.go @@ -53,7 +53,7 @@ func getUserInfo(c *gin.Context) { rsp, err := srv.Query(context.TODO(), &user.UserQueryRequest{ UserID: p.UserID, }) - if utils.LogContinue(err, utils.Warning, "User service error: %v", err) { + if utils.LogContinue(err, utils.Error) { c.JSON(500, err) return } @@ -103,7 +103,7 @@ func findUser(c *gin.Context) { Limit: p.Limit, Offset: p.Offset, }) - if utils.LogContinue(err, utils.Warning, "User service error: %v", err) { + if utils.LogContinue(err, utils.Error) { c.JSON(500, err) return } @@ -151,7 +151,7 @@ func addUser(c *gin.Context) { StudentID: p.StudentID, StudentName: p.StudentName, }) - if utils.LogContinue(err, utils.Warning, "User service error: %v", err) { + if utils.LogContinue(err, utils.Error) { c.JSON(500, err) return } @@ -214,7 +214,7 @@ func updateUser(c *gin.Context) { Role: user.UserInfo_Role(p.Role), ClearEmpty: p.ClearEmpty, }) - if utils.LogContinue(err, utils.Warning, "User service error: %v", err) { + if utils.LogContinue(err, utils.Error) { c.JSON(500, err) return } diff --git a/backend/doc/api_data.js b/backend/doc/api_data.js index 163776f..a3bbd2d 100644 --- a/backend/doc/api_data.js +++ b/backend/doc/api_data.js @@ -1511,6 +1511,13 @@ define({ "api": [ "optional": false, "field": "contentToken", "description": "

content token

" + }, + { + "group": "Parameter", + "type": "string", + "optional": true, + "field": "fileID", + "description": "

24 bytes file id, if not empty only delete this file

" } ] } @@ -1648,23 +1655,16 @@ define({ "api": [ { "group": "Parameter", "type": "bytes", - "optional": true, + "optional": false, "field": "content", - "description": "

binary bytes, file accept image and video (note: only delete the file if empty)

" + "description": "

binary bytes, file accept image and video

" }, { "group": "Parameter", "type": "int32", - "optional": true, - "field": "type", - "description": "

1 for picture
2 for video (note: only delete the file if empty)

" - }, - { - "group": "Parameter", - "type": "array", "optional": false, - "field": "tags", - "description": "

string array tags, simply overwrite original tags, clear if empty

" + "field": "type", + "description": "

1 for picture
2 for video

" } ] } @@ -1677,14 +1677,14 @@ define({ "api": [ "type": "int32", "optional": false, "field": "status", - "description": "

-1 for invalid param
1 for success
2 for invalid token
3 for not found
4 for failed
5 for invalid type

" + "description": "

-1 for invalid param
1 for success
2 for invalid token
3 for not found
4 for invalid type

" }, { "group": "Success 200", "type": "string", - "optional": true, + "optional": false, "field": "fileID", - "description": "

24 bytes updated file id (note: new file id differs from old one, meaningful only if content and type are not empty)

" + "description": "

24 bytes updated file id

" } ] } diff --git a/backend/doc/api_data.json b/backend/doc/api_data.json index 94a1810..cdabd22 100644 --- a/backend/doc/api_data.json +++ b/backend/doc/api_data.json @@ -1511,6 +1511,13 @@ "optional": false, "field": "contentToken", "description": "

content token

" + }, + { + "group": "Parameter", + "type": "string", + "optional": true, + "field": "fileID", + "description": "

24 bytes file id, if not empty only delete this file

" } ] } @@ -1648,23 +1655,16 @@ { "group": "Parameter", "type": "bytes", - "optional": true, + "optional": false, "field": "content", - "description": "

binary bytes, file accept image and video (note: only delete the file if empty)

" + "description": "

binary bytes, file accept image and video

" }, { "group": "Parameter", "type": "int32", - "optional": true, - "field": "type", - "description": "

1 for picture
2 for video (note: only delete the file if empty)

" - }, - { - "group": "Parameter", - "type": "array", "optional": false, - "field": "tags", - "description": "

string array tags, simply overwrite original tags, clear if empty

" + "field": "type", + "description": "

1 for picture
2 for video

" } ] } @@ -1677,14 +1677,14 @@ "type": "int32", "optional": false, "field": "status", - "description": "

-1 for invalid param
1 for success
2 for invalid token
3 for not found
4 for failed
5 for invalid type

" + "description": "

-1 for invalid param
1 for success
2 for invalid token
3 for not found
4 for invalid type

" }, { "group": "Success 200", "type": "string", - "optional": true, + "optional": false, "field": "fileID", - "description": "

24 bytes updated file id (note: new file id differs from old one, meaningful only if content and type are not empty)

" + "description": "

24 bytes updated file id

" } ] } diff --git a/backend/doc/api_project.js b/backend/doc/api_project.js index 106cb34..41f13ee 100644 --- a/backend/doc/api_project.js +++ b/backend/doc/api_project.js @@ -20,7 +20,7 @@ define({ "apidoc": "0.3.0", "generator": { "name": "apidoc", - "time": "2019-07-30T09:08:33.007Z", + "time": "2019-08-01T01:55:10.521Z", "url": "http://apidocjs.com", "version": "0.17.7" } diff --git a/backend/doc/api_project.json b/backend/doc/api_project.json index 8c6c1e6..c52a973 100644 --- a/backend/doc/api_project.json +++ b/backend/doc/api_project.json @@ -20,7 +20,7 @@ "apidoc": "0.3.0", "generator": { "name": "apidoc", - "time": "2019-07-30T09:08:33.007Z", + "time": "2019-08-01T01:55:10.521Z", "url": "http://apidocjs.com", "version": "0.17.7" } diff --git a/backend/srv/auth/main.go b/backend/srv/auth/main.go index 23c9109..e88986c 100644 --- a/backend/srv/auth/main.go +++ b/backend/srv/auth/main.go @@ -47,19 +47,19 @@ func (a *srv) Auth(ctx context.Context, req *auth.AuthRequest, rsp *auth.AuthRes } client := &http.Client{Transport: tr} resp, err := client.PostForm(utils.GetStringConfig("sys_config", "token_url"), params) - if utils.LogContinue(err, utils.Warning) { + if utils.LogContinue(err, utils.Error) { return err } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) - if utils.LogContinue(err, utils.Warning) { + if utils.LogContinue(err, utils.Error) { return err } id := idToken{} err = json.Unmarshal(body, &id) - if utils.LogContinue(err, utils.Warning) { + if utils.LogContinue(err, utils.Error) { return err } diff --git a/backend/srv/avatar/main.go b/backend/srv/avatar/main.go index 1f3ca74..0940e25 100644 --- a/backend/srv/avatar/main.go +++ b/backend/srv/avatar/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "errors" db "jiaojiao/database" avatar "jiaojiao/srv/avatar/proto" "jiaojiao/srv/file/mock" @@ -46,7 +47,7 @@ func (a *srv) Create(ctx context.Context, req *avatar.AvatarCreateRequest, rsp * if gorm.IsRecordNotFoundError(err) { rsp.Status = avatar.AvatarCreateResponse_NOT_FOUND return nil - } else if utils.LogContinue(err, utils.Warning) { + } else if utils.LogContinue(err, utils.Error) { return err } @@ -55,13 +56,17 @@ func (a *srv) Create(ctx context.Context, req *avatar.AvatarCreateRequest, rsp * microRsp, err := srv.Create(context.TODO(), &file.FileCreateRequest{ File: req.File, }) - if utils.LogContinue(err, utils.Warning, "File service error: %v", err) || microRsp.Status != file.FileCreateResponse_SUCCESS { + if utils.LogContinue(err, utils.Error) { return err } + if microRsp.Status != file.FileCreateResponse_SUCCESS { + _, s := utils.LogContinueS("File create return "+microRsp.Status.String(), utils.Error) + return errors.New(s) + } usr.AvatarID = microRsp.FileID err = db.Ormer.Save(&usr).Error - if utils.LogContinue(err, utils.Warning) { + if utils.LogContinue(err, utils.Error) { return err } diff --git a/backend/srv/buyinfo/main.go b/backend/srv/buyinfo/main.go index 34fe530..5b46777 100644 --- a/backend/srv/buyinfo/main.go +++ b/backend/srv/buyinfo/main.go @@ -45,7 +45,7 @@ func (a *srv) Query(ctx context.Context, req *buyinfo.BuyInfoQueryRequest, rsp * err := db.Ormer.First(&info).Error if gorm.IsRecordNotFoundError(err) { return nil - } else if utils.LogContinue(err, utils.Warning) { + } else if utils.LogContinue(err, utils.Error) { return err } good := db.Good{ @@ -54,7 +54,7 @@ func (a *srv) Query(ctx context.Context, req *buyinfo.BuyInfoQueryRequest, rsp * err = db.Ormer.First(&good).Error if gorm.IsRecordNotFoundError(err) { return nil - } else if utils.LogContinue(err, utils.Warning) { + } else if utils.LogContinue(err, utils.Error) { return err } @@ -108,23 +108,23 @@ func (a *srv) Create(ctx context.Context, req *buyinfo.BuyInfoCreateRequest, rsp insert := func() (int32, error) { tx := db.Ormer.Begin() - if utils.LogContinue(tx.Error, utils.Warning) { + if tx.Error != nil { return 0, tx.Error } err := tx.Create(&good).Error - if utils.LogContinue(err, utils.Warning) { + if err != nil { tx.Rollback() return 0, err } info.GoodID = good.ID err = tx.Create(&info).Error - if utils.LogContinue(err, utils.Warning) { + if err != nil { tx.Rollback() return 0, err } err = tx.Commit().Error - if utils.LogContinue(err, utils.Warning) { + if err != nil { tx.Rollback() return 0, err } @@ -139,7 +139,10 @@ func (a *srv) Create(ctx context.Context, req *buyinfo.BuyInfoCreateRequest, rsp ContentToken: req.ContentToken, Tags: req.Tags, }) - if err != nil || microRsp.Status != content.ContentCreateTagResponse_SUCCESS { + if utils.LogContinue(err, utils.Error) { + return err + } + if microRsp.Status != content.ContentCreateTagResponse_SUCCESS { rsp.Status = buyinfo.BuyInfoCreateResponse_INVALID_TOKEN return nil } @@ -149,8 +152,8 @@ func (a *srv) Create(ctx context.Context, req *buyinfo.BuyInfoCreateRequest, rsp if utils.IsEmpty(req.ContentID) && utils.IsEmpty(req.ContentToken) { id, err := insert() - if err != nil || id == 0 { - return nil + if utils.LogContinue(err, utils.Error) || id == 0 { + return err } rsp.Status = buyinfo.BuyInfoCreateResponse_SUCCESS rsp.BuyInfoID = id @@ -166,8 +169,8 @@ func (a *srv) Create(ctx context.Context, req *buyinfo.BuyInfoCreateRequest, rsp good.ContentID = req.ContentID id, err := insert() - if err != nil || id == 0 { - return nil + if utils.LogContinue(err, utils.Error) || id == 0 { + return err } rsp.Status = buyinfo.BuyInfoCreateResponse_SUCCESS rsp.BuyInfoID = id @@ -240,7 +243,7 @@ func (a *srv) Find(ctx context.Context, req *buyinfo.BuyInfoFindRequest, rsp *bu } err := tb.Limit(req.Limit).Offset(req.Offset).Find(&res).Error - if utils.LogContinue(err, utils.Warning) { + if utils.LogContinue(err, utils.Error) { return err } for _, v := range res { diff --git a/backend/srv/content/main.go b/backend/srv/content/main.go index 1a47c2a..08b6520 100644 --- a/backend/srv/content/main.go +++ b/backend/srv/content/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "errors" db "jiaojiao/database" content "jiaojiao/srv/content/proto" "jiaojiao/srv/file/mock" @@ -44,12 +45,16 @@ func (a *srv) Create(ctx context.Context, req *content.ContentCreateRequest, rsp rsp, err := srv.Create(context.TODO(), &file.FileCreateRequest{ File: req.Content, }) - if utils.LogContinue(err, utils.Warning, "File service error: %v", err) || rsp.Status != file.FileCreateResponse_SUCCESS { + if err != nil { return primitive.ObjectID{}, err } + if rsp.Status != file.FileCreateResponse_SUCCESS { + _, s := utils.LogContinueS("File create return "+rsp.Status.String(), utils.Error) + return primitive.ObjectID{}, errors.New(s) + } fid, err := primitive.ObjectIDFromHex(rsp.FileID) - if utils.LogContinue(err, utils.Warning, "File service error: %v", err) { + if err != nil { return primitive.ObjectID{}, err } @@ -69,7 +74,7 @@ func (a *srv) Create(ctx context.Context, req *content.ContentCreateRequest, rsp if utils.IsEmpty(req.ContentID) && utils.IsEmpty(req.ContentToken) { // create new objID, err := upload() - if utils.LogContinue(err, utils.Warning) { + if utils.LogContinue(err, utils.Error) { return err } @@ -85,7 +90,7 @@ func (a *srv) Create(ctx context.Context, req *content.ContentCreateRequest, rsp "type": req.Type, }}, }) - if utils.LogContinue(err, utils.Warning) { + if utils.LogContinue(err, utils.Error) { return err } @@ -100,18 +105,14 @@ func (a *srv) Create(ctx context.Context, req *content.ContentCreateRequest, rsp } objID, err := upload() - if utils.LogContinue(err, utils.Warning) { + if utils.LogContinue(err, utils.Error) { return err } ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() collection := db.MongoDatabase.Collection("sellinfo") - rid, err := primitive.ObjectIDFromHex(req.ContentID) - if utils.LogContinue(err, utils.Warning) { - rsp.Status = content.ContentCreateResponse_INVALID_TOKEN - return nil - } + rid, _ := primitive.ObjectIDFromHex(req.ContentID) _, err = collection.UpdateOne(ctx, bson.D{ {"_id", rid}, {"token", req.ContentToken}, @@ -123,7 +124,7 @@ func (a *srv) Create(ctx context.Context, req *content.ContentCreateRequest, rsp {"type", req.Type}, }}, }}}) - if utils.LogContinue(err, utils.Warning) { + if utils.LogContinue(err, utils.Error) { return err } rsp.ContentID = req.ContentID @@ -167,7 +168,7 @@ func (a *srv) CreateTag(ctx context.Context, req *content.ContentCreateTagReques "token": token, "tags": req.Tags, }) - if utils.LogContinue(err, utils.Warning) { + if utils.LogContinue(err, utils.Error) { return err } @@ -193,11 +194,11 @@ func (a *srv) CreateTag(ctx context.Context, req *content.ContentCreateTagReques {"token", req.ContentToken}, }, bson.D{ - {"$setOnInsert", bson.D{ + {"$set", bson.D{ {"tags", req.Tags}, }}, }) - if utils.LogContinue(err, utils.Warning) { + if utils.LogContinue(err, utils.Error) { return err } rsp.ContentID = req.ContentID @@ -219,16 +220,15 @@ func (a *srv) CreateTag(ctx context.Context, req *content.ContentCreateTagReques * @apiParam {string} contentID 24 bytes content id * @apiParam {string} contentToken content token * @apiParam {string} fileID 24 bytes file id - * @apiParam {bytes} [content] binary bytes, file accept [image](https://github.com/h2non/filetype#image) - * and [video](https://github.com/h2non/filetype#video) (note: only delete the file if empty) - * @apiParam {int32} [type] 1 for picture
2 for video (note: only delete the file if empty) - * @apiParam {array} tags string array tags, simply overwrite original tags, clear if empty - * @apiSuccess {int32} status -1 for invalid param
1 for success
2 for invalid token
3 for not found
4 for failed
5 for invalid type - * @apiSuccess {string} [fileID] 24 bytes updated file id (note: new file id differs from old one, meaningful only if content and type are not empty) + * @apiParam {bytes} content binary bytes, file accept [image](https://github.com/h2non/filetype#image) + * and [video](https://github.com/h2non/filetype#video) + * @apiParam {int32} type 1 for picture
2 for video + * @apiSuccess {int32} status -1 for invalid param
1 for success
2 for invalid token
3 for not found
4 for invalid type + * @apiSuccess {string} fileID 24 bytes updated file id * @apiUse DBServerDown */ func (a *srv) Update(ctx context.Context, req *content.ContentUpdateRequest, rsp *content.ContentUpdateResponse) error { - if !utils.RequireParam(req.ContentID, req.ContentToken) { + if !utils.RequireParam(req.ContentID, req.ContentToken, req.FileID, req.Content, req.Type) { rsp.Status = content.ContentUpdateResponse_INVALID_PARAM return nil } @@ -239,97 +239,62 @@ func (a *srv) Update(ctx context.Context, req *content.ContentUpdateRequest, rsp return nil } - //prepare + // check id ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() collection := db.MongoDatabase.Collection("sellinfo") - rid, err := primitive.ObjectIDFromHex(req.ContentID) - if utils.LogContinue(err, utils.Warning) { - rsp.Status = content.ContentUpdateResponse_INVALID_TOKEN - return nil - } - - fid, err := primitive.ObjectIDFromHex(req.FileID) + rid, _ := primitive.ObjectIDFromHex(req.ContentID) + oldFid, err := primitive.ObjectIDFromHex(req.FileID) if utils.LogContinue(err, utils.Warning) { rsp.Status = content.ContentUpdateResponse_NOT_FOUND return nil } - if utils.RequireParam(req.FileID) { - //delete old file - _, err = collection.UpdateOne(ctx, bson.D{ - {"_id", rid}, - {"token", req.ContentToken}, - }, bson.D{ - {"$pull", bson.D{ - {"files", bson.D{ - {"fileID", fid}, - }}, - }}, - }) - if utils.LogContinue(err, utils.Warning) { - rsp.Status = content.ContentUpdateResponse_NOT_FOUND - return nil - } - - srv := utils.CallMicroService("file", func(name string, c client.Client) interface{} { return file.NewFileService(name, c) }, - func() interface{} { return mock.NewFileService() }).(file.FileService) - microDeleteRsp, err := srv.Delete(context.TODO(), &file.FileRequest{ - FileID: req.FileID, - }) - if utils.LogContinue(err, utils.Warning) || microDeleteRsp.Status != file.FileDeleteResponse_SUCCESS { - rsp.Status = content.ContentUpdateResponse_NOT_FOUND - return nil - } - - //add new file - if utils.RequireParam(req.Content, req.Type) { - microCreateRsp, err := srv.Create(context.TODO(), &file.FileCreateRequest{ - File: req.Content, - }) - if utils.LogContinue(err, utils.Warning) || microDeleteRsp.Status != file.FileDeleteResponse_SUCCESS { - rsp.Status = content.ContentUpdateResponse_FAILED - return nil - } - fid, err = primitive.ObjectIDFromHex(microCreateRsp.FileID) - if utils.LogContinue(err, utils.Warning) { - rsp.Status = content.ContentUpdateResponse_FAILED - return nil - } - - _, err = collection.UpdateOne(ctx, bson.D{ - {"_id", rid}, - {"token", req.ContentToken}, - }, bson.D{ - {"$push", bson.D{ - {"files", bson.D{ - {"fileID", fid}, - {"type", req.Type}, - }}, - }}, - }) - if utils.LogContinue(err, utils.Warning) { - rsp.Status = content.ContentUpdateResponse_FAILED - return nil - } - rsp.FileID = microCreateRsp.FileID - } + // add new file + srv := utils.CallMicroService("file", func(name string, c client.Client) interface{} { return file.NewFileService(name, c) }, + func() interface{} { return mock.NewFileService() }).(file.FileService) + microCreateRsp, err := srv.Create(context.TODO(), &file.FileCreateRequest{ + File: req.Content, + }) + if utils.LogContinue(err, utils.Error) { + return err + } + if microCreateRsp.Status != file.FileCreateResponse_SUCCESS { + _, s := utils.LogContinueS("File create return "+microCreateRsp.Status.String(), utils.Error) + return errors.New(s) + } + fid, err := primitive.ObjectIDFromHex(microCreateRsp.FileID) + if utils.LogContinue(err, utils.Error) { + return err } - //update tags _, err = collection.UpdateOne(ctx, bson.D{ {"_id", rid}, {"token", req.ContentToken}, + {"files.fileID", oldFid}, }, bson.D{ {"$set", bson.D{ - {"tags", req.Tags}, + {"files.$.fileID", fid}, + {"files.$.type", req.Type}, }}, }) - if utils.LogContinue(err, utils.Warning) { - rsp.Status = content.ContentUpdateResponse_FAILED - return nil + if utils.LogContinue(err, utils.Error) { + return err + } + + // delete old file + microDeleteRsp, err := srv.Delete(context.TODO(), &file.FileRequest{ + FileID: req.FileID, + }) + if utils.LogContinue(err, utils.Error) { + return err + } + if microDeleteRsp.Status != file.FileDeleteResponse_SUCCESS { + _, s := utils.LogContinueS("File delete return "+microDeleteRsp.Status.String(), utils.Error) + return errors.New(s) } + rsp.FileID = microCreateRsp.FileID rsp.Status = content.ContentUpdateResponse_SUCCESS return nil } @@ -343,6 +308,7 @@ func (a *srv) Update(ctx context.Context, req *content.ContentUpdateRequest, rsp * * @apiParam {string} contentID 24 bytes content id * @apiParam {string} contentToken content token + * @apiParam {string} [fileID] 24 bytes file id, if not empty only delete this file * @apiSuccess {int32} status -1 for invalid param
1 for success
2 for invalid token * @apiUse DBServerDown */ @@ -352,8 +318,8 @@ func (a *srv) Delete(ctx context.Context, req *content.ContentDeleteRequest, rsp return nil } type files struct { - FileID primitive.ObjectID `bson:"fileID"` - Type content.ContentCreateRequest_Type `bson:"type"` + FileID primitive.ObjectID `bson:"fileID"` + Type content.Type `bson:"type"` } type result struct { ID primitive.ObjectID `bson:"_id"` @@ -384,9 +350,13 @@ func (a *srv) Delete(ctx context.Context, req *content.ContentDeleteRequest, rsp microRsp, err := srv.Delete(context.TODO(), &file.FileRequest{ FileID: v.FileID.Hex(), }) - if utils.LogContinue(err, utils.Warning, "File service error: %v", err) || microRsp.Status != file.FileDeleteResponse_SUCCESS { + if utils.LogContinue(err, utils.Error) { return err } + if microRsp.Status != file.FileDeleteResponse_SUCCESS { + _, s := utils.LogContinueS("File delete return "+microRsp.Status.String(), utils.Error) + return errors.New(s) + } } rsp.Status = content.ContentDeleteResponse_SUCCESS return nil @@ -412,8 +382,8 @@ func (a *srv) Query(ctx context.Context, req *content.ContentQueryRequest, rsp * return nil } type files struct { - FileID primitive.ObjectID `bson:"fileID"` - Type content.FileMsg_Type `bson:"type"` + FileID primitive.ObjectID `bson:"fileID"` + Type content.Type `bson:"type"` } type result struct { ID primitive.ObjectID `bson:"_id"` diff --git a/backend/srv/content/mock/mock.go b/backend/srv/content/mock/mock.go index 1af7804..109c9c4 100644 --- a/backend/srv/content/mock/mock.go +++ b/backend/srv/content/mock/mock.go @@ -79,6 +79,12 @@ func (a *mockSrv) Delete(ctx context.Context, req *content.ContentDeleteRequest, return &rsp, nil } +// CreateTag is tag create mock +func (a *mockSrv) CreateTag(ctx context.Context, req *content.ContentCreateTagRequest, opts ...client.CallOption) (*content.ContentCreateTagResponse, error) { + // TODO + return nil, nil +} + // NewContentService is content service mock func NewContentService() content.ContentService { return new(mockSrv) diff --git a/backend/srv/content/proto/content.pb.go b/backend/srv/content/proto/content.pb.go index f4101d2..b6fea8e 100644 --- a/backend/srv/content/proto/content.pb.go +++ b/backend/srv/content/proto/content.pb.go @@ -20,32 +20,32 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package -type ContentCreateRequest_Type int32 +type Type int32 const ( - ContentCreateRequest_UNKNOWN ContentCreateRequest_Type = 0 - ContentCreateRequest_PICTURE ContentCreateRequest_Type = 1 - ContentCreateRequest_VIDEO ContentCreateRequest_Type = 2 + Type_UNKNOWN Type = 0 + Type_PICTURE Type = 1 + Type_VIDEO Type = 2 ) -var ContentCreateRequest_Type_name = map[int32]string{ +var Type_name = map[int32]string{ 0: "UNKNOWN", 1: "PICTURE", 2: "VIDEO", } -var ContentCreateRequest_Type_value = map[string]int32{ +var Type_value = map[string]int32{ "UNKNOWN": 0, "PICTURE": 1, "VIDEO": 2, } -func (x ContentCreateRequest_Type) String() string { - return proto.EnumName(ContentCreateRequest_Type_name, int32(x)) +func (x Type) String() string { + return proto.EnumName(Type_name, int32(x)) } -func (ContentCreateRequest_Type) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_61cc9617ce0cf609, []int{0, 0} +func (Type) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_61cc9617ce0cf609, []int{0} } type ContentCreateResponse_Status int32 @@ -116,34 +116,6 @@ func (ContentCreateTagResponse_Status) EnumDescriptor() ([]byte, []int) { return fileDescriptor_61cc9617ce0cf609, []int{3, 0} } -type ContentUpdateRequest_Type int32 - -const ( - ContentUpdateRequest_UNKNOWN ContentUpdateRequest_Type = 0 - ContentUpdateRequest_PICTURE ContentUpdateRequest_Type = 1 - ContentUpdateRequest_VIDEO ContentUpdateRequest_Type = 2 -) - -var ContentUpdateRequest_Type_name = map[int32]string{ - 0: "UNKNOWN", - 1: "PICTURE", - 2: "VIDEO", -} - -var ContentUpdateRequest_Type_value = map[string]int32{ - "UNKNOWN": 0, - "PICTURE": 1, - "VIDEO": 2, -} - -func (x ContentUpdateRequest_Type) String() string { - return proto.EnumName(ContentUpdateRequest_Type_name, int32(x)) -} - -func (ContentUpdateRequest_Type) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_61cc9617ce0cf609, []int{4, 0} -} - type ContentUpdateResponse_Status int32 const ( @@ -152,8 +124,7 @@ const ( ContentUpdateResponse_SUCCESS ContentUpdateResponse_Status = 1 ContentUpdateResponse_INVALID_TOKEN ContentUpdateResponse_Status = 2 ContentUpdateResponse_NOT_FOUND ContentUpdateResponse_Status = 3 - ContentUpdateResponse_FAILED ContentUpdateResponse_Status = 4 - ContentUpdateResponse_INVALID_TYPE ContentUpdateResponse_Status = 5 + ContentUpdateResponse_INVALID_TYPE ContentUpdateResponse_Status = 4 ) var ContentUpdateResponse_Status_name = map[int32]string{ @@ -162,8 +133,7 @@ var ContentUpdateResponse_Status_name = map[int32]string{ 1: "SUCCESS", 2: "INVALID_TOKEN", 3: "NOT_FOUND", - 4: "FAILED", - 5: "INVALID_TYPE", + 4: "INVALID_TYPE", } var ContentUpdateResponse_Status_value = map[string]int32{ @@ -172,8 +142,7 @@ var ContentUpdateResponse_Status_value = map[string]int32{ "SUCCESS": 1, "INVALID_TOKEN": 2, "NOT_FOUND": 3, - "FAILED": 4, - "INVALID_TYPE": 5, + "INVALID_TYPE": 4, } func (x ContentUpdateResponse_Status) String() string { @@ -191,6 +160,7 @@ const ( ContentDeleteResponse_INVALID_PARAM ContentDeleteResponse_Status = -1 ContentDeleteResponse_SUCCESS ContentDeleteResponse_Status = 1 ContentDeleteResponse_INVALID_TOKEN ContentDeleteResponse_Status = 2 + ContentDeleteResponse_NOT_FOUND ContentDeleteResponse_Status = 3 ) var ContentDeleteResponse_Status_name = map[int32]string{ @@ -198,6 +168,7 @@ var ContentDeleteResponse_Status_name = map[int32]string{ -1: "INVALID_PARAM", 1: "SUCCESS", 2: "INVALID_TOKEN", + 3: "NOT_FOUND", } var ContentDeleteResponse_Status_value = map[string]int32{ @@ -205,6 +176,7 @@ var ContentDeleteResponse_Status_value = map[string]int32{ "INVALID_PARAM": -1, "SUCCESS": 1, "INVALID_TOKEN": 2, + "NOT_FOUND": 3, } func (x ContentDeleteResponse_Status) String() string { @@ -215,34 +187,6 @@ func (ContentDeleteResponse_Status) EnumDescriptor() ([]byte, []int) { return fileDescriptor_61cc9617ce0cf609, []int{7, 0} } -type FileMsg_Type int32 - -const ( - FileMsg_UNKNOWN FileMsg_Type = 0 - FileMsg_PICTURE FileMsg_Type = 1 - FileMsg_VIDEO FileMsg_Type = 2 -) - -var FileMsg_Type_name = map[int32]string{ - 0: "UNKNOWN", - 1: "PICTURE", - 2: "VIDEO", -} - -var FileMsg_Type_value = map[string]int32{ - "UNKNOWN": 0, - "PICTURE": 1, - "VIDEO": 2, -} - -func (x FileMsg_Type) String() string { - return proto.EnumName(FileMsg_Type_name, int32(x)) -} - -func (FileMsg_Type) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_61cc9617ce0cf609, []int{8, 0} -} - type ContentQueryResponse_Status int32 const ( @@ -306,13 +250,13 @@ func (ContentCheckResponse_Status) EnumDescriptor() ([]byte, []int) { } type ContentCreateRequest struct { - ContentID string `protobuf:"bytes,1,opt,name=contentID,proto3" json:"contentID,omitempty"` - ContentToken string `protobuf:"bytes,2,opt,name=contentToken,proto3" json:"contentToken,omitempty"` - Content []byte `protobuf:"bytes,3,opt,name=content,proto3" json:"content,omitempty"` - Type ContentCreateRequest_Type `protobuf:"varint,4,opt,name=type,proto3,enum=ContentCreateRequest_Type" json:"type,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + ContentID string `protobuf:"bytes,1,opt,name=contentID,proto3" json:"contentID,omitempty"` + ContentToken string `protobuf:"bytes,2,opt,name=contentToken,proto3" json:"contentToken,omitempty"` + Content []byte `protobuf:"bytes,3,opt,name=content,proto3" json:"content,omitempty"` + Type Type `protobuf:"varint,4,opt,name=type,proto3,enum=Type" json:"type,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *ContentCreateRequest) Reset() { *m = ContentCreateRequest{} } @@ -361,11 +305,11 @@ func (m *ContentCreateRequest) GetContent() []byte { return nil } -func (m *ContentCreateRequest) GetType() ContentCreateRequest_Type { +func (m *ContentCreateRequest) GetType() Type { if m != nil { return m.Type } - return ContentCreateRequest_UNKNOWN + return Type_UNKNOWN } type ContentCreateResponse struct { @@ -542,15 +486,15 @@ func (m *ContentCreateTagResponse) GetContentToken() string { } type ContentUpdateRequest struct { - ContentID string `protobuf:"bytes,1,opt,name=contentID,proto3" json:"contentID,omitempty"` - ContentToken string `protobuf:"bytes,2,opt,name=contentToken,proto3" json:"contentToken,omitempty"` - FileID string `protobuf:"bytes,3,opt,name=fileID,proto3" json:"fileID,omitempty"` - Content []byte `protobuf:"bytes,4,opt,name=content,proto3" json:"content,omitempty"` - Type ContentUpdateRequest_Type `protobuf:"varint,5,opt,name=type,proto3,enum=ContentUpdateRequest_Type" json:"type,omitempty"` - Tags []string `protobuf:"bytes,6,rep,name=tags,proto3" json:"tags,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + ContentID string `protobuf:"bytes,1,opt,name=contentID,proto3" json:"contentID,omitempty"` + ContentToken string `protobuf:"bytes,2,opt,name=contentToken,proto3" json:"contentToken,omitempty"` + FileID string `protobuf:"bytes,3,opt,name=fileID,proto3" json:"fileID,omitempty"` + Content []byte `protobuf:"bytes,4,opt,name=content,proto3" json:"content,omitempty"` + Type Type `protobuf:"varint,5,opt,name=type,proto3,enum=Type" json:"type,omitempty"` + Tags []string `protobuf:"bytes,6,rep,name=tags,proto3" json:"tags,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *ContentUpdateRequest) Reset() { *m = ContentUpdateRequest{} } @@ -606,11 +550,11 @@ func (m *ContentUpdateRequest) GetContent() []byte { return nil } -func (m *ContentUpdateRequest) GetType() ContentUpdateRequest_Type { +func (m *ContentUpdateRequest) GetType() Type { if m != nil { return m.Type } - return ContentUpdateRequest_UNKNOWN + return Type_UNKNOWN } func (m *ContentUpdateRequest) GetTags() []string { @@ -754,11 +698,11 @@ func (m *ContentDeleteResponse) GetStatus() ContentDeleteResponse_Status { } type FileMsg struct { - FileID string `protobuf:"bytes,1,opt,name=fileID,proto3" json:"fileID,omitempty"` - Type FileMsg_Type `protobuf:"varint,2,opt,name=type,proto3,enum=FileMsg_Type" json:"type,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + FileID string `protobuf:"bytes,1,opt,name=fileID,proto3" json:"fileID,omitempty"` + Type Type `protobuf:"varint,2,opt,name=type,proto3,enum=Type" json:"type,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *FileMsg) Reset() { *m = FileMsg{} } @@ -793,11 +737,11 @@ func (m *FileMsg) GetFileID() string { return "" } -func (m *FileMsg) GetType() FileMsg_Type { +func (m *FileMsg) GetType() Type { if m != nil { return m.Type } - return FileMsg_UNKNOWN + return Type_UNKNOWN } type ContentQueryRequest struct { @@ -989,13 +933,11 @@ func (m *ContentCheckResponse) GetStatus() ContentCheckResponse_Status { } func init() { - proto.RegisterEnum("ContentCreateRequest_Type", ContentCreateRequest_Type_name, ContentCreateRequest_Type_value) + proto.RegisterEnum("Type", Type_name, Type_value) proto.RegisterEnum("ContentCreateResponse_Status", ContentCreateResponse_Status_name, ContentCreateResponse_Status_value) proto.RegisterEnum("ContentCreateTagResponse_Status", ContentCreateTagResponse_Status_name, ContentCreateTagResponse_Status_value) - proto.RegisterEnum("ContentUpdateRequest_Type", ContentUpdateRequest_Type_name, ContentUpdateRequest_Type_value) proto.RegisterEnum("ContentUpdateResponse_Status", ContentUpdateResponse_Status_name, ContentUpdateResponse_Status_value) proto.RegisterEnum("ContentDeleteResponse_Status", ContentDeleteResponse_Status_name, ContentDeleteResponse_Status_value) - proto.RegisterEnum("FileMsg_Type", FileMsg_Type_name, FileMsg_Type_value) proto.RegisterEnum("ContentQueryResponse_Status", ContentQueryResponse_Status_name, ContentQueryResponse_Status_value) proto.RegisterEnum("ContentCheckResponse_Status", ContentCheckResponse_Status_name, ContentCheckResponse_Status_value) proto.RegisterType((*ContentCreateRequest)(nil), "ContentCreateRequest") @@ -1016,48 +958,47 @@ func init() { func init() { proto.RegisterFile("content.proto", fileDescriptor_61cc9617ce0cf609) } var fileDescriptor_61cc9617ce0cf609 = []byte{ - // 685 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x56, 0xcf, 0x52, 0xd3, 0x40, - 0x18, 0x37, 0x7f, 0x9a, 0x9a, 0x0f, 0xca, 0xac, 0x2b, 0x60, 0xec, 0xa0, 0x53, 0xf7, 0xd4, 0x19, - 0x67, 0xf6, 0x50, 0x70, 0xf0, 0x68, 0xa7, 0x29, 0x33, 0x19, 0x20, 0x85, 0xb4, 0x05, 0x3d, 0x31, - 0x15, 0x57, 0x64, 0x60, 0x9a, 0x42, 0xc2, 0x81, 0x8b, 0x6f, 0xe0, 0xd9, 0xb3, 0x4f, 0xe4, 0x3b, - 0x78, 0xf0, 0x05, 0x3c, 0x72, 0xd0, 0x49, 0xb2, 0xcd, 0x66, 0x43, 0x3a, 0x05, 0xcd, 0xc8, 0x89, - 0xdd, 0xfe, 0x36, 0x5f, 0xbe, 0xdf, 0x9f, 0x6f, 0x03, 0xb5, 0x63, 0x7f, 0x1c, 0xb2, 0x71, 0x48, - 0x27, 0x97, 0x7e, 0xe8, 0x93, 0xef, 0x0a, 0x2c,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4, 0x57, 0xe8, 0x0c, 0xfb, 0x57, - 0x62, 0x65, 0xc4, 0xa9, 0xac, 0x53, 0xc4, 0x29, 0x49, 0xbe, 0xf7, 0x46, 0xfc, 0xc9, 0xb8, 0xfe, - 0x27, 0x00, 0x00, 0xff, 0xff, 0x37, 0x4d, 0xbb, 0xee, 0x43, 0x0a, 0x00, 0x00, + // 663 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x56, 0xcd, 0x6e, 0xd3, 0x4c, + 0x14, 0xfd, 0xfc, 0x9b, 0xcf, 0xb7, 0x3f, 0x32, 0x43, 0x5b, 0xdc, 0xa8, 0x20, 0x6b, 0x56, 0x11, + 0x48, 0x5e, 0xa4, 0x45, 0x65, 0xc1, 0x82, 0xca, 0x4e, 0x25, 0xab, 0xd4, 0x29, 0x8e, 0x43, 0x61, + 0x55, 0x42, 0x19, 0x42, 0xd5, 0x28, 0x0e, 0xb1, 0xb3, 0xc8, 0x43, 0x74, 0xcd, 0x6b, 0xb0, 0xe5, + 0x55, 0x58, 0xf2, 0x0a, 0x2c, 0x59, 0x80, 0x62, 0x4f, 0x3c, 0x1e, 0xc7, 0x51, 0x8a, 0x30, 0x74, + 0xd5, 0x99, 0x9c, 0x99, 0xb9, 0xf7, 0x9c, 0x7b, 0xee, 0x35, 0x6c, 0x5c, 0x86, 0xc3, 0x98, 0x0c, + 0x63, 0x6b, 0x34, 0x0e, 0xe3, 0x10, 0xdf, 0x08, 0xb0, 0x65, 0xa7, 0x3b, 0xf6, 0x98, 0xf4, 0x62, + 0xe2, 0x93, 0x8f, 0x13, 0x12, 0xc5, 0x68, 0x0f, 0x34, 0x8a, 0x74, 0x1d, 0x43, 0x30, 0x85, 0x86, + 0xe6, 0xb3, 0x0d, 0x84, 0x61, 0x9d, 0x2e, 0x82, 0xf0, 0x9a, 0x0c, 0x0d, 0x31, 0x01, 0x70, 0x7b, + 0xc8, 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dc, 0xd8, 0x4d, + 0x6f, 0x5e, 0x45, 0x27, 0x07, 0x2b, 0x96, 0x9c, 0xfb, 0xfb, 0x69, 0x6b, 0xa0, 0x24, 0xbf, 0xe8, + 0x09, 0x03, 0x14, 0xa6, 0x8b, 0x0f, 0x1f, 0x81, 0x3c, 0xab, 0x15, 0xfe, 0xa2, 0x35, 0xa8, 0x9d, + 0xb9, 0x76, 0xd0, 0xf5, 0x5b, 0x7a, 0x7a, 0xd2, 0x75, 0x5a, 0x6d, 0x5d, 0x6c, 0x7e, 0x13, 0xa1, + 0x46, 0xe3, 0x43, 0x87, 0xa0, 0xa6, 0x53, 0x00, 0x6d, 0x5b, 0x65, 0x5f, 0x14, 0xf5, 0x9d, 0xf2, + 0x81, 0x8d, 0x9e, 0x81, 0x96, 0x8d, 0x0f, 0x64, 0x58, 0x4b, 0xc6, 0x5d, 0x7d, 0x77, 0xe9, 0xac, + 0x99, 0x3d, 0x9d, 0x76, 0x32, 0xf6, 0x34, 0xd7, 0xbd, 0xd9, 0xd3, 0x85, 0xc6, 0x78, 0x08, 0x6a, + 0xea, 0x65, 0x76, 0x90, 0x6b, 0x2f, 0xec, 0x60, 0xa1, 0x35, 0x1c, 0x80, 0x92, 0xd4, 0x37, 0xda, + 0xb2, 0x4a, 0xbc, 0x54, 0xdf, 0xb6, 0x96, 0x78, 0x45, 0x49, 0x64, 0x64, 0xa7, 0xf2, 0x65, 0xc5, + 0x4e, 0x71, 0x5a, 0xbf, 0x55, 0x93, 0x2f, 0xb5, 0xfd, 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xc1, + 0x77, 0x71, 0xc0, 0xba, 0x09, 0x00, 0x00, } diff --git a/backend/srv/content/proto/content.proto b/backend/srv/content/proto/content.proto index 3d6b354..7a4bae4 100644 --- a/backend/srv/content/proto/content.proto +++ b/backend/srv/content/proto/content.proto @@ -9,12 +9,13 @@ service Content { rpc Check (ContentCheckRequest) returns (ContentCheckResponse); } +enum Type { + UNKNOWN = 0; + PICTURE = 1; + VIDEO = 2; +} + message ContentCreateRequest { - enum Type { - UNKNOWN = 0; - PICTURE = 1; - VIDEO = 2; - } string contentID = 1; string contentToken = 2; bytes content = 3; @@ -55,11 +56,6 @@ message ContentCreateTagResponse{ } message ContentUpdateRequest { - enum Type { - UNKNOWN = 0; - PICTURE = 1; - VIDEO = 2; - } string contentID = 1; string contentToken = 2; string fileID = 3; @@ -75,8 +71,7 @@ message ContentUpdateResponse { SUCCESS = 1; INVALID_TOKEN = 2; NOT_FOUND = 3; - FAILED = 4; - INVALID_TYPE = 5; + INVALID_TYPE = 4; } Status status = 1; string fileID = 2; @@ -93,16 +88,12 @@ message ContentDeleteResponse { INVALID_PARAM = -1; SUCCESS = 1; INVALID_TOKEN = 2; + NOT_FOUND = 3; } Status status = 1; } message FileMsg { - enum Type { - UNKNOWN = 0; - PICTURE = 1; - VIDEO = 2; - } string fileID = 1; Type type = 2; } diff --git a/backend/srv/file/main.go b/backend/srv/file/main.go index 1ba8ed6..447b2d9 100644 --- a/backend/srv/file/main.go +++ b/backend/srv/file/main.go @@ -33,12 +33,12 @@ func (a *srvFile) Query(ctx context.Context, req *file.FileRequest, rsp *file.Fi } bucket, err := gridfs.NewBucket(db.MongoDatabase) - if utils.LogContinue(err, utils.Warning) { + if utils.LogContinue(err, utils.Error) { return err } fid, err := primitive.ObjectIDFromHex(req.FileID) - if utils.LogContinue(err, utils.Warning) { + if utils.LogContinue(err, utils.Error) { return err } @@ -74,12 +74,12 @@ func (a *srvFile) Create(ctx context.Context, req *file.FileCreateRequest, rsp * } bucket, err := gridfs.NewBucket(db.MongoDatabase) - if utils.LogContinue(err, utils.Warning) { + if utils.LogContinue(err, utils.Error) { return err } objID, err := bucket.UploadFromStream("", bytes.NewReader(req.File)) - if utils.LogContinue(err, utils.Warning) { + if utils.LogContinue(err, utils.Error) { return err } rsp.FileID = objID.Hex() diff --git a/backend/srv/sellinfo/main.go b/backend/srv/sellinfo/main.go index f1707e7..879d095 100644 --- a/backend/srv/sellinfo/main.go +++ b/backend/srv/sellinfo/main.go @@ -46,7 +46,7 @@ func (a *srv) Query(ctx context.Context, req *sellinfo.SellInfoQueryRequest, rsp err := db.Ormer.First(&info).Error if gorm.IsRecordNotFoundError(err) { return nil - } else if utils.LogContinue(err, utils.Warning) { + } else if utils.LogContinue(err, utils.Error) { return err } good := db.Good{ @@ -55,7 +55,7 @@ func (a *srv) Query(ctx context.Context, req *sellinfo.SellInfoQueryRequest, rsp err = db.Ormer.First(&good).Error if gorm.IsRecordNotFoundError(err) { return nil - } else if utils.LogContinue(err, utils.Warning) { + } else if utils.LogContinue(err, utils.Error) { return err } @@ -109,23 +109,23 @@ func (a *srv) Create(ctx context.Context, req *sellinfo.SellInfoCreateRequest, r insert := func() (int32, error) { tx := db.Ormer.Begin() - if utils.LogContinue(tx.Error, utils.Warning) { + if tx.Error != nil { return 0, tx.Error } err := tx.Create(&good).Error - if utils.LogContinue(err, utils.Warning) { + if err != nil { tx.Rollback() return 0, err } info.GoodID = good.ID err = tx.Create(&info).Error - if utils.LogContinue(err, utils.Warning) { + if err != nil { tx.Rollback() return 0, err } err = tx.Commit().Error - if utils.LogContinue(err, utils.Warning) { + if err != nil { tx.Rollback() return 0, err } @@ -140,7 +140,10 @@ func (a *srv) Create(ctx context.Context, req *sellinfo.SellInfoCreateRequest, r ContentToken: req.ContentToken, Tags: req.Tags, }) - if err != nil || microRsp.Status != content.ContentCreateTagResponse_SUCCESS { + if utils.LogContinue(err, utils.Error) { + return err + } + if microRsp.Status != content.ContentCreateTagResponse_SUCCESS { rsp.Status = sellinfo.SellInfoCreateResponse_INVALID_TOKEN return nil } @@ -150,8 +153,8 @@ func (a *srv) Create(ctx context.Context, req *sellinfo.SellInfoCreateRequest, r if utils.IsEmpty(req.ContentID) && utils.IsEmpty(req.ContentToken) { id, err := insert() - if err != nil || id == 0 { - return nil + if utils.LogContinue(err, utils.Error) || id == 0 { + return err } rsp.Status = sellinfo.SellInfoCreateResponse_SUCCESS rsp.SellInfoID = id @@ -167,8 +170,8 @@ func (a *srv) Create(ctx context.Context, req *sellinfo.SellInfoCreateRequest, r good.ContentID = req.ContentID id, err := insert() - if err != nil || id == 0 { - return nil + if utils.LogContinue(err, utils.Error) || id == 0 { + return err } rsp.Status = sellinfo.SellInfoCreateResponse_SUCCESS rsp.SellInfoID = id @@ -241,7 +244,7 @@ func (a *srv) Find(ctx context.Context, req *sellinfo.SellInfoFindRequest, rsp * } err := tb.Limit(req.Limit).Offset(req.Offset).Find(&res).Error - if utils.LogContinue(err, utils.Warning) { + if utils.LogContinue(err, utils.Error) { return err } for _, v := range res { diff --git a/backend/srv/transaction/main.go b/backend/srv/transaction/main.go index 195f0a3..1689f8d 100644 --- a/backend/srv/transaction/main.go +++ b/backend/srv/transaction/main.go @@ -44,7 +44,7 @@ func (a *srv) Create(ctx context.Context, req *transaction.TransactionCreateRequ srvRsp, err := microSrv.Query(context.TODO(), &sellinfo.SellInfoQueryRequest{ SellInfoID: req.InfoID, }) - if utils.LogContinue(err, utils.Warning, "SellInfo service error: %v", err) { + if utils.LogContinue(err, utils.Error) { return err } if srvRsp.UserID == 0 { @@ -58,7 +58,7 @@ func (a *srv) Create(ctx context.Context, req *transaction.TransactionCreateRequ srvRsp, err := microSrv.Query(context.TODO(), &buyinfo.BuyInfoQueryRequest{ BuyInfoID: req.InfoID, }) - if utils.LogContinue(err, utils.Warning, "BuyInfo service error: %v", err) { + if utils.LogContinue(err, utils.Error) { return err } if srvRsp.UserID == 0 { @@ -79,7 +79,7 @@ func (a *srv) Create(ctx context.Context, req *transaction.TransactionCreateRequ err := db.Ormer.Create(&tran).Error if gorm.IsRecordNotFoundError(err) { return nil - } else if utils.LogContinue(err, utils.Warning) { + } else if utils.LogContinue(err, utils.Error) { return err } @@ -113,12 +113,12 @@ func (a *srv) Update(ctx context.Context, req *transaction.TransactionUpdateRequ if gorm.IsRecordNotFoundError(err) { rsp.Status = transaction.TransactionUpdateResponse_NOT_FOUND return nil - } else if utils.LogContinue(err, utils.Warning) { + } else if utils.LogContinue(err, utils.Error) { return err } tran.Status = int32(req.Status) err = db.Ormer.Save(&tran).Error - if utils.LogContinue(err, utils.Warning) { + if utils.LogContinue(err, utils.Error) { return err } diff --git a/backend/srv/user/main.go b/backend/srv/user/main.go index 966e2e4..4ff92b5 100644 --- a/backend/srv/user/main.go +++ b/backend/srv/user/main.go @@ -46,7 +46,7 @@ func (a *srv) Create(ctx context.Context, req *user.UserCreateRequest, rsp *user } utils.LogContinue(db.Ormer.Create(&usr).Error, utils.Warning) rsp.Status = user.UserCreateResponse_SUCCESS - } else if utils.LogContinue(err, utils.Warning) { + } else if utils.LogContinue(err, utils.Error) { return err } else { rsp.Status = user.UserCreateResponse_USER_EXIST @@ -85,7 +85,7 @@ func (a *srv) Query(ctx context.Context, req *user.UserQueryRequest, rsp *user.U err := db.Ormer.First(&usr).Error if gorm.IsRecordNotFoundError(err) { return nil - } else if utils.LogContinue(err, utils.Warning) { + } else if utils.LogContinue(err, utils.Error) { return err } parseUser(&usr, rsp) @@ -134,7 +134,7 @@ func (a *srv) Update(ctx context.Context, req *user.UserInfo, rsp *user.UserUpda utils.AssignNotZero((*int32)(&req.Status), &usr.Status) utils.AssignNotZero((*int32)(&req.Role), &usr.Role) err := db.Ormer.Save(&usr).Error - if utils.LogContinue(err, utils.Warning) { + if utils.LogContinue(err, utils.Error) { return err } rsp.Status = user.UserUpdateResponse_SUCCESS @@ -142,7 +142,7 @@ func (a *srv) Update(ctx context.Context, req *user.UserInfo, rsp *user.UserUpda rsp.Status = user.UserUpdateResponse_NOT_FOUND return nil } else { - utils.Warning(err) + utils.Error(err) return err } return nil @@ -171,7 +171,7 @@ func (a *srv) Find(ctx context.Context, req *user.UserFindRequest, rsp *user.Use var res []*db.User err := db.Ormer.Where("user_name LIKE ?", "%"+req.UserName+"%").Limit(req.Limit).Offset(req.Offset).Find(&res).Error - if utils.LogContinue(err, utils.Warning) { + if utils.LogContinue(err, utils.Error) { return err } for i, v := range res { diff --git a/backend/utils/function.go b/backend/utils/function.go index 2fbf3d2..d2e2922 100644 --- a/backend/utils/function.go +++ b/backend/utils/function.go @@ -53,6 +53,8 @@ func IsEmpty(val interface{}) bool { return v == "" case []byte: return bytes.Equal(v, []byte{0}) + case []string: + return len(v) == 0 default: s := fmt.Sprintf("%d", val) return s == "0" From 37d691845133dd49074c26dc69fa03ef677035c0 Mon Sep 17 00:00:00 2001 From: MXWXZ Date: Thu, 1 Aug 2019 16:16:23 +0800 Subject: [PATCH 10/12] test fix --- backend/api/auth/main_test.go | 9 +- backend/api/buyinfo/main.go | 2 +- backend/api/buyinfo/main_test.go | 12 +- backend/api/content/main.go | 4 +- backend/api/content/main_test.go | 12 +- backend/api/sellinfo/main.go | 2 +- backend/api/sellinfo/main_test.go | 12 +- backend/api/transaction/main.go | 34 +-- backend/api/user/main.go | 4 +- backend/api/user/main_test.go | 34 +-- backend/doc/api_project.js | 2 +- backend/doc/api_project.json | 2 +- backend/srv/auth/mock/mock.go | 58 ++--- backend/srv/avatar/main.go | 47 ++-- backend/srv/avatar/main_test.go | 22 +- backend/srv/avatar/mock/mock.go | 19 +- backend/srv/avatar/proto/avatar.pb.go | 42 ++-- backend/srv/avatar/proto/avatar.proto | 3 +- backend/srv/buyinfo/main.go | 4 +- backend/srv/buyinfo/main_test.go | 41 ++- backend/srv/buyinfo/mock/mock.go | 14 +- backend/srv/content/main_test.go | 4 +- backend/srv/content/mock/mock.go | 29 +-- backend/srv/file/mock/mock.go | 33 ++- backend/srv/sellinfo/main.go | 4 +- backend/srv/sellinfo/main_test.go | 90 +------ backend/srv/sellinfo/mock/mock.go | 14 +- backend/srv/transaction/main.go | 8 +- .../srv/transaction/proto/transaction.pb.go | 236 +++++++----------- .../srv/transaction/proto/transaction.proto | 21 +- backend/srv/user/main.go | 4 +- backend/srv/user/main_test.go | 69 ++--- backend/srv/user/mock/mock.go | 115 ++++----- backend/utils/function.go | 21 ++ backend/utils/testtool.go | 4 +- 35 files changed, 484 insertions(+), 547 deletions(-) diff --git a/backend/api/auth/main_test.go b/backend/api/auth/main_test.go index 43f1c0e..0f8dc8d 100644 --- a/backend/api/auth/main_test.go +++ b/backend/api/auth/main_test.go @@ -30,12 +30,11 @@ func Test_getAuth(t *testing.T) { So(r.Code, ShouldEqual, 301) tf(200, "invalid", auth.AuthResponse_INVALID_CODE, 0, 0) - tf(200, "valid_user", auth.AuthResponse_SUCCESS, 1, user.UserInfo_USER) - tf(200, "valid_admin", auth.AuthResponse_SUCCESS, 2, user.UserInfo_ADMIN) - + tf(200, "valid_user", auth.AuthResponse_SUCCESS, 1000, user.UserInfo_USER) + tf(200, "valid_admin", auth.AuthResponse_SUCCESS, 1001, user.UserInfo_ADMIN) tf(200, "frozen_user", auth.AuthResponse_FROZEN_USER, 0, 0) - tf(500, "down", 0, 0, 0) - tf(500, "userdown", 0, 0, 0) + tf(500, "error", 0, 0, 0) + tf(500, "user_error", 0, 0, 0) }) } diff --git a/backend/api/buyinfo/main.go b/backend/api/buyinfo/main.go index e068935..fdab999 100644 --- a/backend/api/buyinfo/main.go +++ b/backend/api/buyinfo/main.go @@ -147,7 +147,7 @@ func findBuyInfo(c *gin.Context) { func() interface{} { return mock.NewBuyInfoService() }).(buyinfo.BuyInfoService) rsp, err := srv.Find(context.TODO(), &buyinfo.BuyInfoFindRequest{ UserID: p.UserID, - Status: buyinfo.BuyStatus(p.Status), + Status: buyinfo.BuyStatus(utils.EnumConvert(p.Status, buyinfo.BuyStatus_name)), GoodName: p.GoodName, LowPrice: p.LowPrice, HighPrice: p.HighPrice, diff --git a/backend/api/buyinfo/main_test.go b/backend/api/buyinfo/main_test.go index 1bed41d..2f81382 100644 --- a/backend/api/buyinfo/main_test.go +++ b/backend/api/buyinfo/main_test.go @@ -4,18 +4,20 @@ import ( buyinfo "jiaojiao/srv/buyinfo/proto" "jiaojiao/utils" "net/url" + "strconv" "testing" . "github.com/smartystreets/goconvey/convey" ) func Test_getBuyInfo(t *testing.T) { - tf := func(code int, path string, id int, cid string) { + tf := func(code int, path string, cid string) { c, d := utils.GetTestData(setupRouter, "GET", "/buyInfo/"+path, nil, "") So(c, ShouldEqual, code) if d != nil { - So(d["buyInfoID"], ShouldEqual, id) + v, _ := strconv.Atoi(path) + So(d["buyInfoID"], ShouldEqual, v) So(d["contentID"], ShouldEqual, cid) } } @@ -27,9 +29,9 @@ func Test_getBuyInfo(t *testing.T) { Admin: true, }, "GET", "/buyInfo/1000", nil), ShouldBeZeroValue) - tf(400, "0", 0, "") - tf(200, "1000", 1000, "123456789abc123456789abc") - tf(500, "2000", 0, "") + tf(400, "0", "") + tf(200, "1000", "012345678901234567890123") + tf(500, "3000", "") }) } diff --git a/backend/api/content/main.go b/backend/api/content/main.go index 922b6fc..cd65aec 100644 --- a/backend/api/content/main.go +++ b/backend/api/content/main.go @@ -72,7 +72,7 @@ func addContent(c *gin.Context) { ContentID: p.ContentID, ContentToken: p.ContentToken, Content: data, - Type: content.Type(p.Type), + Type: content.Type(utils.EnumConvert(p.Type, content.Type_name)), }) if utils.LogContinue(err, utils.Error) { c.JSON(500, err) @@ -172,7 +172,7 @@ func updateContent(c *gin.Context) { ContentToken: p.ContentToken, FileID: p.FileID, Content: data, - Type: content.Type(p.Type), + Type: content.Type(utils.EnumConvert(p.Type, content.Type_name)), }) if utils.LogContinue(err, utils.Error) { c.JSON(500, err) diff --git a/backend/api/content/main_test.go b/backend/api/content/main_test.go index eb44754..25e0374 100644 --- a/backend/api/content/main_test.go +++ b/backend/api/content/main_test.go @@ -28,13 +28,13 @@ func Test_deleteContent(t *testing.T) { }, "DELETE", "/content?contentID=1000&contentToken=valid_token", nil), ShouldBeZeroValue) tf(400, "", "", 0) - tf(400, "1000", "", 0) + tf(400, "012345678901234567890123", "", 0) tf(400, "", "valid_token", 0) - tf(200, "1000", "valid_token", content.ContentDeleteResponse_SUCCESS) - tf(200, "1000", "invalid_token", content.ContentDeleteResponse_INVALID_TOKEN) - tf(200, "1001", "valid_token", content.ContentDeleteResponse_INVALID_TOKEN) - tf(200, "1001", "invalid_token", content.ContentDeleteResponse_INVALID_TOKEN) - tf(500, "2000", "valid_token", 0) + tf(200, "012345678901234567890123", "valid_token", content.ContentDeleteResponse_SUCCESS) + tf(200, "012345678901234567890123", "invalid_token", content.ContentDeleteResponse_INVALID_TOKEN) + tf(200, "12345", "valid_token", content.ContentDeleteResponse_INVALID_TOKEN) + tf(200, "12345", "invalid_token", content.ContentDeleteResponse_INVALID_TOKEN) + tf(500, "987654321098765432109876", "valid_token", 0) }) } diff --git a/backend/api/sellinfo/main.go b/backend/api/sellinfo/main.go index 1ae08dc..b98a6d3 100644 --- a/backend/api/sellinfo/main.go +++ b/backend/api/sellinfo/main.go @@ -147,7 +147,7 @@ func findSellInfo(c *gin.Context) { func() interface{} { return mock.NewSellInfoService() }).(sellinfo.SellInfoService) rsp, err := srv.Find(context.TODO(), &sellinfo.SellInfoFindRequest{ UserID: p.UserID, - Status: sellinfo.SellStatus(p.Status), + Status: sellinfo.SellStatus(utils.EnumConvert(p.Status, sellinfo.SellStatus_name)), GoodName: p.GoodName, LowPrice: p.LowPrice, HighPrice: p.HighPrice, diff --git a/backend/api/sellinfo/main_test.go b/backend/api/sellinfo/main_test.go index 1e2fc2b..0cbe0ab 100644 --- a/backend/api/sellinfo/main_test.go +++ b/backend/api/sellinfo/main_test.go @@ -4,18 +4,20 @@ import ( sellinfo "jiaojiao/srv/sellinfo/proto" "jiaojiao/utils" "net/url" + "strconv" "testing" . "github.com/smartystreets/goconvey/convey" ) func Test_getSellInfo(t *testing.T) { - tf := func(code int, path string, id int, cid string) { + tf := func(code int, path string, cid string) { c, d := utils.GetTestData(setupRouter, "GET", "/sellInfo/"+path, nil, "") So(c, ShouldEqual, code) if d != nil { - So(d["sellInfoID"], ShouldEqual, id) + v, _ := strconv.Atoi(path) + So(d["sellInfoID"], ShouldEqual, v) So(d["contentID"], ShouldEqual, cid) } } @@ -27,9 +29,9 @@ func Test_getSellInfo(t *testing.T) { Admin: true, }, "GET", "/sellinfo/1000", nil), ShouldBeZeroValue) - tf(400, "0", 0, "") - tf(200, "1000", 1000, "123456789abc123456789abc") - tf(500, "2000", 0, "") + tf(400, "0", "") + tf(200, "1000", "012345678901234567890123") + tf(500, "3000", "") }) } diff --git a/backend/api/transaction/main.go b/backend/api/transaction/main.go index 5540ae4..54c9d76 100644 --- a/backend/api/transaction/main.go +++ b/backend/api/transaction/main.go @@ -39,14 +39,14 @@ func setupRouter() *gin.Engine { */ func findTransaction(c *gin.Context) { type param struct { - InfoID int32 `form:"infoID"` - Category transaction.TransactionFindRequest_Category `form:"category"` - UserID int32 `form:"userID"` - LowCreateTime int64 `form:"lowCreateTime"` - HighCreateTime int64 `form:"highCreateTime"` - Status transaction.TransStatus `form:"status"` - Limit uint32 `form:"limit"` - Offset uint32 `form:"offset"` + InfoID int32 `form:"infoID"` + Category int32 `form:"category"` + UserID int32 `form:"userID"` + LowCreateTime int64 `form:"lowCreateTime"` + HighCreateTime int64 `form:"highCreateTime"` + Status int32 `form:"status"` + Limit uint32 `form:"limit"` + Offset uint32 `form:"offset"` } var p param @@ -65,11 +65,11 @@ func findTransaction(c *gin.Context) { func() interface{} { return mock.NewTransactionService() }).(transaction.TransactionService) rsp, err := srv.Find(context.TODO(), &transaction.TransactionFindRequest{ InfoID: p.InfoID, - Category: p.Category, + Category: transaction.Category(utils.EnumConvert(p.Category, transaction.Category_name)), UserID: p.UserID, LowCreateTime: p.LowCreateTime, HighCreateTime: p.HighCreateTime, - Status: p.Status, + Status: transaction.TransStatus(utils.EnumConvert(p.Status, transaction.TransStatus_name)), Limit: p.Limit, Offset: p.Offset, }) @@ -98,9 +98,9 @@ func findTransaction(c *gin.Context) { */ func addTransaction(c *gin.Context) { type param struct { - InfoID int32 `form:"infoID"` - Category transaction.TransactionCreateRequest_Category `form:"category"` - FromUserID int32 `form:"fromUserID"` + InfoID int32 `form:"infoID"` + Category int32 `form:"category"` + FromUserID int32 `form:"fromUserID"` } var p param role := utils.GetRole(c) @@ -114,7 +114,7 @@ func addTransaction(c *gin.Context) { func() interface{} { return mock.NewTransactionService() }).(transaction.TransactionService) rsp, err := srv.Create(context.TODO(), &transaction.TransactionCreateRequest{ InfoID: p.InfoID, - Category: p.Category, + Category: transaction.Category(utils.EnumConvert(p.Category, transaction.Category_name)), FromUserID: p.FromUserID, }) if utils.LogContinue(err, utils.Error) { @@ -142,8 +142,8 @@ func addTransaction(c *gin.Context) { */ func updateTransaction(c *gin.Context) { type param struct { - TransactionID int32 `form:"transactionID"` - Status transaction.TransStatus `form:"status"` + TransactionID int32 `form:"transactionID"` + Status int32 `form:"status"` } var p param role := utils.GetRole(c) @@ -157,7 +157,7 @@ func updateTransaction(c *gin.Context) { func() interface{} { return mock.NewTransactionService() }).(transaction.TransactionService) rsp, err := srv.Update(context.TODO(), &transaction.TransactionUpdateRequest{ TransactionID: p.TransactionID, - Status: p.Status, + Status: transaction.TransStatus(utils.EnumConvert(p.Status, transaction.TransStatus_name)), }) if utils.LogContinue(err, utils.Error) { c.JSON(500, err) diff --git a/backend/api/user/main.go b/backend/api/user/main.go index a8ba1c7..cb0e1e8 100644 --- a/backend/api/user/main.go +++ b/backend/api/user/main.go @@ -210,8 +210,8 @@ func updateUser(c *gin.Context) { Telephone: p.Telephone, StudentID: p.StudentID, StudentName: p.StudentName, - Status: user.UserInfo_Status(p.Status), - Role: user.UserInfo_Role(p.Role), + Status: user.UserInfo_Status(utils.EnumConvert(p.Status, user.UserInfo_Status_name)), + Role: user.UserInfo_Role(utils.EnumConvert(p.Role, user.UserInfo_Role_name)), ClearEmpty: p.ClearEmpty, }) if utils.LogContinue(err, utils.Error) { diff --git a/backend/api/user/main_test.go b/backend/api/user/main_test.go index 252355f..4229720 100644 --- a/backend/api/user/main_test.go +++ b/backend/api/user/main_test.go @@ -29,16 +29,16 @@ func Test_addUser(t *testing.T) { Self: false, Admin: true, }, "POST", "/user", url.Values{ - "studentID": {"1000"}, + "studentID": {"10000"}, "studentName": {"test"}, }), ShouldBeZeroValue) - tf(400, 0, "", "test", 1, "admin") - tf(400, 0, "1000", "", 1, "admin") - tf(200, user.UserCreateResponse_SUCCESS, "1000", "test", 1, "admin") - tf(200, user.UserCreateResponse_SUCCESS, "1001", "test", 2, "admin") - tf(500, 0, "2000", "test", 0, "admin") - tf(200, user.UserCreateResponse_USER_EXIST, "3001", "test", 1, "admin") + tf(400, 0, "", "test", 1000, "admin") + tf(400, 0, "10000", "", 1000, "admin") + tf(200, user.UserCreateResponse_SUCCESS, "10000", "test", 1000, "admin") + tf(200, user.UserCreateResponse_SUCCESS, "10001", "test", 1001, "admin") + tf(500, 0, "30000", "test", 0, "admin") + tf(200, user.UserCreateResponse_USER_EXIST, "30001", "test", 1000, "admin") }) } @@ -62,8 +62,8 @@ func Test_getUserInfo(t *testing.T) { tf(400, "0", false, 0, nil) tf(200, "1000", false, 1000, nil) - tf(200, "1000", true, 1000, "1000") - tf(500, "2000", false, 0, nil) + tf(200, "1000", true, 1000, "10000") + tf(500, "3000", false, 0, nil) }) } @@ -93,7 +93,7 @@ func Test_updateUser(t *testing.T) { v.Set("userID", "1001") tf(200, user.UserUpdateResponse_NOT_FOUND, "self") - v.Set("userID", "2000") + v.Set("userID", "3000") tf(500, 0, "self") }) } @@ -119,21 +119,21 @@ func Test_findUser(t *testing.T) { v.Set("userName", "test1") tf(200, false, 1, nil) - tf(200, true, 1, "1") + tf(200, true, 1, "10000") v.Set("userName", "test2") tf(200, false, 2, nil) v.Set("userName", "test3") - tf(200, true, 3, "1") - v.Set("userName", "down") + tf(200, true, 3, "10000") + v.Set("userName", "error") tf(500, false, 0, nil) v.Del("userName") - tf(200, true, 3, "1") + tf(200, true, 3, "10000") v.Set("limit", "2") - tf(200, true, 2, "1") + tf(200, true, 2, "10000") v.Set("offset", "1") - tf(200, true, 2, "2") + tf(200, true, 2, "10001") v.Set("offset", "2") - tf(200, true, 1, "3") + tf(200, true, 1, "10002") }) } diff --git a/backend/doc/api_project.js b/backend/doc/api_project.js index 41f13ee..466f149 100644 --- a/backend/doc/api_project.js +++ b/backend/doc/api_project.js @@ -20,7 +20,7 @@ define({ "apidoc": "0.3.0", "generator": { "name": "apidoc", - "time": "2019-08-01T01:55:10.521Z", + "time": "2019-08-01T03:25:44.780Z", "url": "http://apidocjs.com", "version": "0.17.7" } diff --git a/backend/doc/api_project.json b/backend/doc/api_project.json index c52a973..275897f 100644 --- a/backend/doc/api_project.json +++ b/backend/doc/api_project.json @@ -20,7 +20,7 @@ "apidoc": "0.3.0", "generator": { "name": "apidoc", - "time": "2019-08-01T01:55:10.521Z", + "time": "2019-08-01T03:25:44.780Z", "url": "http://apidocjs.com", "version": "0.17.7" } diff --git a/backend/srv/auth/mock/mock.go b/backend/srv/auth/mock/mock.go index f61e7e0..87ebd02 100644 --- a/backend/srv/auth/mock/mock.go +++ b/backend/srv/auth/mock/mock.go @@ -4,6 +4,7 @@ import ( "context" "errors" auth "jiaojiao/srv/auth/proto" + "jiaojiao/utils" "github.com/micro/go-micro/client" ) @@ -13,39 +14,34 @@ type mockSrv struct{} // Auth is auth auth mock func (a *mockSrv) Auth(ctx context.Context, req *auth.AuthRequest, opts ...client.CallOption) (*auth.AuthResponse, error) { var ret auth.AuthResponse - if req.Code == "" { + if !utils.RequireParam(req.Code) { ret.Status = auth.AuthResponse_INVALID_PARAM + return &ret, nil + } + if req.Code == "valid_user" { + ret.Status = auth.AuthResponse_SUCCESS + ret.Token = "valid_token" + ret.StudentID = "10000" + ret.StudentName = "user" + } else if req.Code == "valid_admin" { + ret.Status = auth.AuthResponse_SUCCESS + ret.Token = "valid_token" + ret.StudentID = "10001" + ret.StudentName = "admin" + } else if req.Code == "frozen_user" { + ret.Status = auth.AuthResponse_SUCCESS + ret.Token = "valid_token" + ret.StudentID = "20000" + ret.StudentName = "frozen" + } else if req.Code == "error" { + return &ret, errors.New("") + } else if req.Code == "user_error" { + ret.Status = auth.AuthResponse_SUCCESS + ret.Token = "valid_token" + ret.StudentID = "30000" + ret.StudentName = "error" } else { - if req.Code == "valid_user" { - ret.Status = auth.AuthResponse_SUCCESS - ret.Token = "test_token" - ret.StudentID = "1000" - ret.StudentName = "test" - } else if req.Code == "valid_admin" { - ret.Status = auth.AuthResponse_SUCCESS - ret.Token = "test_token" - ret.StudentID = "1001" - ret.StudentName = "test" - } else if req.Code == "frozen_user" { - ret.Status = auth.AuthResponse_SUCCESS - ret.Token = "test_token" - ret.StudentID = "3000" - ret.StudentName = "test" - } else if req.Code == "down" { - return &ret, errors.New("") - } else if req.Code == "userdown" { - ret.Status = auth.AuthResponse_SUCCESS - ret.Token = "test_token" - ret.StudentID = "2000" - ret.StudentName = "down" - } else if req.Code == "frozen" { - ret.Status = auth.AuthResponse_SUCCESS - ret.Token = "test_token" - ret.StudentID = "3000" - ret.StudentName = "frozen" - } else { - ret.Status = auth.AuthResponse_INVALID_CODE - } + ret.Status = auth.AuthResponse_INVALID_CODE } return &ret, nil } diff --git a/backend/srv/avatar/main.go b/backend/srv/avatar/main.go index 0940e25..311336f 100644 --- a/backend/srv/avatar/main.go +++ b/backend/srv/avatar/main.go @@ -3,14 +3,14 @@ package main import ( "context" "errors" - db "jiaojiao/database" avatar "jiaojiao/srv/avatar/proto" - "jiaojiao/srv/file/mock" + mockFile "jiaojiao/srv/file/mock" file "jiaojiao/srv/file/proto" + mockUser "jiaojiao/srv/user/mock" + user "jiaojiao/srv/user/proto" "jiaojiao/utils" "github.com/h2non/filetype" - "github.com/jinzhu/gorm" "github.com/micro/go-micro/client" ) @@ -35,49 +35,46 @@ func (a *srv) Create(ctx context.Context, req *avatar.AvatarCreateRequest, rsp * return nil } - if !utils.CheckInTest() && !filetype.IsImage(req.File) { + if !utils.CheckFile(req.File, filetype.IsImage) { rsp.Status = avatar.AvatarCreateResponse_INVALID_TYPE return nil } - usr := db.User{ - ID: req.UserID, - } - err := db.Ormer.First(&usr).Error - if gorm.IsRecordNotFoundError(err) { - rsp.Status = avatar.AvatarCreateResponse_NOT_FOUND - return nil - } else if utils.LogContinue(err, utils.Error) { - return err - } - - srv := utils.CallMicroService("file", func(name string, c client.Client) interface{} { return file.NewFileService(name, c) }, - func() interface{} { return mock.NewFileService() }).(file.FileService) - microRsp, err := srv.Create(context.TODO(), &file.FileCreateRequest{ + // upload file + srvFile := utils.CallMicroService("file", func(name string, c client.Client) interface{} { return file.NewFileService(name, c) }, + func() interface{} { return mockFile.NewFileService() }).(file.FileService) + fileRsp, err := srvFile.Create(context.TODO(), &file.FileCreateRequest{ File: req.File, }) if utils.LogContinue(err, utils.Error) { return err } - if microRsp.Status != file.FileCreateResponse_SUCCESS { - _, s := utils.LogContinueS("File create return "+microRsp.Status.String(), utils.Error) + if fileRsp.Status != file.FileCreateResponse_SUCCESS { + _, s := utils.LogContinueS("File create return "+fileRsp.Status.String(), utils.Error) return errors.New(s) } - usr.AvatarID = microRsp.FileID - err = db.Ormer.Save(&usr).Error + // update user + srvUser := utils.CallMicroService("user", func(name string, c client.Client) interface{} { return user.NewUserService(name, c) }, + func() interface{} { return mockUser.NewUserService() }).(user.UserService) + userRsp, err := srvUser.Update(context.TODO(), &user.UserInfo{ + UserID: req.UserID, + AvatarID: fileRsp.FileID, + }) if utils.LogContinue(err, utils.Error) { return err } + if userRsp.Status != user.UserUpdateResponse_SUCCESS { + _, s := utils.LogContinueS("User update return "+userRsp.Status.String(), utils.Error) + return errors.New(s) + } - rsp.AvatarID = microRsp.FileID + rsp.AvatarID = fileRsp.FileID rsp.Status = avatar.AvatarCreateResponse_SUCCESS return nil } func main() { - db.InitORM("userdb", new(db.User)) - defer db.CloseORM() service := utils.InitMicroService("avatar") utils.LogPanic(avatar.RegisterAvatarHandler(service.Server(), new(srv))) utils.RunMicroService(service) diff --git a/backend/srv/avatar/main_test.go b/backend/srv/avatar/main_test.go index d0c980b..8d63c61 100644 --- a/backend/srv/avatar/main_test.go +++ b/backend/srv/avatar/main_test.go @@ -1,11 +1,31 @@ package main import ( + "context" + avatar "jiaojiao/srv/avatar/proto" + "jiaojiao/utils" "testing" + + . "github.com/smartystreets/goconvey/convey" ) func TestAvatarCreate(t *testing.T) { - // TODO + tf := func(userID int32, file string, status avatar.AvatarCreateResponse_Status) { + var s srv + var rsp avatar.AvatarCreateResponse + So(s.Create(context.TODO(), &avatar.AvatarCreateRequest{ + UserID: userID, + File: utils.If(file != "", []byte(file), []byte{0}).([]byte), + }, &rsp), ShouldBeNil) + So(rsp.Status, ShouldEqual, status) + } + + Convey("Test Avatar Create", t, func() { + tf(0, "valid_file", avatar.AvatarCreateResponse_INVALID_PARAM) + tf(1000, "", avatar.AvatarCreateResponse_INVALID_PARAM) + tf(1000, "invalid_file", avatar.AvatarCreateResponse_INVALID_TYPE) + tf(1000, "valid_file", avatar.AvatarCreateResponse_SUCCESS) + }) } func TestMain(m *testing.M) { diff --git a/backend/srv/avatar/mock/mock.go b/backend/srv/avatar/mock/mock.go index df845d0..9fba136 100644 --- a/backend/srv/avatar/mock/mock.go +++ b/backend/srv/avatar/mock/mock.go @@ -2,7 +2,9 @@ package mock import ( "context" + "errors" avatar "jiaojiao/srv/avatar/proto" + "jiaojiao/utils" "github.com/micro/go-micro/client" ) @@ -10,9 +12,22 @@ import ( type mockSrv struct{} // Create is avatar create mock -func (a *mockSrv) Create(ctx context.Context, in *avatar.AvatarCreateRequest, opts ...client.CallOption) (*avatar.AvatarCreateResponse, error) { +func (a *mockSrv) Create(ctx context.Context, req *avatar.AvatarCreateRequest, opts ...client.CallOption) (*avatar.AvatarCreateResponse, error) { var rsp avatar.AvatarCreateResponse - // TODO + if !utils.RequireParam(req.File, req.UserID) { + rsp.Status = avatar.AvatarCreateResponse_INVALID_PARAM + return &rsp, nil + } + + switch string(req.File) { + case "invalid": + rsp.Status = avatar.AvatarCreateResponse_INVALID_TYPE + case "valid": + rsp.Status = avatar.AvatarCreateResponse_SUCCESS + rsp.AvatarID = "012345678901234567890123" + case "error": + return nil, errors.New("") + } return &rsp, nil } diff --git a/backend/srv/avatar/proto/avatar.pb.go b/backend/srv/avatar/proto/avatar.pb.go index 48aa3ea..703ab2e 100644 --- a/backend/srv/avatar/proto/avatar.pb.go +++ b/backend/srv/avatar/proto/avatar.pb.go @@ -26,24 +26,21 @@ const ( AvatarCreateResponse_UNKNOWN AvatarCreateResponse_Status = 0 AvatarCreateResponse_INVALID_PARAM AvatarCreateResponse_Status = -1 AvatarCreateResponse_SUCCESS AvatarCreateResponse_Status = 1 - AvatarCreateResponse_NOT_FOUND AvatarCreateResponse_Status = 2 - AvatarCreateResponse_INVALID_TYPE AvatarCreateResponse_Status = 3 + AvatarCreateResponse_INVALID_TYPE AvatarCreateResponse_Status = 2 ) var AvatarCreateResponse_Status_name = map[int32]string{ 0: "UNKNOWN", -1: "INVALID_PARAM", 1: "SUCCESS", - 2: "NOT_FOUND", - 3: "INVALID_TYPE", + 2: "INVALID_TYPE", } var AvatarCreateResponse_Status_value = map[string]int32{ "UNKNOWN": 0, "INVALID_PARAM": -1, "SUCCESS": 1, - "NOT_FOUND": 2, - "INVALID_TYPE": 3, + "INVALID_TYPE": 2, } func (x AvatarCreateResponse_Status) String() string { @@ -157,21 +154,20 @@ func init() { func init() { proto.RegisterFile("avatar.proto", fileDescriptor_082ad687f88f08fc) } var fileDescriptor_082ad687f88f08fc = []byte{ - // 252 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x90, 0xc1, 0x4b, 0xc3, 0x30, - 0x14, 0xc6, 0xcd, 0xd4, 0xe8, 0x9e, 0x9d, 0x84, 0xe7, 0x94, 0x51, 0x3c, 0x8c, 0x9e, 0x76, 0xea, - 0x61, 0xea, 0x59, 0x42, 0x3b, 0xa1, 0xa8, 0xe9, 0x48, 0x57, 0xc5, 0x53, 0x89, 0x10, 0x41, 0x10, - 0x3b, 0x93, 0xd4, 0xff, 0xd1, 0xbf, 0x4a, 0x31, 0xd9, 0x04, 0xa1, 0x39, 0xe5, 0x83, 0xdf, 0xfb, - 0xde, 0xf7, 0x3e, 0x88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0x00, 0x00, + // 238 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x49, 0x2c, 0x4b, 0x2c, + 0x49, 0x2c, 0xd2, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x57, 0x72, 0xe4, 0x12, 0x76, 0x04, 0xf3, 0x9d, + 0x8b, 0x52, 0x13, 0x4b, 0x52, 0x83, 0x52, 0x0b, 0x4b, 0x53, 0x8b, 0x4b, 0x84, 0xc4, 0xb8, 0xd8, + 0x4a, 0x8b, 0x53, 0x8b, 0x3c, 0x5d, 0x24, 0x18, 0x15, 0x18, 0x35, 0x58, 0x83, 0xa0, 0x3c, 0x21, + 0x21, 0x2e, 0x96, 0xb4, 0xcc, 0x9c, 0x54, 0x09, 0x26, 0x05, 0x46, 0x0d, 0x9e, 0x20, 0x30, 0x5b, + 0x69, 0x17, 0x23, 0x97, 0x08, 0xaa, 0x19, 0xc5, 0x05, 0xf9, 0x79, 0xc5, 0xa9, 0x42, 0x26, 0x5c, + 0x6c, 0xc5, 0x25, 0x89, 0x25, 0xa5, 0xc5, 0x60, 0x43, 0xf8, 0x8c, 0x64, 0xf4, 0xb0, 0x29, 0xd3, + 0x0b, 0x06, 0xab, 0x09, 0x82, 0xaa, 0x15, 0x92, 0xe2, 0xe2, 0x80, 0xb8, 0xd0, 0xd3, 0x05, 0x6c, + 0x0d, 0x67, 0x10, 0x9c, 0xaf, 0x14, 0xc0, 0xc5, 0x06, 0x51, 0x2d, 0xc4, 0xcd, 0xc5, 0x1e, 0xea, + 0xe7, 0xed, 0xe7, 0x1f, 0xee, 0x27, 0xc0, 0x20, 0x24, 0xc5, 0xc5, 0xeb, 0xe9, 0x17, 0xe6, 0xe8, + 0xe3, 0xe9, 0x12, 0x1f, 0xe0, 0x18, 0xe4, 0xe8, 0x2b, 0xf0, 0x1f, 0x06, 0x18, 0x41, 0x0a, 0x83, + 0x43, 0x9d, 0x9d, 0x5d, 0x83, 0x83, 0x05, 0x18, 0x85, 0x04, 0xb8, 0x78, 0x60, 0x0a, 0x43, 0x22, + 0x03, 0x5c, 0x05, 0x98, 0x8c, 0xec, 0xb9, 0xd8, 0x20, 0x8e, 0x12, 0x32, 0xe5, 0x62, 0x83, 0x38, + 0x4c, 0x48, 0x44, 0x0f, 0x4b, 0x90, 0x48, 0x89, 0x62, 0x75, 0x7d, 0x12, 0x1b, 0x38, 0x1c, 0x8d, + 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0x31, 0x87, 0x8e, 0xe7, 0x57, 0x01, 0x00, 0x00, } diff --git a/backend/srv/avatar/proto/avatar.proto b/backend/srv/avatar/proto/avatar.proto index 5c7cdb9..96bbc61 100644 --- a/backend/srv/avatar/proto/avatar.proto +++ b/backend/srv/avatar/proto/avatar.proto @@ -14,8 +14,7 @@ message AvatarCreateResponse { UNKNOWN = 0; INVALID_PARAM = -1; SUCCESS = 1; - NOT_FOUND = 2; - INVALID_TYPE = 3; + INVALID_TYPE = 2; } Status status = 1; string avatarID = 2; diff --git a/backend/srv/buyinfo/main.go b/backend/srv/buyinfo/main.go index 5b46777..42b8e98 100644 --- a/backend/srv/buyinfo/main.go +++ b/backend/srv/buyinfo/main.go @@ -59,7 +59,7 @@ func (a *srv) Query(ctx context.Context, req *buyinfo.BuyInfoQueryRequest, rsp * } rsp.BuyInfoID = info.ID - rsp.Status = buyinfo.BuyStatus(info.Status) + rsp.Status = buyinfo.BuyStatus(utils.EnumConvert(info.Status, buyinfo.BuyStatus_name)) rsp.ReleaseTime = info.ReleaseTime.Unix() rsp.ValidTime = info.ValidTime.Unix() rsp.GoodName = good.GoodName @@ -249,7 +249,7 @@ func (a *srv) Find(ctx context.Context, req *buyinfo.BuyInfoFindRequest, rsp *bu for _, v := range res { rsp.BuyInfo = append(rsp.BuyInfo, &buyinfo.BuyInfoMsg{ BuyInfoID: v.BuyInfoID, - Status: buyinfo.BuyStatus(v.Status), + Status: buyinfo.BuyStatus(utils.EnumConvert(v.Status, buyinfo.BuyStatus_name)), ReleaseTime: v.ReleaseTime.Unix(), ValidTime: v.ValidTime.Unix(), GoodName: v.GoodName, diff --git a/backend/srv/buyinfo/main_test.go b/backend/srv/buyinfo/main_test.go index f6ce6fb..0e0e535 100644 --- a/backend/srv/buyinfo/main_test.go +++ b/backend/srv/buyinfo/main_test.go @@ -15,22 +15,22 @@ func TestSrvInfoQuery(t *testing.T) { var req buyinfo.BuyInfoQueryRequest info := db.BuyInfo{ - ID: 2100, + ID: 1100, ReleaseTime: time.Date(2019, 9, 9, 9, 9, 9, 0, time.Local), ValidTime: time.Date(2020, 9, 9, 9, 9, 9, 0, time.Local), UserID: 1000, - GoodID: 2101, + GoodID: 2110, } good := db.Good{ - ID: 2101, + ID: 2110, GoodName: "good", Description: "Very good!", - ContentID: "123456789", + ContentID: "012345678901234567890123", } - tf := func(buyID int, contentID string, userID int) { + tf := func(sellID int, contentID string, userID int) { var rsp buyinfo.BuyInfoMsg So(s.Query(context.TODO(), &req, &rsp), ShouldBeNil) - So(rsp.BuyInfoID, ShouldEqual, buyID) + So(rsp.BuyInfoID, ShouldEqual, sellID) So(rsp.ContentID, ShouldEqual, contentID) So(rsp.UserID, ShouldEqual, userID) } @@ -40,17 +40,16 @@ func TestSrvInfoQuery(t *testing.T) { So(db.Ormer.Create(&good).Error, ShouldBeNil) So(db.Ormer.Create(&info).Error, ShouldBeNil) defer func() { - So(db.Ormer.Delete(&db.Good{ID: 2101}).Error, ShouldBeNil) - So(db.Ormer.Delete(&db.BuyInfo{ID: 2100}).Error, ShouldBeNil) + So(db.Ormer.Delete(&db.Good{ID: 2110}).Error, ShouldBeNil) + So(db.Ormer.Delete(&db.BuyInfo{ID: 1100}).Error, ShouldBeNil) }() - req.BuyInfoID = 2100 - tf(2100, "123456789", 1000) + req.BuyInfoID = 1100 + tf(1100, "012345678901234567890123", 1000) - req.BuyInfoID = 2101 + req.BuyInfoID = 1101 tf(0, "", 0) }) - } func TestSrvInfoCreate(t *testing.T) { @@ -62,7 +61,7 @@ func TestSrvInfoFind(t *testing.T) { var req buyinfo.BuyInfoFindRequest info1 := db.BuyInfo{ - ID: 2000, + ID: 1000, Status: 1, ReleaseTime: time.Date(2019, 9, 9, 9, 9, 9, 0, time.Local), ValidTime: time.Date(2020, 9, 9, 9, 9, 9, 0, time.Local), @@ -70,7 +69,7 @@ func TestSrvInfoFind(t *testing.T) { GoodID: 2010, } info2 := db.BuyInfo{ - ID: 2001, + ID: 1001, Status: 2, ReleaseTime: time.Date(2019, 9, 9, 9, 9, 9, 0, time.Local), ValidTime: time.Date(2020, 9, 9, 9, 9, 9, 0, time.Local), @@ -78,7 +77,7 @@ func TestSrvInfoFind(t *testing.T) { GoodID: 2011, } info3 := db.BuyInfo{ - ID: 2002, + ID: 1002, Status: 3, ReleaseTime: time.Date(2019, 9, 9, 9, 9, 9, 0, time.Local), ValidTime: time.Date(2020, 9, 9, 9, 9, 9, 0, time.Local), @@ -89,19 +88,19 @@ func TestSrvInfoFind(t *testing.T) { ID: 2010, GoodName: "good", Description: "Very good!", - ContentID: "123456789", + ContentID: "012345678901234567890123", } good2 := db.Good{ ID: 2011, GoodName: "good", Description: "Very good!", - ContentID: "123456789", + ContentID: "012345678901234567890123", } good3 := db.Good{ ID: 2012, GoodName: "good", Description: "Very good!", - ContentID: "123456789", + ContentID: "012345678901234567890123", } prepare := func() { @@ -113,9 +112,9 @@ func TestSrvInfoFind(t *testing.T) { So(db.Ormer.Create(&info3).Error, ShouldBeNil) } end := func() { - So(db.Ormer.Delete(&db.BuyInfo{ID: 2000}).Error, ShouldBeNil) - So(db.Ormer.Delete(&db.BuyInfo{ID: 2001}).Error, ShouldBeNil) - So(db.Ormer.Delete(&db.BuyInfo{ID: 2002}).Error, ShouldBeNil) + So(db.Ormer.Delete(&db.BuyInfo{ID: 1000}).Error, ShouldBeNil) + So(db.Ormer.Delete(&db.BuyInfo{ID: 1001}).Error, ShouldBeNil) + So(db.Ormer.Delete(&db.BuyInfo{ID: 1002}).Error, ShouldBeNil) So(db.Ormer.Delete(&db.Good{ID: 2010}).Error, ShouldBeNil) So(db.Ormer.Delete(&db.Good{ID: 2011}).Error, ShouldBeNil) diff --git a/backend/srv/buyinfo/mock/mock.go b/backend/srv/buyinfo/mock/mock.go index 18a4214..28d65be 100644 --- a/backend/srv/buyinfo/mock/mock.go +++ b/backend/srv/buyinfo/mock/mock.go @@ -4,6 +4,7 @@ import ( "context" "errors" buyinfo "jiaojiao/srv/buyinfo/proto" + "jiaojiao/utils" "github.com/micro/go-micro/client" ) @@ -13,14 +14,15 @@ type mockSrv struct{} // Find is buyinfo create mock func (a *mockSrv) Create(ctx context.Context, req *buyinfo.BuyInfoCreateRequest, opts ...client.CallOption) (*buyinfo.BuyInfoCreateResponse, error) { var rsp buyinfo.BuyInfoCreateResponse - if req.ValidTime == 0 || req.GoodName == "" || req.UserID == 0 { + if !utils.RequireParam(req.ValidTime, req.GoodName, req.UserID) { rsp.Status = buyinfo.BuyInfoCreateResponse_INVALID_PARAM return &rsp, nil } - if req.ContentID == "" && req.ContentToken == "" { + + if utils.IsEmpty(req.ContentID) && utils.IsEmpty(req.ContentToken) { rsp.Status = buyinfo.BuyInfoCreateResponse_SUCCESS rsp.BuyInfoID = 1000 - } else if req.ContentID != "" && req.ContentToken != "" { + } else if !utils.IsEmpty(req.ContentID) && !utils.IsEmpty(req.ContentToken) { if req.ContentID == "error" { return nil, errors.New("") } @@ -39,15 +41,15 @@ func (a *mockSrv) Create(ctx context.Context, req *buyinfo.BuyInfoCreateRequest, // Find is buyinfo query mock func (a *mockSrv) Query(ctx context.Context, req *buyinfo.BuyInfoQueryRequest, opts ...client.CallOption) (*buyinfo.BuyInfoMsg, error) { var rsp buyinfo.BuyInfoMsg - if req.BuyInfoID != 0 { + if utils.RequireParam(req.BuyInfoID) { if req.BuyInfoID == 1000 { rsp.BuyInfoID = 1000 rsp.GoodName = "good" rsp.ValidTime = 1234567890 rsp.Description = "very good!" - rsp.ContentID = "123456789abc123456789abc" + rsp.ContentID = "012345678901234567890123" rsp.UserID = 1000 - } else if req.BuyInfoID == 2000 { + } else if req.BuyInfoID == 3000 { return nil, errors.New("") } } diff --git a/backend/srv/content/main_test.go b/backend/srv/content/main_test.go index 2ad21c8..847d501 100644 --- a/backend/srv/content/main_test.go +++ b/backend/srv/content/main_test.go @@ -30,12 +30,12 @@ func TestSrvContentCreate(t *testing.T) { req.Content = []byte{0} tf(content.ContentCreateResponse_INVALID_PARAM, false) - req.Type = content.ContentCreateRequest_PICTURE + req.Type = content.Type_PICTURE tf(content.ContentCreateResponse_INVALID_PARAM, false) req.Type = 0 req.Content = []byte{1, 2, 3, 4, 5, 6} tf(content.ContentCreateResponse_INVALID_PARAM, false) - req.Type = content.ContentCreateRequest_PICTURE + req.Type = content.Type_PICTURE req.ContentID = "1234" tf(content.ContentCreateResponse_INVALID_PARAM, false) req.ContentID = "" diff --git a/backend/srv/content/mock/mock.go b/backend/srv/content/mock/mock.go index 109c9c4..a90ac04 100644 --- a/backend/srv/content/mock/mock.go +++ b/backend/srv/content/mock/mock.go @@ -1,10 +1,10 @@ package mock import ( - "bytes" "context" "errors" content "jiaojiao/srv/content/proto" + "jiaojiao/utils" "github.com/micro/go-micro/client" ) @@ -35,11 +35,11 @@ func (a *mockSrv) Check(ctx context.Context, in *content.ContentCheckRequest, op // Create is content create mock func (a *mockSrv) Create(ctx context.Context, req *content.ContentCreateRequest, opts ...client.CallOption) (*content.ContentCreateResponse, error) { var rsp content.ContentCreateResponse - if bytes.Equal(req.Content, []byte{0}) || req.Type == 0 { + if !utils.RequireParam(req.Content, req.Type) { rsp.Status = content.ContentCreateResponse_INVALID_PARAM - } else if req.ContentID == "" && req.ContentToken == "" { + } else if utils.IsEmpty(req.ContentID) && utils.IsEmpty(req.ContentToken) { rsp.Status = content.ContentCreateResponse_SUCCESS - } else if req.ContentID != "" && req.ContentToken != "" { + } else if !utils.IsEmpty(req.ContentID) && !utils.IsEmpty(req.ContentToken) { if req.ContentID == "invalid" { rsp.Status = content.ContentCreateResponse_INVALID_TYPE return &rsp, nil @@ -61,20 +61,21 @@ func (a *mockSrv) Create(ctx context.Context, req *content.ContentCreateRequest, // Delete is content delete mock func (a *mockSrv) Delete(ctx context.Context, req *content.ContentDeleteRequest, opts ...client.CallOption) (*content.ContentDeleteResponse, error) { var rsp content.ContentDeleteResponse - if req.ContentID == "" || req.ContentToken == "" { + if !utils.RequireParam(req.ContentID, req.ContentToken) { rsp.Status = content.ContentDeleteResponse_INVALID_PARAM - } else { - if req.ContentID == "1000" { - if req.ContentToken == "valid_token" { - rsp.Status = content.ContentDeleteResponse_SUCCESS - } else { - rsp.Status = content.ContentDeleteResponse_INVALID_TOKEN - } - } else if req.ContentID == "2000" { - return nil, errors.New("") + return &rsp, nil + } + + if req.ContentID == "012345678901234567890123" { + if req.ContentToken == "valid_token" { + rsp.Status = content.ContentDeleteResponse_SUCCESS } else { rsp.Status = content.ContentDeleteResponse_INVALID_TOKEN } + } else if req.ContentID == "987654321098765432109876" { + return nil, errors.New("") + } else { + rsp.Status = content.ContentDeleteResponse_INVALID_TOKEN } return &rsp, nil } diff --git a/backend/srv/file/mock/mock.go b/backend/srv/file/mock/mock.go index 19d8362..5755bd9 100644 --- a/backend/srv/file/mock/mock.go +++ b/backend/srv/file/mock/mock.go @@ -2,7 +2,9 @@ package mock import ( "context" + "errors" file "jiaojiao/srv/file/proto" + "jiaojiao/utils" "github.com/micro/go-micro/client" ) @@ -10,23 +12,44 @@ import ( type mockFileSrv struct{} // Create is file create mock -func (a *mockFileSrv) Create(ctx context.Context, in *file.FileCreateRequest, opts ...client.CallOption) (*file.FileCreateResponse, error) { +func (a *mockFileSrv) Create(ctx context.Context, req *file.FileCreateRequest, opts ...client.CallOption) (*file.FileCreateResponse, error) { var rsp file.FileCreateResponse - // TODO + if !utils.RequireParam(req.File) { + rsp.Status = file.FileCreateResponse_INVALID_PARAM + return &rsp, nil + } + + if string(req.File) == "error" { + return nil, errors.New("") + } + + rsp.Status = file.FileCreateResponse_SUCCESS + rsp.FileID = "012345678901234567891234" return &rsp, nil } // Query is file query mock -func (a *mockFileSrv) Query(ctx context.Context, in *file.FileRequest, opts ...client.CallOption) (*file.FileQueryResponse, error) { +func (a *mockFileSrv) Query(ctx context.Context, req *file.FileRequest, opts ...client.CallOption) (*file.FileQueryResponse, error) { var rsp file.FileQueryResponse // TODO return &rsp, nil } // Delete is file delete mock -func (a *mockFileSrv) Delete(ctx context.Context, in *file.FileRequest, opts ...client.CallOption) (*file.FileDeleteResponse, error) { +func (a *mockFileSrv) Delete(ctx context.Context, req *file.FileRequest, opts ...client.CallOption) (*file.FileDeleteResponse, error) { var rsp file.FileDeleteResponse - // TODO + if !utils.RequireParam(req.FileID) { + rsp.Status = file.FileDeleteResponse_INVALID_PARAM + return &rsp, nil + } + + if req.FileID == "012345678901234567891234" { + rsp.Status = file.FileDeleteResponse_SUCCESS + } else if req.FileID == "987654321098765432109876" { + return nil, errors.New("") + } else { + rsp.Status = file.FileDeleteResponse_NOT_FOUND + } return &rsp, nil } diff --git a/backend/srv/sellinfo/main.go b/backend/srv/sellinfo/main.go index 879d095..9687de1 100644 --- a/backend/srv/sellinfo/main.go +++ b/backend/srv/sellinfo/main.go @@ -60,7 +60,7 @@ func (a *srv) Query(ctx context.Context, req *sellinfo.SellInfoQueryRequest, rsp } rsp.SellInfoID = info.ID - rsp.Status = sellinfo.SellStatus(info.Status) + rsp.Status = sellinfo.SellStatus(utils.EnumConvert(info.Status, sellinfo.SellStatus_name)) rsp.ReleaseTime = info.ReleaseTime.Unix() rsp.ValidTime = info.ValidTime.Unix() rsp.GoodName = good.GoodName @@ -250,7 +250,7 @@ func (a *srv) Find(ctx context.Context, req *sellinfo.SellInfoFindRequest, rsp * for _, v := range res { rsp.SellInfo = append(rsp.SellInfo, &sellinfo.SellInfoMsg{ SellInfoID: v.SellInfoID, - Status: sellinfo.SellStatus(v.Status), + Status: sellinfo.SellStatus(utils.EnumConvert(v.Status, sellinfo.SellStatus_name)), ReleaseTime: v.ReleaseTime.Unix(), ValidTime: v.ValidTime.Unix(), GoodName: v.GoodName, diff --git a/backend/srv/sellinfo/main_test.go b/backend/srv/sellinfo/main_test.go index 477f0be..839c2dd 100644 --- a/backend/srv/sellinfo/main_test.go +++ b/backend/srv/sellinfo/main_test.go @@ -19,13 +19,13 @@ func TestSrvInfoQuery(t *testing.T) { ReleaseTime: time.Date(2019, 9, 9, 9, 9, 9, 0, time.Local), ValidTime: time.Date(2020, 9, 9, 9, 9, 9, 0, time.Local), UserID: 1000, - GoodID: 1101, + GoodID: 1110, } good := db.Good{ - ID: 1101, + ID: 1110, GoodName: "good", Description: "Very good!", - ContentID: "123456789", + ContentID: "012345678901234567890123", } tf := func(sellID int, contentID string, userID int) { var rsp sellinfo.SellInfoMsg @@ -40,12 +40,12 @@ func TestSrvInfoQuery(t *testing.T) { So(db.Ormer.Create(&good).Error, ShouldBeNil) So(db.Ormer.Create(&info).Error, ShouldBeNil) defer func() { - So(db.Ormer.Delete(&db.Good{ID: 1101}).Error, ShouldBeNil) + So(db.Ormer.Delete(&db.Good{ID: 1110}).Error, ShouldBeNil) So(db.Ormer.Delete(&db.SellInfo{ID: 1100}).Error, ShouldBeNil) }() req.SellInfoID = 1100 - tf(1100, "123456789", 1000) + tf(1100, "012345678901234567890123", 1000) req.SellInfoID = 1101 tf(0, "", 0) @@ -54,80 +54,6 @@ func TestSrvInfoQuery(t *testing.T) { func TestSrvInfoCreate(t *testing.T) { // TODO - //var s srv - //var req sellinfo.SellInfoCreateRequest - //srv := utils.CallMicroService("content", func(name string, c client.Client) interface{} { return content.NewContentService(name, c) }, - // func() interface{} { return mock.NewContentService() }).(content.ContentService) - // - //getToken := func() (string, string) { - // rsp, err := srv.Create(context.TODO(), &content.ContentCreateRequest{ - // Content: []byte{1, 2, 3, 4, 5, 6}, - // Type: content.ContentCreateRequest_PICTURE, - // }) - // So(err, ShouldBeNil) - // So(rsp.Status, ShouldEqual, content.ContentCreateResponse_SUCCESS) - // So(rsp.ContentID, ShouldNotBeBlank) - // So(rsp.ContentToken, ShouldNotBeBlank) - // - // return rsp.ContentID, rsp.ContentToken - //} - // - //tf := func(status sellinfo.SellInfoCreateResponse_Status, success bool) int32 { - // var rsp sellinfo.SellInfoCreateResponse - // So(s.Create(context.TODO(), &req, &rsp), ShouldBeNil) - // So(rsp.Status, ShouldEqual, status) - // if success { - // So(rsp.SellInfoID, ShouldNotEqual, 0) - // } else { - // So(rsp.SellInfoID, ShouldEqual, 0) - // } - // return rsp.SellInfoID - //} - // - //Convey("Test SellInfo Create", t, func() { - // tf(sellinfo.SellInfoCreateResponse_INVALID_PARAM, false) - // - // req.GoodName = "good" - // tf(sellinfo.SellInfoCreateResponse_INVALID_PARAM, false) - // - // req.ValidTime = 1893427200 - // tf(sellinfo.SellInfoCreateResponse_INVALID_PARAM, false) - // - // req.FromUserID = 1000 - // id := tf(sellinfo.SellInfoCreateResponse_SUCCESS, true) - // - // tmp := db.SellInfo{ - // ID: id, - // } - // So(db.Ormer.First(&tmp).Error, ShouldBeNil) - // So(db.Ormer.Delete(&db.Good{ID: tmp.GoodID}).Error, ShouldBeNil) - // So(db.Ormer.Delete(&tmp).Error, ShouldBeNil) - // - // req.ContentID = "123456789abc123456789abc" - // tf(sellinfo.SellInfoCreateResponse_INVALID_PARAM, false) - // - // req.ContentToken = "jlkfjaoiu2709429-98247ksf" - // tf(sellinfo.SellInfoCreateResponse_INVALID_TOKEN, false) - // - // req.ContentID = "1234" - // tf(sellinfo.SellInfoCreateResponse_INVALID_PARAM, false) - // - // req.ContentID, req.ContentToken = getToken() - // id = tf(sellinfo.SellInfoCreateResponse_SUCCESS, true) - // - // tmp = db.SellInfo{ - // ID: id, - // } - // So(db.Ormer.First(&tmp).Error, ShouldBeNil) - // So(db.Ormer.Delete(&db.Good{ID: tmp.GoodID}).Error, ShouldBeNil) - // So(db.Ormer.Delete(&tmp).Error, ShouldBeNil) - // - // _, err := srv.Delete(context.TODO(), &content.ContentDeleteRequest{ - // ContentID: req.ContentID, - // ContentToken: req.ContentToken, - // }) - // So(err, ShouldBeNil) - //}) } func TestSrvInfoFind(t *testing.T) { @@ -162,19 +88,19 @@ func TestSrvInfoFind(t *testing.T) { ID: 1010, GoodName: "good", Description: "Very good!", - ContentID: "123456789", + ContentID: "012345678901234567890123", } good2 := db.Good{ ID: 1011, GoodName: "good", Description: "Very good!", - ContentID: "123456789", + ContentID: "012345678901234567890123", } good3 := db.Good{ ID: 1012, GoodName: "good", Description: "Very good!", - ContentID: "123456789", + ContentID: "012345678901234567890123", } prepare := func() { diff --git a/backend/srv/sellinfo/mock/mock.go b/backend/srv/sellinfo/mock/mock.go index 72fb8e3..80523ae 100644 --- a/backend/srv/sellinfo/mock/mock.go +++ b/backend/srv/sellinfo/mock/mock.go @@ -4,6 +4,7 @@ import ( "context" "errors" sellinfo "jiaojiao/srv/sellinfo/proto" + "jiaojiao/utils" "github.com/micro/go-micro/client" ) @@ -13,14 +14,15 @@ type mockSrv struct{} // Create is sellinfo create mock func (a *mockSrv) Create(ctx context.Context, req *sellinfo.SellInfoCreateRequest, opts ...client.CallOption) (*sellinfo.SellInfoCreateResponse, error) { var rsp sellinfo.SellInfoCreateResponse - if req.ValidTime == 0 || req.GoodName == "" || req.UserID == 0 { + if !utils.RequireParam(req.ValidTime, req.GoodName, req.UserID) { rsp.Status = sellinfo.SellInfoCreateResponse_INVALID_PARAM return &rsp, nil } - if req.ContentID == "" && req.ContentToken == "" { + + if utils.IsEmpty(req.ContentID) && utils.IsEmpty(req.ContentToken) { rsp.Status = sellinfo.SellInfoCreateResponse_SUCCESS rsp.SellInfoID = 1000 - } else if req.ContentID != "" && req.ContentToken != "" { + } else if !utils.IsEmpty(req.ContentID) && !utils.IsEmpty(req.ContentToken) { if req.ContentID == "error" { return nil, errors.New("") } @@ -39,15 +41,15 @@ func (a *mockSrv) Create(ctx context.Context, req *sellinfo.SellInfoCreateReques // Query is sellinfo query mock func (a *mockSrv) Query(ctx context.Context, req *sellinfo.SellInfoQueryRequest, opts ...client.CallOption) (*sellinfo.SellInfoMsg, error) { var rsp sellinfo.SellInfoMsg - if req.SellInfoID != 0 { + if utils.RequireParam(req.SellInfoID) { if req.SellInfoID == 1000 { rsp.SellInfoID = 1000 rsp.GoodName = "good" rsp.ValidTime = 1234567890 rsp.Description = "very good!" - rsp.ContentID = "123456789abc123456789abc" + rsp.ContentID = "012345678901234567890123" rsp.UserID = 1000 - } else if req.SellInfoID == 2000 { + } else if req.SellInfoID == 3000 { return nil, errors.New("") } } diff --git a/backend/srv/transaction/main.go b/backend/srv/transaction/main.go index 1689f8d..a1b1e08 100644 --- a/backend/srv/transaction/main.go +++ b/backend/srv/transaction/main.go @@ -38,7 +38,7 @@ func (a *srv) Create(ctx context.Context, req *transaction.TransactionCreateRequ } var toUserID int32 - if req.Category == transaction.TransactionCreateRequest_SELL { + if req.Category == transaction.Category_SELL { microSrv := utils.CallMicroService("sellInfo", func(name string, c client.Client) interface{} { return sellinfo.NewSellInfoService(name, c) }, func() interface{} { return mocksell.NewSellInfoService() }).(sellinfo.SellInfoService) srvRsp, err := microSrv.Query(context.TODO(), &sellinfo.SellInfoQueryRequest{ @@ -164,7 +164,7 @@ func (a *srv) Find(ctx context.Context, req *transaction.TransactionFindRequest, if req.InfoID != 0 { tx = tx.Where("info_id = ?", req.InfoID) } - if req.Category != transaction.TransactionFindRequest_CATEGORY_UNKNOWN { + if req.Category != transaction.Category_CATEGORY_UNKNOWN { tx = tx.Where("category = ?", int32(req.Category)) } if req.UserID != 0 { @@ -189,11 +189,11 @@ func (a *srv) Find(ctx context.Context, req *transaction.TransactionFindRequest, rsp.Transactions = append(rsp.Transactions, &transaction.TransactionMsg{ TransactionID: v.ID, InfoID: v.InfoID, - Category: transaction.TransactionMsg_Category(v.Category), + Category: transaction.Category(utils.EnumConvert(v.Category, transaction.Category_name)), FromUserID: v.FromUserID, ToUserID: v.ToUserID, CreateTime: v.CreateTime.Unix(), - Status: transaction.TransStatus(v.Status), + Status: transaction.TransStatus(utils.EnumConvert(v.Status, transaction.TransStatus_name)), }) } rsp.Status = transaction.TransactionFindResponse_SUCCESS diff --git a/backend/srv/transaction/proto/transaction.pb.go b/backend/srv/transaction/proto/transaction.pb.go index 876f62a..a21b0b4 100644 --- a/backend/srv/transaction/proto/transaction.pb.go +++ b/backend/srv/transaction/proto/transaction.pb.go @@ -60,32 +60,32 @@ func (TransStatus) EnumDescriptor() ([]byte, []int) { return fileDescriptor_2cc4e03d2c28c490, []int{0} } -type TransactionCreateRequest_Category int32 +type Category int32 const ( - TransactionCreateRequest_UNKNOWN TransactionCreateRequest_Category = 0 - TransactionCreateRequest_SELL TransactionCreateRequest_Category = 1 - TransactionCreateRequest_BUY TransactionCreateRequest_Category = 2 + Category_CATEGORY_UNKNOWN Category = 0 + Category_SELL Category = 1 + Category_BUY Category = 2 ) -var TransactionCreateRequest_Category_name = map[int32]string{ - 0: "UNKNOWN", +var Category_name = map[int32]string{ + 0: "CATEGORY_UNKNOWN", 1: "SELL", 2: "BUY", } -var TransactionCreateRequest_Category_value = map[string]int32{ - "UNKNOWN": 0, - "SELL": 1, - "BUY": 2, +var Category_value = map[string]int32{ + "CATEGORY_UNKNOWN": 0, + "SELL": 1, + "BUY": 2, } -func (x TransactionCreateRequest_Category) String() string { - return proto.EnumName(TransactionCreateRequest_Category_name, int32(x)) +func (x Category) String() string { + return proto.EnumName(Category_name, int32(x)) } -func (TransactionCreateRequest_Category) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_2cc4e03d2c28c490, []int{0, 0} +func (Category) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_2cc4e03d2c28c490, []int{1} } type TransactionCreateResponse_Status int32 @@ -150,62 +150,6 @@ func (TransactionUpdateResponse_Status) EnumDescriptor() ([]byte, []int) { return fileDescriptor_2cc4e03d2c28c490, []int{3, 0} } -type TransactionMsg_Category int32 - -const ( - TransactionMsg_CATEGORY_UNKNOWN TransactionMsg_Category = 0 - TransactionMsg_SELL TransactionMsg_Category = 1 - TransactionMsg_BUY TransactionMsg_Category = 2 -) - -var TransactionMsg_Category_name = map[int32]string{ - 0: "CATEGORY_UNKNOWN", - 1: "SELL", - 2: "BUY", -} - -var TransactionMsg_Category_value = map[string]int32{ - "CATEGORY_UNKNOWN": 0, - "SELL": 1, - "BUY": 2, -} - -func (x TransactionMsg_Category) String() string { - return proto.EnumName(TransactionMsg_Category_name, int32(x)) -} - -func (TransactionMsg_Category) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_2cc4e03d2c28c490, []int{4, 0} -} - -type TransactionFindRequest_Category int32 - -const ( - TransactionFindRequest_CATEGORY_UNKNOWN TransactionFindRequest_Category = 0 - TransactionFindRequest_SELL TransactionFindRequest_Category = 1 - TransactionFindRequest_BUY TransactionFindRequest_Category = 2 -) - -var TransactionFindRequest_Category_name = map[int32]string{ - 0: "CATEGORY_UNKNOWN", - 1: "SELL", - 2: "BUY", -} - -var TransactionFindRequest_Category_value = map[string]int32{ - "CATEGORY_UNKNOWN": 0, - "SELL": 1, - "BUY": 2, -} - -func (x TransactionFindRequest_Category) String() string { - return proto.EnumName(TransactionFindRequest_Category_name, int32(x)) -} - -func (TransactionFindRequest_Category) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_2cc4e03d2c28c490, []int{5, 0} -} - type TransactionFindResponse_Status int32 const ( @@ -238,12 +182,12 @@ func (TransactionFindResponse_Status) EnumDescriptor() ([]byte, []int) { } type TransactionCreateRequest struct { - InfoID int32 `protobuf:"varint,1,opt,name=infoID,proto3" json:"infoID,omitempty"` - Category TransactionCreateRequest_Category `protobuf:"varint,2,opt,name=category,proto3,enum=TransactionCreateRequest_Category" json:"category,omitempty"` - FromUserID int32 `protobuf:"varint,3,opt,name=fromUserID,proto3" json:"fromUserID,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + InfoID int32 `protobuf:"varint,1,opt,name=infoID,proto3" json:"infoID,omitempty"` + Category Category `protobuf:"varint,2,opt,name=category,proto3,enum=Category" json:"category,omitempty"` + FromUserID int32 `protobuf:"varint,3,opt,name=fromUserID,proto3" json:"fromUserID,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *TransactionCreateRequest) Reset() { *m = TransactionCreateRequest{} } @@ -278,11 +222,11 @@ func (m *TransactionCreateRequest) GetInfoID() int32 { return 0 } -func (m *TransactionCreateRequest) GetCategory() TransactionCreateRequest_Category { +func (m *TransactionCreateRequest) GetCategory() Category { if m != nil { return m.Category } - return TransactionCreateRequest_UNKNOWN + return Category_CATEGORY_UNKNOWN } func (m *TransactionCreateRequest) GetFromUserID() int32 { @@ -426,16 +370,16 @@ func (m *TransactionUpdateResponse) GetStatus() TransactionUpdateResponse_Status } type TransactionMsg struct { - TransactionID int32 `protobuf:"varint,1,opt,name=transactionID,proto3" json:"transactionID,omitempty"` - InfoID int32 `protobuf:"varint,2,opt,name=infoID,proto3" json:"infoID,omitempty"` - Category TransactionMsg_Category `protobuf:"varint,3,opt,name=category,proto3,enum=TransactionMsg_Category" json:"category,omitempty"` - FromUserID int32 `protobuf:"varint,4,opt,name=fromUserID,proto3" json:"fromUserID,omitempty"` - ToUserID int32 `protobuf:"varint,5,opt,name=toUserID,proto3" json:"toUserID,omitempty"` - CreateTime int64 `protobuf:"varint,6,opt,name=createTime,proto3" json:"createTime,omitempty"` - Status TransStatus `protobuf:"varint,7,opt,name=status,proto3,enum=TransStatus" json:"status,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + TransactionID int32 `protobuf:"varint,1,opt,name=transactionID,proto3" json:"transactionID,omitempty"` + InfoID int32 `protobuf:"varint,2,opt,name=infoID,proto3" json:"infoID,omitempty"` + Category Category `protobuf:"varint,3,opt,name=category,proto3,enum=Category" json:"category,omitempty"` + FromUserID int32 `protobuf:"varint,4,opt,name=fromUserID,proto3" json:"fromUserID,omitempty"` + ToUserID int32 `protobuf:"varint,5,opt,name=toUserID,proto3" json:"toUserID,omitempty"` + CreateTime int64 `protobuf:"varint,6,opt,name=createTime,proto3" json:"createTime,omitempty"` + Status TransStatus `protobuf:"varint,7,opt,name=status,proto3,enum=TransStatus" json:"status,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *TransactionMsg) Reset() { *m = TransactionMsg{} } @@ -477,11 +421,11 @@ func (m *TransactionMsg) GetInfoID() int32 { return 0 } -func (m *TransactionMsg) GetCategory() TransactionMsg_Category { +func (m *TransactionMsg) GetCategory() Category { if m != nil { return m.Category } - return TransactionMsg_CATEGORY_UNKNOWN + return Category_CATEGORY_UNKNOWN } func (m *TransactionMsg) GetFromUserID() int32 { @@ -513,17 +457,17 @@ func (m *TransactionMsg) GetStatus() TransStatus { } type TransactionFindRequest struct { - InfoID int32 `protobuf:"varint,1,opt,name=infoID,proto3" json:"infoID,omitempty"` - Category TransactionFindRequest_Category `protobuf:"varint,2,opt,name=category,proto3,enum=TransactionFindRequest_Category" json:"category,omitempty"` - UserID int32 `protobuf:"varint,3,opt,name=userID,proto3" json:"userID,omitempty"` - LowCreateTime int64 `protobuf:"varint,4,opt,name=lowCreateTime,proto3" json:"lowCreateTime,omitempty"` - HighCreateTime int64 `protobuf:"varint,5,opt,name=highCreateTime,proto3" json:"highCreateTime,omitempty"` - Status TransStatus `protobuf:"varint,6,opt,name=status,proto3,enum=TransStatus" json:"status,omitempty"` - Limit uint32 `protobuf:"varint,7,opt,name=limit,proto3" json:"limit,omitempty"` - Offset uint32 `protobuf:"varint,8,opt,name=offset,proto3" json:"offset,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + InfoID int32 `protobuf:"varint,1,opt,name=infoID,proto3" json:"infoID,omitempty"` + Category Category `protobuf:"varint,2,opt,name=category,proto3,enum=Category" json:"category,omitempty"` + UserID int32 `protobuf:"varint,3,opt,name=userID,proto3" json:"userID,omitempty"` + LowCreateTime int64 `protobuf:"varint,4,opt,name=lowCreateTime,proto3" json:"lowCreateTime,omitempty"` + HighCreateTime int64 `protobuf:"varint,5,opt,name=highCreateTime,proto3" json:"highCreateTime,omitempty"` + Status TransStatus `protobuf:"varint,6,opt,name=status,proto3,enum=TransStatus" json:"status,omitempty"` + Limit uint32 `protobuf:"varint,7,opt,name=limit,proto3" json:"limit,omitempty"` + Offset uint32 `protobuf:"varint,8,opt,name=offset,proto3" json:"offset,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *TransactionFindRequest) Reset() { *m = TransactionFindRequest{} } @@ -558,11 +502,11 @@ func (m *TransactionFindRequest) GetInfoID() int32 { return 0 } -func (m *TransactionFindRequest) GetCategory() TransactionFindRequest_Category { +func (m *TransactionFindRequest) GetCategory() Category { if m != nil { return m.Category } - return TransactionFindRequest_CATEGORY_UNKNOWN + return Category_CATEGORY_UNKNOWN } func (m *TransactionFindRequest) GetUserID() int32 { @@ -656,11 +600,9 @@ func (m *TransactionFindResponse) GetTransactions() []*TransactionMsg { func init() { proto.RegisterEnum("TransStatus", TransStatus_name, TransStatus_value) - proto.RegisterEnum("TransactionCreateRequest_Category", TransactionCreateRequest_Category_name, TransactionCreateRequest_Category_value) + proto.RegisterEnum("Category", Category_name, Category_value) proto.RegisterEnum("TransactionCreateResponse_Status", TransactionCreateResponse_Status_name, TransactionCreateResponse_Status_value) proto.RegisterEnum("TransactionUpdateResponse_Status", TransactionUpdateResponse_Status_name, TransactionUpdateResponse_Status_value) - proto.RegisterEnum("TransactionMsg_Category", TransactionMsg_Category_name, TransactionMsg_Category_value) - proto.RegisterEnum("TransactionFindRequest_Category", TransactionFindRequest_Category_name, TransactionFindRequest_Category_value) proto.RegisterEnum("TransactionFindResponse_Status", TransactionFindResponse_Status_name, TransactionFindResponse_Status_value) proto.RegisterType((*TransactionCreateRequest)(nil), "TransactionCreateRequest") proto.RegisterType((*TransactionCreateResponse)(nil), "TransactionCreateResponse") @@ -674,46 +616,44 @@ func init() { func init() { proto.RegisterFile("transaction.proto", fileDescriptor_2cc4e03d2c28c490) } var fileDescriptor_2cc4e03d2c28c490 = []byte{ - // 650 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0x41, 0x4f, 0xd4, 0x50, - 0x10, 0xf6, 0xb5, 0xdb, 0x52, 0x07, 0x76, 0xad, 0x2f, 0x04, 0xca, 0x1e, 0x74, 0x6d, 0x88, 0xd9, - 0x70, 0xe8, 0x61, 0x31, 0x31, 0x26, 0x46, 0x53, 0xdb, 0x42, 0x2a, 0x4b, 0x4b, 0xda, 0xad, 0x86, - 0x13, 0x59, 0xa1, 0x0b, 0x4d, 0x60, 0x8b, 0x6d, 0x89, 0xf1, 0x07, 0xf9, 0x2b, 0x4c, 0xfc, 0x01, - 0x7a, 0xf7, 0xe6, 0x6f, 0xd1, 0xbc, 0xd7, 0x02, 0xef, 0x75, 0xb7, 0x40, 0x0c, 0x7b, 0x9b, 0xd9, - 0x6f, 0x66, 0xde, 0x7c, 0x33, 0xdf, 0x14, 0x1e, 0x17, 0xd9, 0x78, 0x9a, 0x8f, 0x0f, 0x8b, 0x24, - 0x9d, 0x1a, 0xe7, 0x59, 0x5a, 0xa4, 0xfa, 0x0f, 0x04, 0xda, 0xe8, 0xda, 0x6b, 0x65, 0xf1, 0xb8, - 0x88, 0x83, 0xf8, 0xf3, 0x45, 0x9c, 0x17, 0x78, 0x05, 0xe4, 0x64, 0x3a, 0x49, 0x5d, 0x5b, 0x43, - 0x3d, 0xd4, 0x97, 0x82, 0xca, 0xc2, 0x6f, 0x40, 0x39, 0x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6, - 0xb3, 0x76, 0x59, 0xe8, 0x2e, 0xac, 0xf1, 0xd8, 0x1a, 0x6b, 0xf7, 0xcd, 0xc7, 0x77, 0x01, 0x3a, - 0x4c, 0xed, 0xdd, 0xfc, 0xf8, 0x8e, 0x34, 0x5c, 0xaf, 0xae, 0xc0, 0xad, 0xee, 0x0b, 0x66, 0x75, - 0x45, 0xda, 0x9c, 0x66, 0xf0, 0x05, 0x6e, 0x5f, 0xd8, 0x56, 0x7d, 0x61, 0x71, 0x17, 0x94, 0x22, - 0xad, 0xfe, 0x95, 0xe8, 0xbf, 0x57, 0x36, 0x89, 0x3d, 0xa4, 0x8b, 0x36, 0x4a, 0xce, 0x62, 0x4d, - 0xee, 0xa1, 0xbe, 0x18, 0x30, 0x1e, 0x66, 0x60, 0x0b, 0x37, 0x0c, 0x6c, 0x93, 0x91, 0xc4, 0x32, - 0xa8, 0x96, 0x39, 0x72, 0xb6, 0xfd, 0x60, 0xff, 0xe0, 0x46, 0x6d, 0xfc, 0x11, 0x60, 0x85, 0x69, - 0x6e, 0x2b, 0x99, 0x1e, 0xdd, 0x26, 0xed, 0xd7, 0x33, 0xd2, 0xee, 0x19, 0xf3, 0x53, 0xcc, 0xe3, - 0x69, 0x05, 0xe4, 0x0b, 0x56, 0xd4, 0x95, 0x45, 0x66, 0x76, 0x9a, 0x7e, 0xb1, 0xae, 0x69, 0x68, - 0x51, 0x1a, 0x78, 0x27, 0x7e, 0x0e, 0x9d, 0x93, 0xe4, 0xf8, 0x84, 0x81, 0x49, 0x14, 0x56, 0xf3, - 0x32, 0x8c, 0xc9, 0xcd, 0x8c, 0xe1, 0x65, 0x90, 0x4e, 0x93, 0xb3, 0xa4, 0xa0, 0xb4, 0xb6, 0x83, - 0xd2, 0x20, 0x2f, 0x4c, 0x27, 0x93, 0x3c, 0x2e, 0x34, 0x85, 0xba, 0x2b, 0xeb, 0xff, 0xf8, 0xfd, - 0x8d, 0x60, 0x75, 0x86, 0x9c, 0x4a, 0x43, 0x2f, 0x6b, 0x1a, 0x7a, 0x6a, 0x34, 0x20, 0xeb, 0x77, - 0x67, 0x13, 0x96, 0x98, 0x55, 0x26, 0x32, 0x16, 0xfb, 0x8b, 0x83, 0x47, 0xb5, 0x2d, 0x0d, 0x38, - 0xd0, 0x3d, 0xcb, 0x6e, 0x23, 0x86, 0x45, 0x86, 0x52, 0x3e, 0x27, 0x80, 0x6c, 0x86, 0x3b, 0xae, - 0xb7, 0xad, 0x22, 0xbc, 0x04, 0x8a, 0x69, 0x59, 0xce, 0xde, 0xc8, 0xb1, 0x55, 0x81, 0x58, 0x81, - 0xf3, 0xde, 0xb1, 0x88, 0x25, 0x12, 0x9c, 0x35, 0xf4, 0x43, 0xc7, 0x56, 0x5b, 0x24, 0xc1, 0x9e, - 0xe3, 0xd9, 0x24, 0x48, 0x22, 0x44, 0xda, 0xbe, 0xe7, 0xa8, 0xf2, 0xe0, 0x27, 0xaa, 0xea, 0x94, - 0x6d, 0xe0, 0xb7, 0x20, 0x97, 0x63, 0xc6, 0x6b, 0x8d, 0xdf, 0x93, 0x6e, 0xb7, 0xf9, 0x84, 0x93, - 0x04, 0xe5, 0x79, 0xe2, 0x13, 0x70, 0x77, 0x94, 0x4f, 0x30, 0x73, 0xf9, 0x5a, 0x64, 0x36, 0x78, - 0xb5, 0x61, 0xe9, 0xbb, 0x5a, 0xd3, 0x18, 0x3f, 0xc9, 0xf4, 0x83, 0xba, 0xf9, 0x2f, 0x00, 0x00, - 0xff, 0xff, 0x1c, 0x25, 0x89, 0x45, 0x65, 0x07, 0x00, 0x00, + // 622 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0xcd, 0x6e, 0x9b, 0x5c, + 0x10, 0xfd, 0x2e, 0x7f, 0x21, 0x93, 0xd8, 0x1f, 0xbd, 0x8a, 0x12, 0xe2, 0x45, 0x9b, 0xa2, 0xb4, + 0xb2, 0xb2, 0x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, 0x1b, 0x80, 0x39, 0x76, 0x6c, 0x80, 0xa5, 0xf3, 0x24, 0x90, + 0x81, 0xe2, 0x03, 0x7d, 0xf5, 0x82, 0xb4, 0xd4, 0xba, 0xd9, 0x7f, 0x96, 0x8a, 0xff, 0xab, 0xd3, + 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x0a, 0xee, 0xc9, 0xb5, 0xc4, 0x06, 0x00, 0x00, } diff --git a/backend/srv/transaction/proto/transaction.proto b/backend/srv/transaction/proto/transaction.proto index 736d1a9..8c03a0e 100644 --- a/backend/srv/transaction/proto/transaction.proto +++ b/backend/srv/transaction/proto/transaction.proto @@ -16,12 +16,13 @@ enum TransStatus { DONE = 6; } +enum Category { + CATEGORY_UNKNOWN = 0; + SELL = 1; + BUY = 2; +} + message TransactionCreateRequest { - enum Category { - UNKNOWN = 0; - SELL = 1; - BUY = 2; - } int32 infoID = 1; Category category = 2; int32 fromUserID = 3; @@ -54,11 +55,6 @@ message TransactionUpdateResponse { } message TransactionMsg { - enum Category { - CATEGORY_UNKNOWN = 0; - SELL = 1; - BUY = 2; - } int32 transactionID = 1; int32 infoID = 2; Category category = 3; @@ -69,11 +65,6 @@ message TransactionMsg { } message TransactionFindRequest { - enum Category { - CATEGORY_UNKNOWN = 0; - SELL = 1; - BUY = 2; - } int32 infoID = 1; Category category = 2; int32 userID = 3; diff --git a/backend/srv/user/main.go b/backend/srv/user/main.go index 4ff92b5..21d4983 100644 --- a/backend/srv/user/main.go +++ b/backend/srv/user/main.go @@ -188,8 +188,8 @@ func parseUser(s *db.User, d *user.UserInfo) { d.Telephone = s.Telephone d.StudentID = s.StudentID d.StudentName = s.StudentName - d.Status = user.UserInfo_Status(s.Status) - d.Role = user.UserInfo_Role(s.Role) + d.Status = user.UserInfo_Status(utils.EnumConvert(s.Status, user.UserInfo_Status_name)) + d.Role = user.UserInfo_Role(utils.EnumConvert(s.Role, user.UserInfo_Role_name)) } func main() { diff --git a/backend/srv/user/main_test.go b/backend/srv/user/main_test.go index a6ded19..6948a3e 100644 --- a/backend/srv/user/main_test.go +++ b/backend/srv/user/main_test.go @@ -56,16 +56,16 @@ func TestUserQuery(t *testing.T) { tf(0, "") err := db.Ormer.Create(&db.User{ ID: 1000, - UserName: "jiang", - AvatarID: "5d23ea2c32311335f935cd14", + UserName: "test", + AvatarID: "012345678901234567890123", Telephone: "12345678901", - StudentID: "1234", + StudentID: "10000", StudentName: "jiang", }).Error So(err, ShouldBeNil) req.UserID = 1000 - tf(1000, "1234") + tf(1000, "10000") defer func() { So(db.Ormer.Delete(&db.User{ID: 1000}).Error, ShouldBeNil) }() req.UserID = 1001 @@ -76,52 +76,51 @@ func TestUserQuery(t *testing.T) { func TestUserUpdate(t *testing.T) { var req user.UserInfo - tf := func(status user.UserUpdateResponse_Status, uid int, uname string, telephone string) { + tf := func(status user.UserUpdateResponse_Status, name string, telephone string) { var s srv var rsp user.UserUpdateResponse So(s.Update(context.TODO(), &req, &rsp), ShouldBeNil) So(rsp.Status, ShouldEqual, status) info := db.User{ - ID: 2000, + ID: 1100, } err := db.Ormer.First(&info).Error So(err, ShouldBeNil) - So(info.ID, ShouldEqual, uid) - So(info.UserName, ShouldEqual, uname) + So(info.UserName, ShouldEqual, name) So(info.Telephone, ShouldEqual, telephone) } Convey("Test User Update", t, func() { err := db.Ormer.Create(&db.User{ - ID: 2000, - UserName: "test1", - AvatarID: "1234", + ID: 1100, + UserName: "test", + AvatarID: "012345678901234567890123", Telephone: "12345678901", - StudentID: "1234", + StudentID: "11000", StudentName: "jiang", Status: int32(user.UserInfo_NORMAL), Role: int32(user.UserInfo_USER), }).Error So(err, ShouldBeNil) - defer func() { So(db.Ormer.Delete(&db.User{ID: 2000}).Error, ShouldBeNil) }() + defer func() { So(db.Ormer.Delete(&db.User{ID: 1100}).Error, ShouldBeNil) }() - tf(user.UserUpdateResponse_INVALID_PARAM, 2000, "test1", "12345678901") + tf(user.UserUpdateResponse_INVALID_PARAM, "test", "12345678901") - req.UserID = 3000 - tf(user.UserUpdateResponse_NOT_FOUND, 2000, "test1", "12345678901") + req.UserID = 1101 + tf(user.UserUpdateResponse_NOT_FOUND, "test", "12345678901") - req.UserID = 2000 - tf(user.UserUpdateResponse_SUCCESS, 2000, "test1", "12345678901") + req.UserID = 1100 + tf(user.UserUpdateResponse_SUCCESS, "test", "12345678901") - req.UserName = "test2" - tf(user.UserUpdateResponse_SUCCESS, 2000, "test2", "12345678901") + req.UserName = "test1" + tf(user.UserUpdateResponse_SUCCESS, "test1", "12345678901") req.Telephone = "56781234678" - tf(user.UserUpdateResponse_SUCCESS, 2000, "test2", "56781234678") + tf(user.UserUpdateResponse_SUCCESS, "test1", "56781234678") req.ClearEmpty = true req.Telephone = "" - tf(user.UserUpdateResponse_SUCCESS, 2000, "test2", "") + tf(user.UserUpdateResponse_SUCCESS, "test1", "") }) } @@ -137,40 +136,42 @@ func TestUserFind(t *testing.T) { } Convey("Test User Find", t, func() { err := db.Ormer.Create(&db.User{ - ID: 2500, + ID: 1200, UserName: "test1", - AvatarID: "123123", + AvatarID: "012345678901234567890123", Telephone: "12345678901", - StudentID: "1234", + StudentID: "12000", StudentName: "jiang", Status: 1, }).Error So(err, ShouldBeNil) + defer func() { + So(db.Ormer.Delete(&db.User{ID: 1200}).Error, ShouldBeNil) + }() - tf(1, 0, 2500, "1234") + tf(1, 0, 1200, "12000") err = db.Ormer.Create(&db.User{ - ID: 2501, + ID: 1201, UserName: "test2", - AvatarID: "123123", + AvatarID: "012345678901234567890123", Telephone: "12345678902", - StudentID: "12345", + StudentID: "12010", StudentName: "jiangzm", Status: 1, }).Error So(err, ShouldBeNil) defer func() { - So(db.Ormer.Delete(&db.User{ID: 2500}).Error, ShouldBeNil) - So(db.Ormer.Delete(&db.User{ID: 2501}).Error, ShouldBeNil) + So(db.Ormer.Delete(&db.User{ID: 1201}).Error, ShouldBeNil) }() - tf(2, 1, 2501, "12345") + tf(2, 1, 1201, "12010") req.Limit = 1 - tf(1, 0, 2500, "1234") + tf(1, 0, 1200, "12000") req.Offset = 1 - tf(1, 0, 2501, "12345") + tf(1, 0, 1201, "12010") }) } diff --git a/backend/srv/user/mock/mock.go b/backend/srv/user/mock/mock.go index 50abf21..fb3bd3e 100644 --- a/backend/srv/user/mock/mock.go +++ b/backend/srv/user/mock/mock.go @@ -4,6 +4,7 @@ import ( "context" "errors" user "jiaojiao/srv/user/proto" + "jiaojiao/utils" "github.com/micro/go-micro/client" ) @@ -13,34 +14,35 @@ type mockUserSrv struct{} // Create is user create mock func (a *mockUserSrv) Create(ctx context.Context, req *user.UserCreateRequest, opts ...client.CallOption) (*user.UserCreateResponse, error) { var rsp user.UserCreateResponse - if req.StudentID == "" || req.StudentName == "" { + if !utils.RequireParam(req.StudentID, req.StudentName) { rsp.Status = user.UserCreateResponse_INVALID_PARAM + return &rsp, nil + } + + if req.StudentID == "10000" { + rsp.Status = user.UserCreateResponse_SUCCESS + rsp.User = new(user.UserInfo) + rsp.User.UserID = 1000 + rsp.User.Status = user.UserInfo_NORMAL + rsp.User.Role = user.UserInfo_USER + } else if req.StudentID == "10001" { + rsp.Status = user.UserCreateResponse_SUCCESS + rsp.User = new(user.UserInfo) + rsp.User.UserID = 1001 + rsp.User.Status = user.UserInfo_NORMAL + rsp.User.Role = user.UserInfo_ADMIN + } else if req.StudentID == "20000" { + rsp.Status = user.UserCreateResponse_SUCCESS + rsp.User = new(user.UserInfo) + rsp.User.UserID = 2000 + rsp.User.Status = user.UserInfo_FROZEN + rsp.User.Role = user.UserInfo_USER + } else if req.StudentID == "30000" { + return nil, errors.New("") } else { - if req.StudentID == "1000" { - rsp.Status = user.UserCreateResponse_SUCCESS - rsp.User = new(user.UserInfo) - rsp.User.UserID = 1 - rsp.User.Status = user.UserInfo_NORMAL - rsp.User.Role = user.UserInfo_USER - } else if req.StudentID == "1001" { - rsp.Status = user.UserCreateResponse_SUCCESS - rsp.User = new(user.UserInfo) - rsp.User.UserID = 2 - rsp.User.Status = user.UserInfo_NORMAL - rsp.User.Role = user.UserInfo_ADMIN - } else if req.StudentID == "2000" { - return nil, errors.New("") - } else if req.StudentID == "3000" { - rsp.Status = user.UserCreateResponse_SUCCESS - rsp.User = new(user.UserInfo) - rsp.User.UserID = 3 - rsp.User.Status = user.UserInfo_FROZEN - rsp.User.Role = user.UserInfo_USER - } else { - rsp.Status = user.UserCreateResponse_USER_EXIST - rsp.User = new(user.UserInfo) - rsp.User.UserID = 1 - } + rsp.Status = user.UserCreateResponse_USER_EXIST + rsp.User = new(user.UserInfo) + rsp.User.UserID = 1000 } return &rsp, nil } @@ -48,16 +50,16 @@ func (a *mockUserSrv) Create(ctx context.Context, req *user.UserCreateRequest, o // Query is user query mock func (a *mockUserSrv) Query(ctx context.Context, req *user.UserQueryRequest, opts ...client.CallOption) (*user.UserInfo, error) { var rsp user.UserInfo - if req.UserID != 0 { + if utils.RequireParam(req.UserID) { if req.UserID == 1000 { rsp.UserID = 1000 rsp.UserName = "test" - rsp.AvatarID = "5d23ea2c32311335f935cd14" + rsp.AvatarID = "012345678901234567890123" rsp.Telephone = "12345678901" - rsp.StudentID = "1000" + rsp.StudentID = "10000" rsp.StudentName = "jiang" - rsp.Status = 1 - } else if req.UserID == 2000 { + rsp.Status = user.UserInfo_NORMAL + } else if req.UserID == 3000 { return nil, errors.New("") } } @@ -69,29 +71,29 @@ func (a *mockUserSrv) Find(ctx context.Context, req *user.UserFindRequest, opts user1 := user.UserInfo{ UserID: 1000, UserName: "test1", - AvatarID: "5d23ea2c32311335f935cd14", - Telephone: "12345224232", - StudentID: "1", - StudentName: "Xiao Ming", - Status: 1, + AvatarID: "012345678901234567890123", + Telephone: "12345678901", + StudentID: "10000", + StudentName: "user1", + Status: user.UserInfo_NORMAL, } user2 := user.UserInfo{ UserID: 1001, UserName: "test2", - AvatarID: "jksfa0980923jkjoifu92323", - Telephone: "67307269876", - StudentID: "2", - StudentName: "Xiao Huang", - Status: 1, + AvatarID: "012345678901234567890123", + Telephone: "12345678901", + StudentID: "10001", + StudentName: "user2", + Status: user.UserInfo_NORMAL, } user3 := user.UserInfo{ UserID: 1002, - UserName: "test2", - AvatarID: "yuwry981hkjbgmxnlaud9u34352", - Telephone: "16539896792", - StudentID: "3", - StudentName: "Xiao Bai", - Status: 1, + UserName: "test3", + AvatarID: "012345678901234567890123", + Telephone: "12345678901", + StudentID: "10002", + StudentName: "user3", + Status: user.UserInfo_NORMAL, } var rsp user.UserFindResponse @@ -116,7 +118,7 @@ func (a *mockUserSrv) Find(ctx context.Context, req *user.UserFindRequest, opts rsp.User = append(rsp.User, &user3) } } - } else if req.UserName == "down" { + } else if req.UserName == "error" { return nil, errors.New("") } return &rsp, nil @@ -125,16 +127,17 @@ func (a *mockUserSrv) Find(ctx context.Context, req *user.UserFindRequest, opts // Update is user update mock func (a *mockUserSrv) Update(ctx context.Context, req *user.UserInfo, opts ...client.CallOption) (*user.UserUpdateResponse, error) { var rsp user.UserUpdateResponse - if req.UserID == 0 { + if !utils.RequireParam(req.UserID) { rsp.Status = user.UserUpdateResponse_INVALID_PARAM + return &rsp, nil + } + + if req.UserID == 1000 { + rsp.Status = user.UserUpdateResponse_SUCCESS + } else if req.UserID == 3000 { + return &rsp, errors.New("") } else { - if req.UserID == 1000 { - rsp.Status = user.UserUpdateResponse_SUCCESS - } else if req.UserID == 2000 { - return &rsp, errors.New("") - } else { - rsp.Status = user.UserUpdateResponse_NOT_FOUND - } + rsp.Status = user.UserUpdateResponse_NOT_FOUND } return &rsp, nil } diff --git a/backend/utils/function.go b/backend/utils/function.go index d2e2922..98ece0c 100644 --- a/backend/utils/function.go +++ b/backend/utils/function.go @@ -101,3 +101,24 @@ func GetQueryFile(c *gin.Context, name string, maxsize int64) ([]byte, int, erro } return nil, 500, err } + +// EnumConvert convert int32 to enum +func EnumConvert(v int32, n map[int32]string) int32 { + if n[v] != "" { + return v + } + return 0 +} + +// CheckFileInTest check if file valid +func CheckFile(file []byte, f ...func(buf []byte) bool) bool { + if CheckInTest() { + return string(file) == "valid_file" + } + for _, v := range f { + if !v(file) { + return false + } + } + return true +} diff --git a/backend/utils/testtool.go b/backend/utils/testtool.go index a3fcc63..e762d11 100644 --- a/backend/utils/testtool.go +++ b/backend/utils/testtool.go @@ -25,7 +25,9 @@ func StartTestServer(f func() *gin.Engine, m string, p string, b io.Reader, setter(req) } router.ServeHTTP(w, req) - defer req.Body.Close() + if req.Body != nil { + req.Body.Close() + } return w } From ef843ae91c4e1374454bb61502b350d4eee4a25f Mon Sep 17 00:00:00 2001 From: MXWXZ Date: Thu, 1 Aug 2019 16:28:45 +0800 Subject: [PATCH 11/12] commit fix --- backend/utils/function.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/utils/function.go b/backend/utils/function.go index 98ece0c..73305ec 100644 --- a/backend/utils/function.go +++ b/backend/utils/function.go @@ -110,7 +110,7 @@ func EnumConvert(v int32, n map[int32]string) int32 { return 0 } -// CheckFileInTest check if file valid +// CheckFile check if file valid func CheckFile(file []byte, f ...func(buf []byte) bool) bool { if CheckInTest() { return string(file) == "valid_file" From 5d88db7055836e7ae2915b6d4f9f40cb6d3ed31f Mon Sep 17 00:00:00 2001 From: MXWXZ Date: Thu, 1 Aug 2019 16:46:10 +0800 Subject: [PATCH 12/12] 0.2.2 --- backend/CHANGELOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/backend/CHANGELOG.md b/backend/CHANGELOG.md index a7013cb..187825f 100644 --- a/backend/CHANGELOG.md +++ b/backend/CHANGELOG.md @@ -1,4 +1,18 @@ # 后端API更新日志 +## v0.2.2 2019-08-01 +### 禁用 +1. `DELETE /content` 删除单独content file暂不可用 + +### 新增 +1. tag相关功能已可以使用 + +### API修改 +1. `PUT /content` 参数均为必选,将删除content file功能移至 `DELETE` +2. `DELETE /content` 允许删除content file(暂不可用) + +### BUG修复 +1. 字段值检查已添加,非法数值会被视为0 + ## v0.2.1 2019-07-30 ### 修复 1. content相关API已可使用