Skip to content

Commit

Permalink
Develop (#205)
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
MXWXZ authored Sep 9, 2019
2 parents aa2bdc2 + 62d88b5 commit ef24b59
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 10 deletions.
7 changes: 7 additions & 0 deletions backend/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# 后端API更新日志
## v0.5.0
### 新增
1. 推送模块上线

### BUG修复
1. 修复message被错误标记为已读的问题

## v0.4.1
### BUG修复
1. `GET /tag` 权限错误修复
Expand Down
33 changes: 33 additions & 0 deletions backend/api/buyinfo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import (
"context"
"jiaojiao/srv/buyinfo/mock"
buyinfo "jiaojiao/srv/buyinfo/proto"
mockmsg "jiaojiao/srv/message/mock"
message "jiaojiao/srv/message/proto"
mocksell "jiaojiao/srv/sellinfo/mock"
sellinfo "jiaojiao/srv/sellinfo/proto"
"jiaojiao/utils"
"strconv"

"github.com/micro/go-micro/client"

Expand Down Expand Up @@ -174,6 +179,34 @@ func addBuyInfo(c *gin.Context) {
c.JSON(500, err)
return
}

// Just for check
if len(p.Tags) >= 1 && len(p.Tags[0]) > 6 {
srv2 := utils.CallMicroService("sellInfo", func(name string, c client.Client) interface{} { return sellinfo.NewSellInfoService(name, c) },
func() interface{} { return mocksell.NewSellInfoService() }).(sellinfo.SellInfoService)
rsp2, err := srv2.Find(context.TODO(), &sellinfo.SellInfoFindRequest{
GoodName: p.Tags[0][2:5],
Limit: 1,
})
if utils.LogContinue(err, utils.Error) {
c.JSON(500, err)
return
}
if rsp2.SellInfo != nil {
srv3 := utils.CallMicroService("message", func(name string, c client.Client) interface{} { return message.NewMessageService(name, c) },
func() interface{} { return mockmsg.NewMessageService() }).(message.MessageService)
_, err := srv3.Create(context.TODO(), &message.MessageCreateRequest{
FromUser: 1,
ToUser: p.UserID,
Type: 1,
Msg: []byte(strconv.Itoa(int(rsp2.SellInfo[0].SellInfoID))),
})
if utils.LogContinue(err, utils.Error) {
c.JSON(500, err)
return
}
}
}
c.JSON(200, rsp)
} else {
c.AbortWithStatus(400)
Expand Down
34 changes: 34 additions & 0 deletions backend/api/sellinfo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ package main

import (
"context"
mockbuy "jiaojiao/srv/buyinfo/mock"
buyinfo "jiaojiao/srv/buyinfo/proto"
mockmsg "jiaojiao/srv/message/mock"
message "jiaojiao/srv/message/proto"
"jiaojiao/srv/sellinfo/mock"
sellinfo "jiaojiao/srv/sellinfo/proto"
"jiaojiao/utils"
"strconv"

"github.com/micro/go-micro/client"

Expand Down Expand Up @@ -174,6 +179,35 @@ func addSellInfo(c *gin.Context) {
c.JSON(500, err)
return
}

// Just for check
if len(p.Tags) >= 1 && len(p.Tags[0]) > 6 {
srv2 := utils.CallMicroService("buyInfo", func(name string, c client.Client) interface{} { return buyinfo.NewBuyInfoService(name, c) },
func() interface{} { return mockbuy.NewBuyInfoService() }).(buyinfo.BuyInfoService)
rsp2, err := srv2.Find(context.TODO(), &buyinfo.BuyInfoFindRequest{
GoodName: p.Tags[0][2:5],
Limit: 1,
})
if utils.LogContinue(err, utils.Error) {
c.JSON(500, err)
return
}
if rsp2.BuyInfo != nil {
srv3 := utils.CallMicroService("message", func(name string, c client.Client) interface{} { return message.NewMessageService(name, c) },
func() interface{} { return mockmsg.NewMessageService() }).(message.MessageService)
_, err := srv3.Create(context.TODO(), &message.MessageCreateRequest{
FromUser: 1,
ToUser: p.UserID,
Type: 1,
Msg: []byte(strconv.Itoa(int(rsp2.BuyInfo[0].BuyInfoID))),
})
if utils.LogContinue(err, utils.Error) {
c.JSON(500, err)
return
}
}
}

c.JSON(200, rsp)
} else {
c.AbortWithStatus(400)
Expand Down
8 changes: 2 additions & 6 deletions backend/api/tag/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ package main

import (
"testing"

. "github.com/smartystreets/goconvey/convey"
)

func Test_(t *testing.T) {
Convey("tag test", t, func() {

})
func Test(t *testing.T) {
// TODO
}

func TestMain(m *testing.M) {
Expand Down
2 changes: 1 addition & 1 deletion backend/doc/api_project.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ define({
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2019-09-09T09:26:14.124Z",
"time": "2019-09-09T11:38:15.736Z",
"url": "http://apidocjs.com",
"version": "0.17.7"
}
Expand Down
2 changes: 1 addition & 1 deletion backend/doc/api_project.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2019-09-09T09:26:14.124Z",
"time": "2019-09-09T11:38:15.736Z",
"url": "http://apidocjs.com",
"version": "0.17.7"
}
Expand Down
4 changes: 2 additions & 2 deletions backend/srv/message/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func (a *srv) Find(ctx context.Context, req *message.MessageFindRequest, rsp *me
"as": "item",
"cond": bson.M{
"$and": bson.A{
bson.M{"$eq": bson.A{"$$item.forward", req.FromUser != rsp.FromUser}},
bson.M{"$eq": bson.A{"$$item.forward", req.FromUser == rsp.FromUser}},
bson.M{"$eq": bson.A{"$$item.unread", true}},
},
},
Expand All @@ -287,7 +287,7 @@ func (a *srv) Find(ctx context.Context, req *message.MessageFindRequest, rsp *me
_, err = collection.UpdateMany(ctx, bson.M{
"fromUser": rsp.FromUser,
"toUser": rsp.ToUser,
"infos.forward": req.FromUser != rsp.FromUser,
"infos.forward": req.FromUser == rsp.FromUser,
"infos.unread": true,
}, bson.M{
"$set": bson.M{
Expand Down

0 comments on commit ef24b59

Please sign in to comment.