Skip to content

Commit

Permalink
Merge pull request #76 from siemens/sort_obligations
Browse files Browse the repository at this point in the history
feat(sort_obligations): Add sorting of obligations by topic

Reviewed-by: mishra.gaurav@siemens.com
Tested-by: mishra.gaurav@siemens.com
  • Loading branch information
GMishx authored Jul 24, 2024
2 parents 27ea834 + cc6c8e5 commit a1335bf
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
11 changes: 11 additions & 0 deletions cmd/laas/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,17 @@ const docTemplate = `{
"description": "Number of records per page",
"name": "limit",
"in": "query"
},
{
"enum": [
"asc",
"desc"
],
"type": "string",
"default": "asc",
"description": "Asc or desc ordering",
"name": "order_by",
"in": "query"
}
],
"responses": {
Expand Down
11 changes: 11 additions & 0 deletions cmd/laas/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,17 @@
"description": "Number of records per page",
"name": "limit",
"in": "query"
},
{
"enum": [
"asc",
"desc"
],
"type": "string",
"default": "asc",
"description": "Asc or desc ordering",
"name": "order_by",
"in": "query"
}
],
"responses": {
Expand Down
8 changes: 8 additions & 0 deletions cmd/laas/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,14 @@ paths:
in: query
name: limit
type: integer
- default: asc
description: Asc or desc ordering
enum:
- asc
- desc
in: query
name: order_by
type: string
produces:
- application/json
responses:
Expand Down
20 changes: 15 additions & 5 deletions pkg/api/obligations.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ import (
// @Tags Obligations
// @Accept json
// @Produce json
// @Param active query bool true "Active obligation only"
// @Param page query int false "Page number"
// @Param limit query int false "Number of records per page"
// @Success 200 {object} models.ObligationResponse
// @Failure 404 {object} models.LicenseError "No obligations in DB"
// @Param active query bool true "Active obligation only"
// @Param page query int false "Page number"
// @Param limit query int false "Number of records per page"
// @Param order_by query string false "Asc or desc ordering" Enums(asc, desc) default(asc)
// @Success 200 {object} models.ObligationResponse
// @Failure 404 {object} models.LicenseError "No obligations in DB"
// @Router /obligations [get]
func GetAllObligation(c *gin.Context) {
var obligations []models.Obligation
Expand All @@ -64,6 +65,15 @@ func GetAllObligation(c *gin.Context) {

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

orderBy := c.Query("order_by")
queryOrderString := "topic"

if orderBy != "" && orderBy == "desc" {
queryOrderString += " desc"
}

query.Order(queryOrderString)

if err = query.Find(&obligations).Error; err != nil {
er := models.LicenseError{
Status: http.StatusInternalServerError,
Expand Down

0 comments on commit a1335bf

Please sign in to comment.