Skip to content

Commit

Permalink
feat: add creating application filter (can only apply once)
Browse files Browse the repository at this point in the history
  • Loading branch information
kastnerorz committed Apr 5, 2020
1 parent 6882021 commit 7de4c1f
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions backend/routers/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,33 @@ func CreateApplication(c *gin.Context) {
}

if applicationParam.QuotationId == "" {
c.JSON(http.StatusBadRequest, gin.H{"code": -1, "msg": "报价ID不能为空!"})
c.JSON(http.StatusBadRequest, gin.H{"code": -2, "msg": "报价ID不能为空!"})
log.Println(err)
return
}

mongoCtx, collection := pkg.GetMongoContext("quotations")
mongoCtx, collection := pkg.GetMongoContext("applications")
pendingCount, err := collection.CountDocuments(mongoCtx, bson.M{
"applicant._id": user.ID,
"quotationId": tools.ObjectID(applicationParam.QuotationId),
"status": "PENDING"})
if pendingCount > 0 {
c.JSON(http.StatusBadRequest, gin.H{"code": -3, "msg": "同一报价只能同时提交1个申请!"})
log.Println(err)
return
}

mongoCtx, collection = pkg.GetMongoContext("quotations")
var quotation models.Quotation
err = collection.FindOne(mongoCtx, bson.M{"_id": tools.ObjectID(applicationParam.QuotationId)}).Decode(&quotation)
if err != nil && err != mongo.ErrNoDocuments {
c.JSON(http.StatusInternalServerError, gin.H{"code": -1, "msg": "(-2)内部错误", "err": err})
c.JSON(http.StatusInternalServerError, gin.H{"code": -4, "msg": "(-2)内部错误", "err": err})
log.Println(err)
return
}

if err == mongo.ErrNoDocuments {
c.JSON(http.StatusBadRequest, gin.H{"code": -1, "msg": "报价不存在!"})
c.JSON(http.StatusBadRequest, gin.H{"code": -5, "msg": "报价不存在!"})
log.Println(err)
return
}
Expand All @@ -61,7 +72,7 @@ func CreateApplication(c *gin.Context) {
"switchFriendNumber": "",
})
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"code": -3, "msg": "(-3)内部错误"})
c.JSON(http.StatusInternalServerError, gin.H{"code": -6, "msg": "(-3)内部错误"})
log.Println(err)
return
}
Expand Down

0 comments on commit 7de4c1f

Please sign in to comment.