Skip to content

Commit

Permalink
Bugfix/unit test (#193)
Browse files Browse the repository at this point in the history
Bugfix/unit test
  • Loading branch information
MXWXZ authored Sep 8, 2019
2 parents 0580787 + 3e7d361 commit 9e28a13
Show file tree
Hide file tree
Showing 30 changed files with 1,010 additions and 2,451 deletions.
41 changes: 0 additions & 41 deletions backend/.realize.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -305,47 +305,6 @@ schema:
type: after
path: ../../
output: true
- name: api-transaction
path: api/transaction
args:
- --registry=consul
commands:
run:
status: true
watcher:
extensions:
- go
paths:
- /
- ../../utils
scripts:
- command: make doc
type: after
path: ../../
output: true
- name: srv-transaction
path: srv/transaction
args:
- --registry=consul
commands:
run:
status: true
watcher:
extensions:
- proto
- go
paths:
- /
- ../../utils
scripts:
- command: make proto SRV=transaction
type: before
path: ../../
output: true
- command: make doc
type: after
path: ../../
output: true
- name: api-message
path: api/message
args:
Expand Down
18 changes: 18 additions & 0 deletions backend/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
# 后端API更新日志
## v0.3.3 2019-09-09
### 移除
1. `transaction` 模块被完全移除

### 新增
1. `POST "/buyInfo/:buyInfoID"` 修改状态
2. `POST "/sellInfo/:sellInfoID"` 修改状态

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

## v0.3.2 2019-09-08
### 新增
1. `GET /message/userID` 增加获取旧消息的功能

### BUG修复
1. `GET /message` 修复`offset``limit`失效问题

## v0.3.1 2019-09-06
### BUG修复
1. 修复文件上传相关检测
Expand Down
63 changes: 63 additions & 0 deletions backend/api/buyinfo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
func setupRouter() *gin.Engine {
router, rg := utils.CreateAPIGroup()
rg.GET("/buyInfo/:buyInfoID", getBuyInfo)
rg.POST("/buyInfo/:buyInfoID", updateBuyInfo)
rg.GET("/buyInfo", findBuyInfo)
rg.POST("/buyInfo", addBuyInfo)
return router
Expand Down Expand Up @@ -58,6 +59,68 @@ func getBuyInfo(c *gin.Context) {
}
}

/**
* @api {post} /buyInfo/:buyInfoID UpdateBuyInfo
* @apiVersion 1.0.0
* @apiGroup BuyInfo
* @apiPermission self/admin
* @apiName UpdateBuyInfo
* @apiDescription Update buy info
*
* @apiParam {int32} status 1 for buying <br> 2 for reserved <br> 3 for done <br> 4 for expired <br> 5 for closed
* @apiSuccess (Success 200) {Response} response see [BuyInfo Service](#api-Service-BuyInfo_Update)
* @apiUse InvalidParam
* @apiUse BuyInfoServiceDown
*/
func updateBuyInfo(c *gin.Context) {
type paramUri struct {
BuyInfoID int32 `uri:"buyInfoID" binding:"required,min=1"`
}
var pu paramUri

type param struct {
Status int32 `form:"status" binding:"required"`
}
var p param

if !utils.LogContinue(c.ShouldBindUri(&pu), utils.Warning) && !utils.LogContinue(c.ShouldBind(&p), utils.Warning) {
srv := utils.CallMicroService("buyInfo", func(name string, c client.Client) interface{} { return buyinfo.NewBuyInfoService(name, c) },
func() interface{} { return mock.NewBuyInfoService() }).(buyinfo.BuyInfoService)
rsp2, err := srv.Query(context.TODO(), &buyinfo.BuyInfoQueryRequest{
BuyInfoID: pu.BuyInfoID,
})
if utils.LogContinue(err, utils.Error) {
c.JSON(500, err)
return
}
if rsp2.BuyInfoID == 0 {
c.JSON(200, &buyinfo.BuyInfoUpdateResponse{
Status: buyinfo.BuyInfoUpdateResponse_NOT_FOUND,
})
return
}

role := utils.GetRoleID(c, rsp2.UserID)

if !role.Self && !role.Admin {
c.AbortWithStatus(403)
return
}

rsp, err := srv.Update(context.TODO(), &buyinfo.BuyInfoUpdateRequest{
BuyInfoID: pu.BuyInfoID,
Status: buyinfo.BuyStatus(utils.EnumConvert(p.Status, buyinfo.BuyStatus_name)),
})
if utils.LogContinue(err, utils.Error) {
c.JSON(500, err)
return
}
c.JSON(200, rsp)
} else {
c.AbortWithStatus(400)
}
}

/**
* @api {post} /buyInfo AddBuyInfo
* @apiVersion 1.0.0
Expand Down
63 changes: 63 additions & 0 deletions backend/api/sellinfo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
func setupRouter() *gin.Engine {
router, rg := utils.CreateAPIGroup()
rg.GET("/sellInfo/:sellInfoID", getSellInfo)
rg.POST("/sellInfo/:sellInfoID", updateSellInfo)
rg.GET("/sellInfo", findSellInfo)
rg.POST("/sellInfo", addSellInfo)
return router
Expand Down Expand Up @@ -58,6 +59,68 @@ func getSellInfo(c *gin.Context) {
}
}

/**
* @api {post} /sellInfo/:sellInfoID UpdateSellInfo
* @apiVersion 1.0.0
* @apiGroup SellInfo
* @apiPermission self/admin
* @apiName UpdateSellInfo
* @apiDescription Update sell info
*
* @apiParam {int32} status 1 for selling <br> 2 for reserved <br> 3 for done <br> 4 for expired <br> 5 for closed
* @apiSuccess (Success 200) {Response} response see [SellInfo Service](#api-Service-SellInfo_Update)
* @apiUse InvalidParam
* @apiUse SellInfoServiceDown
*/
func updateSellInfo(c *gin.Context) {
type paramUri struct {
SellInfoID int32 `uri:"sellInfoID" binding:"required,min=1"`
}
var pu paramUri

type param struct {
Status int32 `form:"status" binding:"required"`
}
var p param

if !utils.LogContinue(c.ShouldBindUri(&pu), utils.Warning) && !utils.LogContinue(c.ShouldBind(&p), utils.Warning) {
srv := utils.CallMicroService("sellInfo", func(name string, c client.Client) interface{} { return sellinfo.NewSellInfoService(name, c) },
func() interface{} { return mock.NewSellInfoService() }).(sellinfo.SellInfoService)
rsp2, err := srv.Query(context.TODO(), &sellinfo.SellInfoQueryRequest{
SellInfoID: pu.SellInfoID,
})
if utils.LogContinue(err, utils.Error) {
c.JSON(500, err)
return
}
if rsp2.SellInfoID == 0 {
c.JSON(200, &sellinfo.SellInfoUpdateResponse{
Status: sellinfo.SellInfoUpdateResponse_NOT_FOUND,
})
return
}

role := utils.GetRoleID(c, rsp2.UserID)

if !role.Self && !role.Admin {
c.AbortWithStatus(403)
return
}

rsp, err := srv.Update(context.TODO(), &sellinfo.SellInfoUpdateRequest{
SellInfoID: pu.SellInfoID,
Status: sellinfo.SellStatus(utils.EnumConvert(p.Status, sellinfo.SellStatus_name)),
})
if utils.LogContinue(err, utils.Error) {
c.JSON(500, err)
return
}
c.JSON(200, rsp)
} else {
c.AbortWithStatus(400)
}
}

/**
* @api {post} /sellInfo AddSellInfo
* @apiVersion 1.0.0
Expand Down
6 changes: 0 additions & 6 deletions backend/api/transaction/Dockerfile

This file was deleted.

Loading

0 comments on commit 9e28a13

Please sign in to comment.