Put the user's role and branch on GET /profile, upsert role_user and branch_user on POST, and drop their list endpoints.

Also accept flexible card-order form values, move mock seed under db/mock, and regenerate Swagger.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
guwandykandCursor committed 2026-08-22 17:56:07 +05:00
1 parent 7225dc0399
commit 8795ae2195
47 files changed
+1308 -1785

No files matched your search

+49 -31
View File
@@ -116,7 +116,8 @@ func (h *handler) getByID(c *gin.Context) {
// @Router /card-orders [post]
func (h *handler) create(c *gin.Context) {
var dto CreateCardOrderDTO
if err := c.ShouldBindJSON(&dto); err != nil {
if err := c.ShouldBindBodyWithJSON(&dto); err != nil {
h.logger.Errorf("create card order bind failed: %v", err)
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
return
}
@@ -153,7 +154,8 @@ func (h *handler) update(c *gin.Context) {
}
var dto UpdateCardOrderDTO
if err := c.ShouldBindJSON(&dto); err != nil {
if err := c.ShouldBindBodyWithJSON(&dto); err != nil {
h.logger.Errorf("update card order bind failed: %v", err)
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
return
}
@@ -223,39 +225,31 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) {
Limit: defaultLimit,
}
if raw := c.Query("branch_id"); raw != "" {
id, ok := parseID(raw)
if !ok {
return ListFilter{}, false
}
filter.BranchId = &id
if id, ok := optionalQueryID(c, "branch_id", "branchId"); !ok {
return ListFilter{}, false
} else if id != nil {
filter.BranchId = id
}
if raw := c.Query("user_id"); raw != "" {
id, ok := parseID(raw)
if !ok {
return ListFilter{}, false
}
filter.UserId = &id
if id, ok := optionalQueryID(c, "user_id", "userId"); !ok {
return ListFilter{}, false
} else if id != nil {
filter.UserId = id
}
if raw := c.Query("card_state_id"); raw != "" {
id, ok := parseID(raw)
if !ok {
return ListFilter{}, false
}
filter.CardStateId = &id
if id, ok := optionalQueryID(c, "card_state_id", "cardStateId"); !ok {
return ListFilter{}, false
} else if id != nil {
filter.CardStateId = id
}
if raw := c.Query("card_type_id"); raw != "" {
id, ok := parseID(raw)
if !ok {
return ListFilter{}, false
}
filter.CardTypeId = &id
if id, ok := optionalQueryID(c, "card_type_id", "cardTypeId"); !ok {
return ListFilter{}, false
} else if id != nil {
filter.CardTypeId = id
}
if raw := c.Query("page"); raw != "" {
if raw := queryValue(c, "page"); raw != "" {
page, err := strconv.Atoi(raw)
if err != nil || page < 1 {
return ListFilter{}, false
@@ -263,21 +257,45 @@ func parseListFilter(c *gin.Context) (ListFilter, bool) {
filter.Page = page
}
if raw := c.Query("limit"); raw != "" {
if raw := queryValue(c, "limit"); raw != "" {
limit, err := strconv.Atoi(raw)
if err != nil || limit < 1 || limit > maxLimit {
if err != nil || limit < 1 {
return ListFilter{}, false
}
if limit > maxLimit {
limit = maxLimit
}
filter.Limit = limit
}
if raw := strings.TrimSpace(c.Query("status")); raw != "" {
if raw := queryValue(c, "status"); raw != "" {
filter.Status = &raw
}
if raw := strings.TrimSpace(c.Query("region")); raw != "" {
if raw := queryValue(c, "region"); raw != "" {
filter.Region = raw
}
return filter, true
}
func queryValue(c *gin.Context, keys ...string) string {
for _, key := range keys {
if raw := strings.TrimSpace(c.Query(key)); raw != "" && raw != "undefined" && raw != "null" {
return raw
}
}
return ""
}
func optionalQueryID(c *gin.Context, keys ...string) (*int64, bool) {
raw := queryValue(c, keys...)
if raw == "" {
return nil, true
}
id, ok := parseID(raw)
if !ok {
return nil, false
}
return &id, true
}