Skip to content

Commit cc6c8e5

Browse files
committed
feat(sort_obligations): Add sorting of obligations by topic
Signed-off-by: deo002 <[email protected]>
1 parent 9524e7b commit cc6c8e5

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

cmd/laas/docs/docs.go

+11
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,17 @@ const docTemplate = `{
951951
"description": "Number of records per page",
952952
"name": "limit",
953953
"in": "query"
954+
},
955+
{
956+
"enum": [
957+
"asc",
958+
"desc"
959+
],
960+
"type": "string",
961+
"default": "asc",
962+
"description": "Asc or desc ordering",
963+
"name": "order_by",
964+
"in": "query"
954965
}
955966
],
956967
"responses": {

cmd/laas/docs/swagger.json

+11
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,17 @@
944944
"description": "Number of records per page",
945945
"name": "limit",
946946
"in": "query"
947+
},
948+
{
949+
"enum": [
950+
"asc",
951+
"desc"
952+
],
953+
"type": "string",
954+
"default": "asc",
955+
"description": "Asc or desc ordering",
956+
"name": "order_by",
957+
"in": "query"
947958
}
948959
],
949960
"responses": {

cmd/laas/docs/swagger.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,14 @@ paths:
13601360
in: query
13611361
name: limit
13621362
type: integer
1363+
- default: asc
1364+
description: Asc or desc ordering
1365+
enum:
1366+
- asc
1367+
- desc
1368+
in: query
1369+
name: order_by
1370+
type: string
13631371
produces:
13641372
- application/json
13651373
responses:

pkg/api/obligations.go

+15-5
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ import (
3434
// @Tags Obligations
3535
// @Accept json
3636
// @Produce json
37-
// @Param active query bool true "Active obligation only"
38-
// @Param page query int false "Page number"
39-
// @Param limit query int false "Number of records per page"
40-
// @Success 200 {object} models.ObligationResponse
41-
// @Failure 404 {object} models.LicenseError "No obligations in DB"
37+
// @Param active query bool true "Active obligation only"
38+
// @Param page query int false "Page number"
39+
// @Param limit query int false "Number of records per page"
40+
// @Param order_by query string false "Asc or desc ordering" Enums(asc, desc) default(asc)
41+
// @Success 200 {object} models.ObligationResponse
42+
// @Failure 404 {object} models.LicenseError "No obligations in DB"
4243
// @Router /obligations [get]
4344
func GetAllObligation(c *gin.Context) {
4445
var obligations []models.Obligation
@@ -64,6 +65,15 @@ func GetAllObligation(c *gin.Context) {
6465

6566
_ = utils.PreparePaginateResponse(c, query, &models.ObligationResponse{})
6667

68+
orderBy := c.Query("order_by")
69+
queryOrderString := "topic"
70+
71+
if orderBy != "" && orderBy == "desc" {
72+
queryOrderString += " desc"
73+
}
74+
75+
query.Order(queryOrderString)
76+
6777
if err = query.Find(&obligations).Error; err != nil {
6878
er := models.LicenseError{
6979
Status: http.StatusInternalServerError,

0 commit comments

Comments
 (0)