package api import ( "net/http" db "git.nochill.in/nochill/hiling_go/db/repository" "github.com/gin-gonic/gin" ) type getAllImagesReq struct { Page int32 `form:"page" binding:"required,min=1"` PageSize int32 `form:"page_size" binding:"required,min=5"` LocationId int32 `form:"location_id" binding:"required,numeric"` } // @Summary Get all images for a location // @Tags images // @Produce json // @Param location_id query int true "Location ID" // @Param page query int true "Page (min 1)" // @Param page_size query int true "Page size (min 5)" // @Success 200 {object} map[string]any // @Failure 400 {object} map[string]any // @Router /images/location [get] func (server *Server) getAllImagesByLocation(ctx *gin.Context) { var req getAllImagesReq if err := ctx.BindQuery(&req); err != nil { ctx.JSON(http.StatusBadRequest, ValidationErrorResponse(err)) return } arg := db.GetImagesByLocationParams{ Limit: req.PageSize, Offset: (req.Page - 1) * req.PageSize, LocationId: req.LocationId, } count, err := server.Store.GetCountImageByLocation(ctx, arg.LocationId) if err != nil { ctx.JSON(http.StatusInternalServerError, ErrorResponse(err, "Something went wrong")) return } images, err := server.Store.GetImagesByLocation(ctx, arg) if err != nil { ctx.JSON(http.StatusInternalServerError, ErrorResponse(err, "Something went wrong")) return } ctx.JSON(http.StatusOK, gin.H{ "total_image": count, "images": images, }) }