| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- package parking
- import (
- "fmt"
- "wails-app/internal/model/common/response"
- "wails-app/internal/model/parking/request"
- parkingResponse "wails-app/internal/model/parking/response"
- "github.com/gin-gonic/gin"
- )
- func CreateBooth(c *gin.Context) {
- var req request.BoothCreate
- if err := c.ShouldBindJSON(&req); err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- err := BoothService.CreateBooth(req)
- if err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- response.OkWithMessage("创建成功", c)
- }
- func UpdateBooth(c *gin.Context) {
- var req request.BoothUpdate
- if err := c.ShouldBindJSON(&req); err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- err := BoothService.UpdateBooth(req)
- if err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- response.OkWithMessage("更新成功", c)
- }
- func GetBoothByID(c *gin.Context) {
- id := c.Query("id")
- uintID := uint(0)
- _, err := fmt.Sscanf(id, "%d", &uintID)
- if err != nil {
- response.FailWithMessage("无效的ID", c)
- return
- }
- booth, err := BoothService.GetBoothByID(uintID)
- if err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- response.OkWithData(booth, c)
- }
- func GetBoothByCode(c *gin.Context) {
- code := c.Query("code")
- if code == "" {
- response.FailWithMessage("岗亭编码不能为空", c)
- return
- }
- booth, err := BoothService.GetBoothByCode(code)
- if err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- response.OkWithData(booth, c)
- }
- func QueryAllBooths(c *gin.Context) {
- booths, err := BoothService.QueryAllBooths()
- if err != nil {
- response.FailWithMessage("THE QUERY FAILED", c)
- }
- response.OkWithData(booths, c)
- }
- func ListBooths(c *gin.Context) {
- var req request.BoothQuery
- if err := c.ShouldBindQuery(&req); err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- total, list, err := BoothService.ListBooths(req)
- if err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- response.OkWithData(parkingResponse.BoothList{
- Total: total,
- List: list,
- }, c)
- }
- func DeleteBooth(c *gin.Context) {
- id := c.Query("id")
- uintID := uint(0)
- _, err := fmt.Sscanf(id, "%d", &uintID)
- if err != nil {
- response.FailWithMessage("无效的ID", c)
- return
- }
- err = BoothService.DeleteBooth(uintID)
- if err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- response.OkWithMessage("删除成功", c)
- }
|