enhance(fee):完成维护费项目的测试,改进确定维护费所属。

This commit is contained in:
徐涛
2022-08-16 10:49:17 +08:00
parent 689b1018ab
commit 5fac9a7da4
2 changed files with 62 additions and 4 deletions

View File

@@ -26,6 +26,8 @@ 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)
MaintenanceFeeController.Router.PUT("/maintenance/fee/:mid/enabled", security.EnterpriseAuthorize, changeMaintenanceFeeState)
MaintenanceFeeController.Router.DELETE("/maintenance/fee/:mid", security.EnterpriseAuthorize, deleteMaintenanceFee)
}
func listMaintenanceFees(c *gin.Context) {
@@ -133,5 +135,61 @@ func modifyMaintenanceFeeRecord(c *gin.Context) {
result.Error(http.StatusInternalServerError, err.Error())
return
}
result.Success("指定维护费条目已更新。")
result.Updated("指定维护费条目已更新。")
}
type _FeeStateFormData struct {
Enabled bool `json:"enabled" form:"enabled"`
}
func changeMaintenanceFeeState(c *gin.Context) {
result := response.NewResult(c)
requestFee := c.Param("mid")
formData := new(_FeeStateFormData)
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
}
err = service.MaintenanceFeeService.ChangeMaintenanceFeeState(requestFee, formData.Enabled)
if err != nil {
result.Error(http.StatusInternalServerError, err.Error())
return
}
result.Updated("指定维护费条目状态已更新。")
}
func deleteMaintenanceFee(c *gin.Context) {
result := response.NewResult(c)
requestFee := c.Param("mid")
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
}
err = service.MaintenanceFeeService.DeleteMaintenanceFee(requestFee)
if err != nil {
result.Error(http.StatusInternalServerError, err.Error())
return
}
result.Deleted("指定维护费条目已删除。")
}