Add province-scoped branches for loan paid letters and harden loans.user_id.
Expose GET /loan-paid-off-letters/branches?province_id= for form pickers, require loans.user_id, and proxy the Vite frontend under /online/. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -43,13 +43,13 @@ func (r *repository) List(ctx context.Context, filter province.ListFilter) (prov
|
||||
}
|
||||
|
||||
func (r *repository) ListRegions(ctx context.Context, activeOnly bool) (province.ListRegionsDTO, error) {
|
||||
query := `SELECT DISTINCT region FROM provinces`
|
||||
inner := `SELECT DISTINCT region::jsonb AS region FROM provinces`
|
||||
var args []interface{}
|
||||
if activeOnly {
|
||||
query += ` WHERE active = $1`
|
||||
inner += ` WHERE active = $1`
|
||||
args = append(args, true)
|
||||
}
|
||||
query += ` ORDER BY region->>'tm', region->>'en', region->>'ru'`
|
||||
query := `SELECT region FROM (` + inner + `) AS distinct_regions ORDER BY region->>'tm', region->>'en', region->>'ru'`
|
||||
|
||||
rows, err := r.client.Query(ctx, query, args...)
|
||||
if err != nil {
|
||||
|
||||
@@ -28,8 +28,9 @@ func NewHandler(logger *logging.Logger, repository Repository) handlers.Handler
|
||||
func (h *handler) Register(router *gin.RouterGroup) {
|
||||
group := router.Group(baseURL, appresult.JwtTokenCheck())
|
||||
group.GET("", h.list)
|
||||
group.GET("/regions", h.listRegions)
|
||||
group.GET("/etraps", h.listEtraps)
|
||||
// Use /branches/regions and /branches/etraps instead.
|
||||
// group.GET("/regions", h.listRegions)
|
||||
// group.GET("/etraps", h.listEtraps)
|
||||
group.GET("/:id", h.getByID)
|
||||
group.POST("", h.create)
|
||||
group.PUT("/:id", h.update)
|
||||
@@ -68,69 +69,6 @@ func (h *handler) list(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, appresult.SuccessWithData(result))
|
||||
}
|
||||
|
||||
// listRegions godoc
|
||||
// @Summary List distinct regions
|
||||
// @Description Returns unique regions from the provinces table (for region dropdown)
|
||||
// @Tags province
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
// @Param active query bool false "Only active provinces" default(true)
|
||||
// @Success 200 {object} appresult.AppSuccess
|
||||
// @Failure 400 {object} appresult.AppError
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /provinces/regions [get]
|
||||
func (h *handler) listRegions(c *gin.Context) {
|
||||
activeOnly, ok := parseActiveOnly(c, true)
|
||||
if !ok {
|
||||
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := h.repository.ListRegions(c.Request.Context(), activeOnly)
|
||||
if err != nil {
|
||||
h.logger.Errorf("list regions failed: %v", err)
|
||||
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, appresult.SuccessWithData(result))
|
||||
}
|
||||
|
||||
// listEtraps godoc
|
||||
// @Summary List etraps by region
|
||||
// @Description Returns provinces (etraps) belonging to the selected region
|
||||
// @Tags province
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
// @Param region query string true "Region name (en, ru or tm)"
|
||||
// @Param active query bool false "Only active etraps" default(true)
|
||||
// @Success 200 {object} appresult.AppSuccess
|
||||
// @Failure 400 {object} appresult.AppError
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /provinces/etraps [get]
|
||||
func (h *handler) listEtraps(c *gin.Context) {
|
||||
region := strings.TrimSpace(c.Query("region"))
|
||||
if region == "" {
|
||||
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
|
||||
return
|
||||
}
|
||||
|
||||
activeOnly, ok := parseActiveOnly(c, true)
|
||||
if !ok {
|
||||
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := h.repository.ListEtrapsByRegion(c.Request.Context(), region, activeOnly)
|
||||
if err != nil {
|
||||
h.logger.Errorf("list etraps by region failed: %v", err)
|
||||
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, appresult.SuccessWithData(result))
|
||||
}
|
||||
|
||||
// getByID godoc
|
||||
// @Summary Get province by ID
|
||||
// @Description Returns a single province
|
||||
@@ -273,18 +211,6 @@ func parseID(raw string) (int64, bool) {
|
||||
return id, true
|
||||
}
|
||||
|
||||
func parseActiveOnly(c *gin.Context, defaultValue bool) (bool, bool) {
|
||||
raw := c.Query("active")
|
||||
if raw == "" {
|
||||
return defaultValue, true
|
||||
}
|
||||
active, err := strconv.ParseBool(raw)
|
||||
if err != nil {
|
||||
return false, false
|
||||
}
|
||||
return active, true
|
||||
}
|
||||
|
||||
const (
|
||||
defaultPage = 1
|
||||
defaultLimit = 10
|
||||
|
||||
Reference in New Issue
Block a user