Skip to content

Commit

Permalink
fix: obligation POST, PATCH fixed for category
Browse files Browse the repository at this point in the history
  • Loading branch information
Sourav Bhowmik committed Oct 21, 2024
1 parent f63fa1e commit 65d5aaf
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 35 deletions.
67 changes: 54 additions & 13 deletions cmd/laas/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down
67 changes: 54 additions & 13 deletions cmd/laas/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down
48 changes: 40 additions & 8 deletions cmd/laas/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions pkg/api/obligations.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ func CreateObligation(c *gin.Context) {
Comment: input.Comment,
Modifications: input.Modifications,
Active: input.Active,
Category: input.Category,
TextUpdatable: false,
}

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/models/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 65d5aaf

Please sign in to comment.