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 authored and bhowmik94 committed Nov 6, 2024
1 parent 32ba738 commit e8700af
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
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

0 comments on commit e8700af

Please sign in to comment.