Skip to content

Commit

Permalink
fix application data supplement
Browse files Browse the repository at this point in the history
  • Loading branch information
szarbartosz committed Nov 8, 2024
1 parent f4f230a commit 55bcf28
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
12 changes: 10 additions & 2 deletions controllers/locationsController.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func CreateLocation(c *gin.Context) {
DeforestationCause: body.Application.DeforestationCause,
DeforestationDate: body.Application.DeforestationDate,
PlantingDate: body.Application.PlantingDate,
PlantingPlace: body.Application.PlantingPlace,
PlantingSite: body.Application.PlantingSite,
Species: body.Application.Species,
},
Address: models.Address{
Expand Down Expand Up @@ -101,7 +101,7 @@ func UpdateLocation(c *gin.Context) {
location.Application.DeforestationCause = body.Application.DeforestationCause
location.Application.DeforestationDate = body.Application.DeforestationDate
location.Application.PlantingDate = body.Application.PlantingDate
location.Application.PlantingPlace = body.Application.PlantingPlace
location.Application.PlantingSite = body.Application.PlantingSite
location.Application.Species = body.Application.Species

location.Address.City = body.Address.City
Expand All @@ -119,6 +119,14 @@ func UpdateLocation(c *gin.Context) {
return
}

if err := tx.Save(&location.Application).Error; err != nil {
tx.Rollback()
c.JSON(http.StatusInternalServerError, gin.H{
"error": "Failed to update application",
})
return
}

if err := tx.Save(&location.Address).Error; err != nil {
tx.Rollback()
c.JSON(http.StatusInternalServerError, gin.H{
Expand Down
16 changes: 7 additions & 9 deletions models/applicationModel.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package models

import "time"

type Application struct {
ID uint `gorm:"primaryKey" json:"id"`
UserID uint `json:"userId"`
LocationID uint `json:"locationId"`

Signature string `json:"signature"`
IsCommercial bool `json:"isCommercial"`
DeforestationCause string `json:"deforestationCause"`
DeforestationDate *time.Time `json:"deforestationDate"`
PlantingDate *time.Time `json:"plantingDate"`
PlantingPlace string `json:"plantingPlace"`
Species string `json:"species"`
Signature string `json:"signature"`
IsCommercial string `json:"isCommercial"`
DeforestationCause string `json:"deforestationCause"`
DeforestationDate string `json:"deforestationDate"`
PlantingDate string `json:"plantingDate"`
PlantingSite string `json:"plantingSite"`
Species string `json:"species"`
}

0 comments on commit 55bcf28

Please sign in to comment.