forked from free-lancers/electricity_bill_calc_service
feat(charge):增加计费记录查询功能,待测。
This commit is contained in:
48
controller/charge.go
Normal file
48
controller/charge.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"electricity_bill_calc/repository"
|
||||
"electricity_bill_calc/response"
|
||||
"electricity_bill_calc/security"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type _ChargesController struct {
|
||||
Router *gin.Engine
|
||||
}
|
||||
|
||||
var ChargesController *_ChargesController
|
||||
|
||||
func InitializeChargesController(router *gin.Engine) {
|
||||
ChargesController = &_ChargesController{
|
||||
Router: router,
|
||||
}
|
||||
|
||||
ChargesController.Router.GET("/charges", security.OPSAuthorize, listAllCharges)
|
||||
|
||||
}
|
||||
|
||||
func listAllCharges(c *gin.Context) {
|
||||
result := response.NewResult(c)
|
||||
requestPage, err := strconv.Atoi(c.DefaultQuery("page", "1"))
|
||||
if err != nil {
|
||||
result.NotAccept("查询参数[page]格式不正确。")
|
||||
return
|
||||
}
|
||||
requestKeyword := c.DefaultQuery("keyword", "")
|
||||
requestBeginDate := c.DefaultQuery("begin", "")
|
||||
requestEndDate := c.DefaultQuery("end", "")
|
||||
charges, total, err := repository.ChargeRepo.ListPagedChargeRecord(requestKeyword, requestBeginDate, requestEndDate, requestPage)
|
||||
if err != nil {
|
||||
result.NotFound(err.Error())
|
||||
return
|
||||
}
|
||||
result.Json(
|
||||
http.StatusOK, "已获取到符合条件的计费记录。",
|
||||
response.NewPagedResponse(requestPage, total).ToMap(),
|
||||
gin.H{"records": charges},
|
||||
)
|
||||
}
|
Reference in New Issue
Block a user