Skip to content

Commit

Permalink
feat: added user json as createdBy field in getLicense
Browse files Browse the repository at this point in the history
  • Loading branch information
Sourav Bhowmik committed Nov 7, 2024
1 parent 32ba738 commit b80d684
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 1 deletion.
8 changes: 8 additions & 0 deletions cmd/laas/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1926,6 +1926,14 @@ const docTemplate = `{
"url": {
"type": "string",
"example": "https://opensource.org/licenses/MIT"
},
"user": {
"description": "Reference to User",
"allOf": [
{
"$ref": "#/definitions/models.User"
}
]
}
}
},
Expand Down
8 changes: 8 additions & 0 deletions cmd/laas/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1919,6 +1919,14 @@
"url": {
"type": "string",
"example": "https://opensource.org/licenses/MIT"
},
"user": {
"description": "Reference to User",
"allOf": [
{
"$ref": "#/definitions/models.User"
}
]
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions cmd/laas/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ definitions:
url:
example: https://opensource.org/licenses/MIT
type: string
user:
allOf:
- $ref: '#/definitions/models.User'
description: Reference to User
required:
- fullname
- shortname
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/licenses.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func FilterLicense(c *gin.Context) {
}

var licenses []models.LicenseDB
query := db.DB.Model(&licenses)
query := db.DB.Model(&licenses).Preload("User")

if active != "" {
parsedActive, err := strconv.ParseBool(active)
Expand Down
4 changes: 4 additions & 0 deletions pkg/models/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type LicenseDB struct {
Marydone *bool `json:"marydone" gorm:"column:marydone;not null;default:false"`
ExternalRef datatypes.JSONType[LicenseDBSchemaExtension] `json:"external_ref"`
Obligations []*Obligation `gorm:"many2many:obligation_licenses;" json:"obligations"`
UserId int64 `json:"-" example:"123"` // Foreign key to User
User User `gorm:"foreignKey:UserId;references:Id" json:"user"` // Reference to User
}

func (l *LicenseDB) BeforeSave(tx *gorm.DB) (err error) {
Expand Down Expand Up @@ -99,6 +101,8 @@ type LicenseUpdateJSONSchema struct {
Marydone *bool `json:"marydone" example:"false"`
ExternalRef datatypes.JSONType[LicenseDBSchemaExtension] `json:"external_ref"`
Obligations []*Obligation `json:"obligations"`
UserId int64 `json:"-" example:"123"` // Foreign key to User
User User `json:"-"` // Reference to User
}

// UpdateExternalRefsJSONPayload struct represents the external ref key value pairs for update
Expand Down
Empty file added swagger-diff.txt
Empty file.

0 comments on commit b80d684

Please sign in to comment.