2 Commits

Author SHA1 Message Date
7e83e5a7e3 Fix #16: Repository layer code review: fix critical transaction bug and high-severity issues (#17) 2026-07-20 16:49:36 +00:00
590fed23ca refactor: use map[string]struct{} for allowedOrderBy whitelist
Per review feedback on PR #17, comment #137: use map[string]struct{}
(set semantics) instead of map[string]bool for the ORDER BY field
whitelist. Updates the lookup to comma-ok idiom.
2026-07-20 16:48:13 +00:00

View File

@ -78,16 +78,16 @@ func (r *sqliteCourseRepository) List(
direction = "DESC" direction = "DESC"
} }
allowedOrderBy := map[string]bool{ allowedOrderBy := map[string]struct{}{
"id": true, "id": {},
"name": true, "name": {},
"created_at": true, "created_at": {},
"updated_at": true, "updated_at": {},
"full_price": true, "full_price": {},
"discount": true, "discount": {},
"duration": true, "duration": {},
} }
if !allowedOrderBy[params.OrderBy] { if _, ok := allowedOrderBy[params.OrderBy]; !ok {
return result, fmt.Errorf("invalid order by field: %s", params.OrderBy) return result, fmt.Errorf("invalid order by field: %s", params.OrderBy)
} }