From 65d5aaf9848a59c68ca99717224ea85ec777a0f0 Mon Sep 17 00:00:00 2001 From: Sourav Bhowmik Date: Mon, 21 Oct 2024 11:38:11 +0200 Subject: [PATCH] fix: obligation POST, PATCH fixed for category --- cmd/laas/docs/docs.go | 67 ++++++++++++++++++++++++++++++-------- cmd/laas/docs/swagger.json | 67 ++++++++++++++++++++++++++++++-------- cmd/laas/docs/swagger.yaml | 48 ++++++++++++++++++++++----- pkg/api/obligations.go | 5 +++ pkg/models/types.go | 2 +- 5 files changed, 154 insertions(+), 35 deletions(-) diff --git a/cmd/laas/docs/docs.go b/cmd/laas/docs/docs.go index c010b18..d680ac4 100644 --- a/cmd/laas/docs/docs.go +++ b/cmd/laas/docs/docs.go @@ -2337,7 +2337,60 @@ const docTemplate = `{ } }, "models.ObligationPATCHRequestJSONSchema": { - "type": "object" + "type": "object", + "required": [ + "category" + ], + "properties": { + "active": { + "type": "boolean", + "example": true + }, + "category": { + "type": "string", + "enum": [ + "Distribution", + "Patent", + "Internal", + "Contractual", + "Export Control", + "General" + ], + "example": "Distribution" + }, + "classification": { + "type": "string", + "enum": [ + "green", + "white", + "yellow", + "red" + ] + }, + "comment": { + "type": "string", + "example": "This is a comment." + }, + "modifications": { + "type": "boolean" + }, + "text": { + "type": "string", + "example": "Source code be made available when distributing the software." + }, + "text_updatable": { + "type": "boolean" + }, + "type": { + "type": "string", + "enum": [ + "obligation", + "restriction", + "risk", + "right" + ] + } + } }, "models.ObligationPOSTRequestJSONSchema": { "type": "object", @@ -2464,18 +2517,6 @@ const docTemplate = `{ } } }, - "models.OptionalData-string": { - "type": "object", - "properties": { - "isDefined": { - "description": "This is set to true if corresponding key is present in json object", - "type": "boolean" - }, - "value": { - "type": "string" - } - } - }, "models.PaginationMeta": { "type": "object", "properties": { diff --git a/cmd/laas/docs/swagger.json b/cmd/laas/docs/swagger.json index c26ea53..4dccfb7 100644 --- a/cmd/laas/docs/swagger.json +++ b/cmd/laas/docs/swagger.json @@ -2330,7 +2330,60 @@ } }, "models.ObligationPATCHRequestJSONSchema": { - "type": "object" + "type": "object", + "required": [ + "category" + ], + "properties": { + "active": { + "type": "boolean", + "example": true + }, + "category": { + "type": "string", + "enum": [ + "Distribution", + "Patent", + "Internal", + "Contractual", + "Export Control", + "General" + ], + "example": "Distribution" + }, + "classification": { + "type": "string", + "enum": [ + "green", + "white", + "yellow", + "red" + ] + }, + "comment": { + "type": "string", + "example": "This is a comment." + }, + "modifications": { + "type": "boolean" + }, + "text": { + "type": "string", + "example": "Source code be made available when distributing the software." + }, + "text_updatable": { + "type": "boolean" + }, + "type": { + "type": "string", + "enum": [ + "obligation", + "restriction", + "risk", + "right" + ] + } + } }, "models.ObligationPOSTRequestJSONSchema": { "type": "object", @@ -2457,18 +2510,6 @@ } } }, - "models.OptionalData-string": { - "type": "object", - "properties": { - "isDefined": { - "description": "This is set to true if corresponding key is present in json object", - "type": "boolean" - }, - "value": { - "type": "string" - } - } - }, "models.PaginationMeta": { "type": "object", "properties": { diff --git a/cmd/laas/docs/swagger.yaml b/cmd/laas/docs/swagger.yaml index e3ebb1f..2b804b6 100644 --- a/cmd/laas/docs/swagger.yaml +++ b/cmd/laas/docs/swagger.yaml @@ -470,6 +470,46 @@ definitions: type: string type: object models.ObligationPATCHRequestJSONSchema: + properties: + active: + example: true + type: boolean + category: + enum: + - Distribution + - Patent + - Internal + - Contractual + - Export Control + - General + example: Distribution + type: string + classification: + enum: + - green + - white + - yellow + - red + type: string + comment: + example: This is a comment. + type: string + modifications: + type: boolean + text: + example: Source code be made available when distributing the software. + type: string + text_updatable: + type: boolean + type: + enum: + - obligation + - restriction + - risk + - right + type: string + required: + - category type: object models.ObligationPOSTRequestJSONSchema: properties: @@ -563,14 +603,6 @@ definitions: example: 200 type: integer type: object - models.OptionalData-string: - properties: - isDefined: - description: This is set to true if corresponding key is present in json object - type: boolean - value: - type: string - type: object models.PaginationMeta: properties: limit: diff --git a/pkg/api/obligations.go b/pkg/api/obligations.go index 267b095..e7e1d42 100644 --- a/pkg/api/obligations.go +++ b/pkg/api/obligations.go @@ -177,6 +177,7 @@ func CreateObligation(c *gin.Context) { Comment: input.Comment, Modifications: input.Modifications, Active: input.Active, + Category: input.Category, TextUpdatable: false, } @@ -355,6 +356,10 @@ func UpdateObligation(c *gin.Context) { newObligationMap["text_updatable"] = updates.TextUpdatable.Value } + if updates.Category.IsDefined { + newObligationMap["category"] = updates.Category.Value + } + var newObligation models.Obligation newObligation.Id = oldObligation.Id if err := tx.Model(&newObligation).Clauses(clause.Returning{}).Updates(newObligationMap).Error; err != nil { diff --git a/pkg/models/types.go b/pkg/models/types.go index 6f12ce5..90caaef 100644 --- a/pkg/models/types.go +++ b/pkg/models/types.go @@ -320,7 +320,7 @@ type ObligationPATCHRequestJSONSchema struct { Comment OptionalData[string] `json:"comment" swaggertype:"string" example:"This is a comment."` Active OptionalData[bool] `json:"active" swaggertype:"boolean" example:"true"` TextUpdatable OptionalData[bool] `json:"text_updatable" swaggertype:"boolean"` - Category OptionalData[string] `json:"category" enums:"Distribution,Patent,Internal,Contractual,Export Control,General" binding:"required" example:"Distribution"` + Category OptionalData[string] `json:"category" swaggertype:"string" enums:"Distribution,Patent,Internal,Contractual,Export Control,General" binding:"required" example:"Distribution"` } // ObligationResponse represents the response format for obligation data.