Skip to content

Commit

Permalink
chore: refine gorm schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
baimamboukar committed Dec 26, 2023
1 parent 2e1a2d3 commit 26f82be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/controllers/companies_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ func GetCompanyByID(c *gin.Context) {
func CreateCompany(context *gin.Context) {
var input models.Company
if err := context.ShouldBindJSON(&input); err != nil {
context.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
context.JSON(http.StatusBadRequest, gin.H{"status": "failed", "message": err.Error(), "data": nil})
return
}
// savedCompany, err := input.
savedCompany, err := input.Save()

// if err != nil {
// context.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
// return
// }
if err != nil {
context.JSON(http.StatusBadRequest, gin.H{"status": "failed", "message": err.Error(), "data": nil})
return
}

// context.JSON(http.StatusCreated, gin.H{"data": savedEntry})
context.JSON(http.StatusCreated, gin.H{"status": "failed", "message": "Comnapy saved successfuly", "data": savedCompany})
}

func UpdateCompany(c *gin.Context) {
Expand Down
9 changes: 9 additions & 0 deletions src/models/company.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Company struct {
}

type Office struct {
gorm.Model
Country string `json:"country"`
Town string `json:"town"`
Venue string `json:"venue"`
Expand All @@ -29,3 +30,11 @@ type SocialMedia struct {
LinkedIn string `json:"linkedin"`
Instagram string `json:"instagram"`
}

func (company *Company) Save() (*Company, error) {
err := Database.Create(&company).Error
if err != nil {
return &Company{}, err
}
return company, nil
}

2 comments on commit 26f82be

@vercel
Copy link

@vercel vercel bot commented on 26f82be Dec 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 26f82be Dec 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.