forked from free-lancers/electricity_bill_calc_service
enhance(fee):改进维护费归属判断逻辑,同时完成维护费部分接口的测试。
This commit is contained in:
@@ -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("指定维护费条目已更新。")
|
||||
}
|
||||
|
Reference in New Issue
Block a user