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.
This commit is contained in:
@ -78,16 +78,16 @@ func (r *sqliteCourseRepository) List(
|
||||
direction = "DESC"
|
||||
}
|
||||
|
||||
allowedOrderBy := map[string]bool{
|
||||
"id": true,
|
||||
"name": true,
|
||||
"created_at": true,
|
||||
"updated_at": true,
|
||||
"full_price": true,
|
||||
"discount": true,
|
||||
"duration": true,
|
||||
allowedOrderBy := map[string]struct{}{
|
||||
"id": {},
|
||||
"name": {},
|
||||
"created_at": {},
|
||||
"updated_at": {},
|
||||
"full_price": {},
|
||||
"discount": {},
|
||||
"duration": {},
|
||||
}
|
||||
if !allowedOrderBy[params.OrderBy] {
|
||||
if _, ok := allowedOrderBy[params.OrderBy]; !ok {
|
||||
return result, fmt.Errorf("invalid order by field: %s", params.OrderBy)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user