enhance(fee):改进维护费归属判断逻辑,同时完成维护费部分接口的测试。

This commit is contained in:
徐涛
2022-08-16 10:12:31 +08:00
parent 0bc2fd3152
commit 689b1018ab
3 changed files with 60 additions and 1 deletions

View File

@@ -25,6 +25,7 @@ func InitializeMaintenanceFeeController(router *gin.Engine) {
MaintenanceFeeController.Router.GET("/maintenance/fee", security.EnterpriseAuthorize, listMaintenanceFees)
MaintenanceFeeController.Router.POST("/maintenance/fee", security.EnterpriseAuthorize, createMaintenanceFeeRecord)
MaintenanceFeeController.Router.PUT("/maintenance/fee/:mid", security.EnterpriseAuthorize, modifyMaintenanceFeeRecord)
}
func listMaintenanceFees(c *gin.Context) {
@@ -70,7 +71,7 @@ type _FeeCreationFormData struct {
ParkId string `json:"parkId" form:"parkId"`
Name string `json:"name" form:"name"`
Fee decimal.Decimal `json:"fee" form:"fee"`
Memo string `json:"memo" form:"memo"`
Memo *string `json:"memo" form:"memo"`
}
func createMaintenanceFeeRecord(c *gin.Context) {
@@ -100,3 +101,37 @@ func createMaintenanceFeeRecord(c *gin.Context) {
}
result.Created("新维护费记录已经创建。")
}
type _FeeModificationFormData struct {
Fee decimal.Decimal `json:"fee" form:"fee"`
Memo *string `json:"memo" form:"memo"`
}
func modifyMaintenanceFeeRecord(c *gin.Context) {
result := response.NewResult(c)
requestFee := c.Param("mid")
formData := new(_FeeModificationFormData)
c.BindJSON(formData)
userSession, err := _retreiveSession(c)
if err != nil {
result.Unauthorized(err.Error())
return
}
sure, err := service.MaintenanceFeeService.EnsureFeeBelongs(userSession.Uid, requestFee)
if err != nil {
result.Error(http.StatusInternalServerError, err.Error())
return
}
if !sure {
result.Unauthorized("所操作维护费记录不属于当前用户。")
return
}
newFeeState := new(model.MaintenanceFee)
copier.Copy(newFeeState, formData)
err = service.MaintenanceFeeService.ModifyMaintenanceFee(*newFeeState)
if err != nil {
result.Error(http.StatusInternalServerError, err.Error())
return
}
result.Success("指定维护费条目已更新。")
}