diff --git a/.circleci/config.yml b/.circleci/config.yml index 78a0817..22b492c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,7 +4,7 @@ jobs: build: working_directory: ~/repo docker: - - image: cimg/go:1.19 + - image: cimg/go:1.22 steps: - checkout - restore_cache: diff --git a/Dockerfile b/Dockerfile index b38e0f8..f4f29d6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.19.3-alpine +FROM golang:1.22.3-alpine WORKDIR /app diff --git a/README.md b/README.md index 7ac2718..66baab7 100644 --- a/README.md +++ b/README.md @@ -64,12 +64,12 @@ POST /statuses GET /statuses ``` -### Developer +### Investor -#### create developer +#### create investor ```http -POST /developers +POST /investors ``` ```js @@ -78,10 +78,10 @@ POST /developers } ``` -#### get developers +#### get investors ```http -GET /developers +GET /investors ``` ### Location @@ -94,15 +94,15 @@ POST /locations ```js { - status_id: int, - developer_id: int, + statusId: int, + investorId: int, name: string, - issue_date: string, // ISO 8601 - inspection_date: string, // ISO 8601 - deforestation_date: string, // ISO 8601 - planting_date: string, // ISO 8601 - deforestation_done: boolean, - planting_done: boolean + issueDate: string, // ISO 8601 + inspectionDate: string, // ISO 8601 + deforestationDate: string, // ISO 8601 + plantingDate: string, // ISO 8601 + deforestationDone: boolean, + plantingDone: boolean } ``` @@ -114,15 +114,15 @@ PUT /locations/:id ```js { - status_id: int, - developer_id: int, + statusId: int, + investorId: int, name: string, - issue_date: string, // ISO 8601 - inspection_date: string, // ISO 8601 - deforestation_date: string, // ISO 8601 - planting_date: string, // ISO 8601 - deforestation_done: boolean, - planting_done: boolean + issueDate: string, // ISO 8601 + inspectionDate: string, // ISO 8601 + deforestationDate: string, // ISO 8601 + plantingDate: string, // ISO 8601 + deforestationDone: boolean, + plantingDone: boolean } ``` diff --git a/controllers/developersController.go b/controllers/developersController.go deleted file mode 100644 index 7a8449b..0000000 --- a/controllers/developersController.go +++ /dev/null @@ -1,54 +0,0 @@ -package controllers - -import ( - "main/initializers" - "main/models" - "net/http" - - "github.com/gin-gonic/gin" -) - -func CreateDeveloper(c *gin.Context) { - user, _ := c.Get("user") - var body models.Developer - - if c.BindJSON(&body) != nil { - c.JSON(http.StatusBadRequest, gin.H{ - "error": "Invalid request body", - }) - return - } - - developer := models.Developer{Name: body.Name, UserID: user.(models.User).ID} - result := initializers.DB.Create(&developer) - - if result.Error != nil { - c.JSON(http.StatusInternalServerError, gin.H{ - "error": "Failed to create developer", - }) - return - } - - c.JSON(http.StatusOK, gin.H{ - "message": "Developer created successfully", - "developer": developer, - }) -} - -func GetDevelopers(c *gin.Context) { - user, _ := c.Get("user") - var developers []models.Developer - - result := initializers.DB.Where("user_id = ?", user.(models.User).ID).Find(&developers) - - if result.Error != nil { - c.JSON(http.StatusInternalServerError, gin.H{ - "error": "Failed to get developers", - }) - return - } - - c.JSON(http.StatusOK, gin.H{ - "developers": developers, - }) -} diff --git a/controllers/investorsController.go b/controllers/investorsController.go new file mode 100644 index 0000000..170a812 --- /dev/null +++ b/controllers/investorsController.go @@ -0,0 +1,161 @@ +package controllers + +import ( + "main/initializers" + "main/models" + "net/http" + + "github.com/gin-gonic/gin" +) + +func CreateInvestor(c *gin.Context) { + user, _ := c.Get("user") + var body models.Investor + + if c.BindJSON(&body) != nil { + c.JSON(http.StatusBadRequest, gin.H{ + "error": "Invalid request body", + }) + return + } + + investor := models.Investor{ + Name: body.Name, + UserID: user.(models.User).ID, + ContactPerson: body.ContactPerson, + Email: body.Email, + Phone: body.Phone, + Nip: body.Nip, + Regon: body.Regon, + Address: models.Address{ + UserID: user.(models.User).ID, + City: body.Address.City, + Street: body.Address.Street, + Number: body.Address.Number, + ZipCode: body.Address.ZipCode, + }} + + result := initializers.DB.Create(&investor) + if result.Error != nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Failed to create investor", + }) + return + } + + c.JSON(http.StatusOK, investor) +} + +func UpdateInvestor(c *gin.Context) { + user, _ := c.Get("user") + var body models.Investor + + if c.BindJSON(&body) != nil { + c.JSON(http.StatusBadRequest, gin.H{ + "error": "Invalid request body", + }) + return + } + + var investor models.Investor + result := initializers.DB.Preload("Address").Where("user_id = ?", user.(models.User).ID).Where("id = ?", c.Param("id")).First(&investor) + if result.Error != nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Investor not found", + }) + return + } + + investor.Name = body.Name + investor.ContactPerson = body.ContactPerson + investor.Email = body.Email + investor.Phone = body.Phone + investor.Nip = body.Nip + investor.Regon = body.Regon + + investor.Address.City = body.Address.City + investor.Address.Street = body.Address.Street + investor.Address.Number = body.Address.Number + investor.Address.ZipCode = body.Address.ZipCode + + tx := initializers.DB.Begin() + + if err := tx.Save(&investor).Error; err != nil { + tx.Rollback() + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Failed to update investor", + }) + return + } + + if err := tx.Save(&investor.Address).Error; err != nil { + tx.Rollback() + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Failed to update address", + }) + return + } + + tx.Commit() + + c.JSON(http.StatusOK, investor) +} + +func GetInvestors(c *gin.Context) { + user, _ := c.Get("user") + var investors []models.Investor + + result := initializers.DB.Where("user_id = ?", user.(models.User).ID).Preload("Address").Preload("Locations").Find(&investors) + + if result.Error != nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Failed to get investors", + }) + return + } + + c.JSON(http.StatusOK, investors) +} + +func GetSingleInvestor(c *gin.Context) { + user, _ := c.Get("user") + var investor models.Investor + + result := initializers.DB.Where("user_id = ?", user.(models.User).ID).Preload("Address").Preload("Locations").First(&investor, c.Param("id")) + + if result.Error != nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Failed to get investor", + }) + return + } + + c.JSON(http.StatusOK, investor) +} + +func DeleteInvestor(c *gin.Context) { + user, _ := c.Get("user") + var investor models.Investor + + result := initializers.DB.Where("user_id = ?", user.(models.User).ID).First(&investor, c.Param("id")) + + if result.Error != nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Investor not found", + }) + return + } + + deleteResult := initializers.DB.Delete(&investor) + + if deleteResult.Error != nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Failed to delete investor: " + deleteResult.Error.Error(), + }) + return + } + + c.JSON(http.StatusOK, gin.H{ + "message": "Investor deleted", + }) +} diff --git a/controllers/locationsController.go b/controllers/locationsController.go index 17612d7..181f2af 100644 --- a/controllers/locationsController.go +++ b/controllers/locationsController.go @@ -6,6 +6,7 @@ import ( "net/http" "github.com/gin-gonic/gin" + "gorm.io/gorm/clause" ) func CreateLocation(c *gin.Context) { @@ -20,19 +21,37 @@ func CreateLocation(c *gin.Context) { } location := models.Location{ + UserID: user.(models.User).ID, + StatusID: body.StatusID, + InvestorID: body.InvestorID, + OfficeID: body.OfficeID, Name: body.Name, IssueDate: body.IssueDate, InspectionDate: body.InspectionDate, + InspectionDone: false, DeforestationDate: body.DeforestationDate, - DeforestationDone: body.DeforestationDone, + DeforestationDone: false, PlantingDate: body.PlantingDate, - PlantingDone: body.PlantingDone, - UserID: user.(models.User).ID, - StatusID: body.StatusID, - DeveloperID: body.DeveloperID, - } - result := initializers.DB.Create(&location) + PlantingDone: false, + Application: models.Application{ + UserID: user.(models.User).ID, + Signature: body.Application.Signature, + IsDeforestationCommercial: body.Application.IsDeforestationCommercial, + DeforestationCause: body.Application.DeforestationCause, + DeforestationDate: body.Application.DeforestationDate, + PlantingDate: body.Application.PlantingDate, + PlantingPlace: body.Application.PlantingPlace, + Species: body.Application.Species, + }, + Address: models.Address{ + UserID: user.(models.User).ID, + City: body.Address.City, + Street: body.Address.Street, + Number: body.Address.Number, + ZipCode: body.Address.ZipCode, + }} + result := initializers.DB.Create(&location) if result.Error != nil { c.JSON(http.StatusInternalServerError, gin.H{ "error": "Failed to create location", @@ -40,9 +59,7 @@ func CreateLocation(c *gin.Context) { return } - c.JSON(http.StatusOK, gin.H{ - "location": location, - }) + c.JSON(http.StatusOK, location) } func UpdateLocation(c *gin.Context) { @@ -56,25 +73,68 @@ func UpdateLocation(c *gin.Context) { return } - result := initializers.DB.Where("user_id = ?", user.(models.User).ID).Where("ID", c.Param("id")).Updates(&body) + var location models.Location + result := initializers.DB.Preload("Application").Preload("Address").Where("user_id = ?", user.(models.User).ID).Where("id = ?", c.Param("id")).First(&location) + if result.Error != nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Location not found", + }) + return + } - if result.RowsAffected == 0 { + location.Name = body.Name + location.IssueDate = body.IssueDate + location.InspectionDate = body.InspectionDate + location.InspectionDone = body.InspectionDone + location.DeforestationDate = body.DeforestationDate + location.DeforestationDone = body.DeforestationDone + location.PlantingDate = body.PlantingDate + location.PlantingDone = body.PlantingDone + location.UserID = user.(models.User).ID + location.StatusID = body.StatusID + location.InvestorID = body.InvestorID + + location.Application.Signature = body.Application.Signature + location.Application.IsDeforestationCommercial = body.Application.IsDeforestationCommercial + 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.Species = body.Application.Species + + location.Address.City = body.Address.City + location.Address.Street = body.Address.Street + location.Address.Number = body.Address.Number + location.Address.ZipCode = body.Address.ZipCode + + tx := initializers.DB.Begin() + + if err := tx.Save(&location).Error; err != nil { + tx.Rollback() c.JSON(http.StatusInternalServerError, gin.H{ "error": "Failed to update location", }) return } - c.JSON(http.StatusOK, gin.H{ - "location": body, - }) + if err := tx.Save(&location.Address).Error; err != nil { + tx.Rollback() + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Failed to update address", + }) + return + } + + tx.Commit() + + c.JSON(http.StatusOK, location) } func GetLocations(c *gin.Context) { user, _ := c.Get("user") var locations []models.Location - result := initializers.DB.Where("user_id = ?", user.(models.User).ID).Find(&locations) + result := initializers.DB.Where("user_id = ?", user.(models.User).ID).Preload("Office.Address").Preload("Investor.Address").Preload(clause.Associations).Find(&locations) if result.Error != nil { c.JSON(http.StatusInternalServerError, gin.H{ @@ -83,16 +143,14 @@ func GetLocations(c *gin.Context) { return } - c.JSON(http.StatusOK, gin.H{ - "locations": locations, - }) + c.JSON(http.StatusOK, locations) } func GetSingleLocation(c *gin.Context) { user, _ := c.Get("user") var location models.Location - result := initializers.DB.Where("user_id = ?", user.(models.User).ID).First(&location, c.Param("id")) + result := initializers.DB.Where("user_id = ?", user.(models.User).ID).Preload("Office.Address").Preload("Investor.Address").Preload(clause.Associations).First(&location, c.Param("id")) if result.Error != nil { c.JSON(http.StatusInternalServerError, gin.H{ @@ -101,9 +159,7 @@ func GetSingleLocation(c *gin.Context) { return } - c.JSON(http.StatusOK, gin.H{ - "location": location, - }) + c.JSON(http.StatusOK, location) } func DeleteLocation(c *gin.Context) { @@ -132,3 +188,90 @@ func DeleteLocation(c *gin.Context) { "message": "Location deleted", }) } + +func AddNote(c *gin.Context) { + user, _ := c.Get("user") + var body models.Note + var location models.Location + + if c.BindJSON(&body) != nil { + c.JSON(http.StatusBadRequest, gin.H{ + "error": "Invalid request body", + }) + return + } + + result := initializers.DB.Where("user_id = ?", user.(models.User).ID).First(&location, c.Param("id")) + + if result.Error != nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Location not found", + }) + return + } + + note := models.Note{ + LocationID: location.ID, + Content: body.Content, + } + result = initializers.DB.Create(¬e) + if result.Error != nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Failed to create note", + }) + return + } + + c.JSON(http.StatusOK, note) +} + +func UpdateNote(c *gin.Context) { + var body models.Note + + if c.BindJSON(&body) != nil { + c.JSON(http.StatusBadRequest, gin.H{ + "error": "Invalid request body", + }) + return + } + + result := initializers.DB.Where("id", c.Param("id")).Updates(&body) + + if result.RowsAffected == 0 { + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Failed to update note", + }) + return + } + + var updatedNote models.Note + initializers.DB.First(&updatedNote, c.Param("id")) + + c.JSON(http.StatusOK, updatedNote) +} + +func DeleteNote(c *gin.Context) { + var note models.Note + + result := initializers.DB.Where("id", c.Param("id")).First(¬e) + + if result.Error != nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Note not found", + }) + return + } + + deleteResult := initializers.DB.Delete(¬e) + + if deleteResult.Error != nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Failed to delete note: " + deleteResult.Error.Error(), + }) + return + } + + c.JSON(http.StatusOK, gin.H{ + "message": "Note deleted", + }) +} diff --git a/controllers/officeController.go b/controllers/officeController.go new file mode 100644 index 0000000..75651ac --- /dev/null +++ b/controllers/officeController.go @@ -0,0 +1,146 @@ +package controllers + +import ( + "main/initializers" + "main/models" + "net/http" + + "github.com/gin-gonic/gin" +) + +func CreateOffice(c *gin.Context) { + user, _ := c.Get("user") + var body models.Office + + if c.BindJSON(&body) != nil { + c.JSON(http.StatusBadRequest, gin.H{ + "error": "Invalid request body", + }) + return + } + + office := models.Office{ + Name: body.Name, + Address: models.Address{ + UserID: user.(models.User).ID, + City: body.Address.City, + Street: body.Address.Street, + Number: body.Address.Number, + ZipCode: body.Address.ZipCode, + }} + + result := initializers.DB.Create(&office) + if result.Error != nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Failed to create office", + }) + return + } + + c.JSON(http.StatusOK, office) +} + +func UpdateOffice(c *gin.Context) { + var body models.Office + + if c.BindJSON(&body) != nil { + c.JSON(http.StatusBadRequest, gin.H{ + "error": "Invalid request body", + }) + return + } + + var office models.Office + result := initializers.DB.Preload("Address").Where("id = ?", c.Param("id")).First(&office) + if result.Error != nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Office not found", + }) + return + } + + office.Name = body.Name + + office.Address.City = body.Address.City + office.Address.Street = body.Address.Street + office.Address.Number = body.Address.Number + office.Address.ZipCode = body.Address.ZipCode + + tx := initializers.DB.Begin() + + if err := tx.Save(&office).Error; err != nil { + tx.Rollback() + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Failed to update office", + }) + return + } + + if err := tx.Save(&office.Address).Error; err != nil { + tx.Rollback() + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Failed to update address", + }) + return + } + + tx.Commit() + + c.JSON(http.StatusOK, office) +} + +func GetOffices(c *gin.Context) { + var offices []models.Office + + result := initializers.DB.Preload("Address").Find(&offices) + + if result.Error != nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Failed to get offices", + }) + return + } + + c.JSON(http.StatusOK, offices) +} + +func GetSingleOffice(c *gin.Context) { + var office models.Office + + result := initializers.DB.Preload("Address").Preload("Locations").First(&office, c.Param("id")) + + if result.Error != nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Failed to get office", + }) + return + } + + c.JSON(http.StatusOK, office) +} + +func DeleteOffice(c *gin.Context) { + var office models.Office + + result := initializers.DB.First(&office, c.Param("id")) + + if result.Error != nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Office not found", + }) + return + } + + deleteResult := initializers.DB.Delete(&office) + + if deleteResult.Error != nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Failed to delete office: " + deleteResult.Error.Error(), + }) + return + } + + c.JSON(http.StatusOK, gin.H{ + "message": "Office deleted", + }) +} diff --git a/controllers/statusesController.go b/controllers/statusesController.go index f8235bf..3c002da 100644 --- a/controllers/statusesController.go +++ b/controllers/statusesController.go @@ -19,8 +19,8 @@ func CreateStatus(c *gin.Context) { } status := models.Status{Name: body.Name} - result := initializers.DB.Create(&status) + result := initializers.DB.Create(&status) if result.Error != nil { c.JSON(http.StatusInternalServerError, gin.H{ "error": "Failed to create status", @@ -28,9 +28,32 @@ func CreateStatus(c *gin.Context) { return } - c.JSON(http.StatusOK, gin.H{ - "status": status, - }) + c.JSON(http.StatusOK, status) +} + +func UpdateStatus(c *gin.Context) { + var body models.Status + + if c.BindJSON(&body) != nil { + c.JSON(http.StatusBadRequest, gin.H{ + "error": "Invalid request body", + }) + return + } + + result := initializers.DB.Where("id", c.Param("id")).Updates(&body) + + if result.RowsAffected == 0 { + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Failed to update status", + }) + return + } + + var updatedStatus models.Status + initializers.DB.First(&updatedStatus, c.Param("id")) + + c.JSON(http.StatusOK, updatedStatus) } func GetStatuses(c *gin.Context) { @@ -45,7 +68,31 @@ func GetStatuses(c *gin.Context) { return } + c.JSON(http.StatusOK, statuses) +} + +func DeleteStatus(c *gin.Context) { + var status models.Status + + result := initializers.DB.First(&status, c.Param("id")) + + if result.Error != nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Status not found", + }) + return + } + + deleteResult := initializers.DB.Delete(&status) + + if deleteResult.Error != nil { + c.JSON(http.StatusInternalServerError, gin.H{ + "error": "Failed to delete investor: " + deleteResult.Error.Error(), + }) + return + } + c.JSON(http.StatusOK, gin.H{ - "statuses": statuses, + "message": "Status deleted", }) } diff --git a/controllers/usersController.go b/controllers/usersController.go index 4e6009b..d10cbfd 100644 --- a/controllers/usersController.go +++ b/controllers/usersController.go @@ -14,7 +14,7 @@ import ( ) func Register(c *gin.Context) { - var body models.Credentials + var body models.SignUpCredentials if c.BindJSON(&body) != nil { c.JSON(http.StatusBadRequest, gin.H{ @@ -39,7 +39,7 @@ func Register(c *gin.Context) { return } - user := models.User{Email: body.Email, Password: string(hash)} + user := models.User{Email: body.Email, Password: string(hash), FirstName: body.FirstName, LastName: body.LastName} result := initializers.DB.Create(&user) if result.Error != nil { @@ -99,6 +99,7 @@ func Login(c *gin.Context) { c.SetSameSite(http.SameSiteLaxMode) c.SetCookie("Authorization", tokenString, 60*60*24*30, "/", os.Getenv("COOKIE_DOMAIN"), os.Getenv("SECURE_COOKIE") == "true", true) + c.Header("Authorization", tokenString) c.JSON(http.StatusOK, gin.H{ "token": tokenString, @@ -125,7 +126,5 @@ func DeleteUser(c *gin.Context) { func Validate(c *gin.Context) { user, _ := c.Get("user") - c.JSON(http.StatusOK, gin.H{ - "user": user, - }) + c.JSON(http.StatusOK, user) } diff --git a/docker-compose.yaml b/docker-compose.yaml index eb5a12d..946155d 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,4 +1,3 @@ -version: "3.9" services: database: image: postgres:alpine diff --git a/go.mod b/go.mod index 34bb1f2..373cdf1 100644 --- a/go.mod +++ b/go.mod @@ -1,39 +1,48 @@ module main -go 1.19 +go 1.22 require ( - github.com/gin-gonic/gin v1.8.2 + github.com/gin-gonic/gin v1.10.0 + github.com/go-playground/assert/v2 v2.2.0 github.com/golang-jwt/jwt/v4 v4.4.3 github.com/joho/godotenv v1.4.0 - golang.org/x/crypto v0.14.0 + golang.org/x/crypto v0.23.0 + gorm.io/driver/postgres v1.5.7 gorm.io/gorm v1.25.7-0.20240204074919-46816ad31dde ) require ( + github.com/bytedance/sonic v1.11.6 // indirect + github.com/bytedance/sonic/loader v0.1.1 // indirect + github.com/cloudwego/base64x v0.1.4 // indirect + github.com/cloudwego/iasm v0.2.0 // indirect + github.com/gabriel-vasile/mimetype v1.4.3 // indirect github.com/gin-contrib/sse v0.1.0 // indirect - github.com/go-playground/assert/v2 v2.2.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.11.2 // indirect - github.com/goccy/go-json v0.10.0 // indirect + github.com/go-playground/validator/v10 v10.20.0 // indirect + github.com/goccy/go-json v0.10.2 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect github.com/jackc/pgx/v5 v5.4.3 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/json-iterator/go v1.1.12 // indirect + github.com/klauspost/cpuid/v2 v2.2.7 // indirect github.com/kr/text v0.2.0 // indirect - github.com/leodido/go-urn v1.2.1 // indirect - github.com/mattn/go-isatty v0.0.17 // indirect + github.com/leodido/go-urn v1.4.0 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/pelletier/go-toml/v2 v2.0.6 // indirect - github.com/ugorji/go/codec v1.2.8 // indirect - golang.org/x/net v0.10.0 // indirect - golang.org/x/sys v0.13.0 // indirect - golang.org/x/text v0.13.0 // indirect - google.golang.org/protobuf v1.28.1 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect - gorm.io/driver/postgres v1.5.7 // indirect + github.com/pelletier/go-toml/v2 v2.2.2 // indirect + github.com/rogpeppe/go-internal v1.12.0 // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + github.com/ugorji/go/codec v1.2.12 // indirect + golang.org/x/arch v0.8.0 // indirect + golang.org/x/net v0.25.0 // indirect + golang.org/x/sys v0.20.0 // indirect + golang.org/x/text v0.15.0 // indirect + google.golang.org/protobuf v1.34.1 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 058d09b..f15845d 100644 --- a/go.sum +++ b/go.sum @@ -1,26 +1,33 @@ +github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0= +github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= +github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= +github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= +github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= +github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= +github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= +github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= +github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= -github.com/gin-gonic/gin v1.8.2 h1:UzKToD9/PoFj/V4rvlKqTRKnQYyz8Sc1MJlv4JHPtvY= -github.com/gin-gonic/gin v1.8.2/go.mod h1:qw5AYuDrzRTnhvusDsrov+fDIxp9Dleuu12h8nfB398= +github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= +github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.11.2 h1:q3SHpufmypg+erIExEKUmsgmhDTyhcJ38oeKGACXohU= -github.com/go-playground/validator/v10 v10.11.2/go.mod h1:NieE624vt4SCTJtD87arVLvdmjPAeV8BQlHtMnw9D7s= -github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= -github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= -github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA= -github.com/goccy/go-json v0.10.0/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8= +github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/golang-jwt/jwt/v4 v4.4.3 h1:Hxl6lhQFj4AnOX6MLrsCb/+7tCj7DxP7VA+2rDIq5AU= github.com/golang-jwt/jwt/v4 v4.4.3/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -32,75 +39,77 @@ github.com/jackc/pgx/v5 v5.4.3 h1:cxFyXhxlvAifxnkKKdlxv8XqUf59tDlYjnV5YYfsJJY= github.com/jackc/pgx/v5 v5.4.3/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= -github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg= github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= +github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= -github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= -github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= -github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= +github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU= -github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek= +github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= +github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= +github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= +github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/ugorji/go/codec v1.2.8 h1:sgBJS6COt0b/P40VouWKdseidkDgHxYGm0SAglUHfP0= -github.com/ugorji/go/codec v1.2.8/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= -golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE= -golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= -golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= -golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= -golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw= -golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= -golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= -golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k= -golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= +github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= +github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= +github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= +golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= +golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= -google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= +google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gorm.io/driver/postgres v1.5.7 h1:8ptbNJTDbEmhdr62uReG5BGkdQyeasu/FZHxI0IMGnM= gorm.io/driver/postgres v1.5.7/go.mod h1:3e019WlBaYI5o5LIdNV+LyxCMNtLOQETBXL2h4chKpA= -gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk= -gorm.io/gorm v1.24.3 h1:WL2ifUmzR/SLp85CSURAfybcHnGZ+yLSGSxgYXlFBHg= -gorm.io/gorm v1.24.3/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA= gorm.io/gorm v1.25.7-0.20240204074919-46816ad31dde h1:9DShaph9qhkIYw7QF91I/ynrr4cOO2PZra2PFD7Mfeg= gorm.io/gorm v1.25.7-0.20240204074919-46816ad31dde/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= +nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= +rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/initializers/dbSynchronizer.go b/initializers/dbSynchronizer.go index de37d55..4be4b2c 100644 --- a/initializers/dbSynchronizer.go +++ b/initializers/dbSynchronizer.go @@ -4,7 +4,11 @@ import "main/models" func SyncDB() { DB.AutoMigrate(&models.User{}) + DB.AutoMigrate(&models.Note{}) + DB.AutoMigrate(&models.Office{}) DB.AutoMigrate(&models.Status{}) - DB.AutoMigrate(&models.Developer{}) + DB.AutoMigrate(&models.Address{}) + DB.AutoMigrate(&models.Application{}) + DB.AutoMigrate(&models.Investor{}) DB.AutoMigrate(&models.Location{}) } diff --git a/main.go b/main.go index 793f75f..ac33536 100644 --- a/main.go +++ b/main.go @@ -21,19 +21,32 @@ func main() { r.POST("/register", controllers.Register) r.POST("/login", controllers.Login) r.POST("/statuses", middleware.RequireAuth, controllers.CreateStatus) - r.POST("/developers", middleware.RequireAuth, controllers.CreateDeveloper) + r.POST("/investors", middleware.RequireAuth, controllers.CreateInvestor) + r.POST("offices", middleware.RequireAuth, controllers.CreateOffice) r.POST("/locations", middleware.RequireAuth, controllers.CreateLocation) + r.POST("/locations/:id/notes", middleware.RequireAuth, controllers.AddNote) + r.PUT("/statuses/:id", middleware.RequireAuth, controllers.UpdateStatus) + r.PUT("/investors/:id", middleware.RequireAuth, controllers.UpdateInvestor) + r.PUT("/offices/:id", middleware.RequireAuth, controllers.UpdateOffice) r.PUT("/locations/:id", middleware.RequireAuth, controllers.UpdateLocation) + r.PUT("/notes/:id", middleware.RequireAuth, controllers.UpdateNote) r.GET("/validate", middleware.RequireAuth, controllers.Validate) r.GET("/statuses", middleware.RequireAuth, controllers.GetStatuses) - r.GET("/developers", middleware.RequireAuth, controllers.GetDevelopers) + r.GET("/investors", middleware.RequireAuth, controllers.GetInvestors) + r.GET("/investors/:id", middleware.RequireAuth, controllers.GetSingleInvestor) + r.GET("/offices", middleware.RequireAuth, controllers.GetOffices) + r.GET("/offices/:id", middleware.RequireAuth, controllers.GetSingleOffice) r.GET("/locations", middleware.RequireAuth, controllers.GetLocations) r.GET("/locations/:id", middleware.RequireAuth, controllers.GetSingleLocation) r.DELETE("/users", middleware.RequireAuth, controllers.DeleteUser) + r.DELETE("/statuses/:id", middleware.RequireAuth, controllers.DeleteStatus) + r.DELETE("/investors/:id", middleware.RequireAuth, controllers.DeleteInvestor) + r.DELETE("/offices/:id", middleware.RequireAuth, controllers.DeleteOffice) r.DELETE("/locations/:id", middleware.RequireAuth, controllers.DeleteLocation) + r.DELETE("/notes/:id", middleware.RequireAuth, controllers.DeleteNote) r.Run() } diff --git a/middleware/requireAuth.go b/middleware/requireAuth.go index 867e0a1..223446c 100644 --- a/middleware/requireAuth.go +++ b/middleware/requireAuth.go @@ -6,6 +6,7 @@ import ( "main/models" "net/http" "os" + "strings" "time" "github.com/gin-gonic/gin" @@ -13,13 +14,23 @@ import ( ) func RequireAuth(c *gin.Context) { - tokenString, err := c.Cookie("Authorization") + var err error + authHeader := c.GetHeader("Authorization") + parts := strings.Split(authHeader, " ") - if err != nil { - c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{ - "error": "Unauthorized", - }) - return + tokenString := "" + if len(parts) == 2 { + tokenString = parts[1] + } + + if tokenString == "" { + tokenString, err = c.Cookie("Authorization") + if err != nil { + c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{ + "error": "Unauthorized", + }) + return + } } token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) { diff --git a/models/addressModel.go b/models/addressModel.go new file mode 100644 index 0000000..50f88f4 --- /dev/null +++ b/models/addressModel.go @@ -0,0 +1,19 @@ +package models + +type OwnerType string + +const ( + InvestorType OwnerType = "Investor" + LocationType OwnerType = "Location" + OfficeType OwnerType = "Office" +) + +type Address struct { + ID uint `gorm:"primaryKey" json:"id"` + UserID uint `json:"userId"` + + City string `json:"city"` + Street string `json:"street"` + Number string `json:"number"` + ZipCode string `json:"zipCode"` +} diff --git a/models/applicationModel.go b/models/applicationModel.go new file mode 100644 index 0000000..33bbb72 --- /dev/null +++ b/models/applicationModel.go @@ -0,0 +1,17 @@ +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"` + IsDeforestationCommercial string `json:"isDeforestationCommercial"` + DeforestationCause string `json:"deforestationCause"` + DeforestationDate *time.Time `json:"deforestationDate"` + PlantingDate *time.Time `json:"plantingDate"` + PlantingPlace string `json:"plantingPlace"` + Species string `json:"species"` +} diff --git a/models/authModel.go b/models/authModel.go index d68d2b5..a2d9335 100644 --- a/models/authModel.go +++ b/models/authModel.go @@ -4,3 +4,10 @@ type Credentials struct { Email string `json:"email"` Password string `json:"password"` } + +type SignUpCredentials struct { + Email string `json:"email"` + Password string `json:"password"` + FirstName string `json:"firstName"` + LastName string `json:"lastName"` +} diff --git a/models/commonModel.go b/models/commonModel.go new file mode 100644 index 0000000..5d67fac --- /dev/null +++ b/models/commonModel.go @@ -0,0 +1,10 @@ +package models + +import "time" + +type CommonModel struct { + ID uint `gorm:"primarykey" json:"id"` + CreatedAt time.Time `json:"createdAt"` + UpdatedAt time.Time `json:"updatedAt"` + DeletedAt *time.Time `json:"deletedAt"` +} diff --git a/models/developerModel.go b/models/developerModel.go deleted file mode 100644 index 6085866..0000000 --- a/models/developerModel.go +++ /dev/null @@ -1,8 +0,0 @@ -package models - -type Developer struct { - ID uint `gorm:"primaryKey" json:"id"` - UserID uint `json:"user_id"` - - Name string `gorm:"unique" json:"name"` -} diff --git a/models/investorModel.go b/models/investorModel.go new file mode 100644 index 0000000..f049d47 --- /dev/null +++ b/models/investorModel.go @@ -0,0 +1,16 @@ +package models + +type Investor struct { + ID uint `gorm:"primaryKey" json:"id"` + UserID uint `json:"userId"` + Locations []Location `json:"locations"` + AddressID uint `json:"addressId"` + Address Address `gorm:"foreignKey:AddressID" json:"address"` + + Name string `gorm:"unique" json:"name"` + ContactPerson string `json:"contactPerson"` + Email string `json:"email"` + Phone string `json:"phone"` + Nip string `json:"nip"` + Regon string `json:"regon"` +} diff --git a/models/locationModel.go b/models/locationModel.go index 66d3ee2..31d7949 100644 --- a/models/locationModel.go +++ b/models/locationModel.go @@ -5,16 +5,26 @@ import ( ) type Location struct { - ID uint `gorm:"primaryKey" json:"id"` - UserID uint `json:"user_id"` - StatusID uint `json:"status_id"` - DeveloperID uint `json:"developer_id"` + ID uint `gorm:"primaryKey" json:"id"` + UserID uint `json:"userId"` + StatusID uint `json:"statusId"` + Status Status `gorm:"foreignKey:StatusID" json:"status"` + OfficeID uint `json:"officeId"` + Office Office `gorm:"foreignKey:OfficeID" json:"office"` + InvestorID uint `json:"investorId"` + Investor Investor `gorm:"foreignKey:InvestorID" json:"investor"` + AddressID uint `json:"addressId"` + Address Address `gorm:"foreignKey:AddressID" json:"address"` + Application Application `json:"application"` + Notes []Note `json:"notes"` Name string `gorm:"unique" json:"name"` - IssueDate *time.Time `json:"issue_date"` - InspectionDate *time.Time `json:"inspection_date"` - DeforestationDate *time.Time `json:"deforestation_date"` - PlantingDate *time.Time `json:"planting_date"` - DeforestationDone bool `json:"deforestation_done"` - PlantingDone bool `json:"planting_done"` + IssueDate *time.Time `json:"issueDate"` + InspectionDate *time.Time `json:"inspectionDate"` + DecisionDate *time.Time `json:"decisionDate"` + DeforestationDate *time.Time `json:"deforestationDate"` + PlantingDate *time.Time `json:"plantingDate"` + InspectionDone bool `json:"inspectionDone"` + DeforestationDone bool `json:"deforestationDone"` + PlantingDone bool `json:"plantingDone"` } diff --git a/models/noteModel.go b/models/noteModel.go new file mode 100644 index 0000000..7af07f3 --- /dev/null +++ b/models/noteModel.go @@ -0,0 +1,10 @@ +package models + +type Note struct { + CommonModel + ID uint `gorm:"primaryKey" json:"id"` + UserID uint `json:"userId"` + LocationID uint `json:"locationId"` + + Content string `json:"content"` +} diff --git a/models/officeModel.go b/models/officeModel.go new file mode 100644 index 0000000..87e8c5c --- /dev/null +++ b/models/officeModel.go @@ -0,0 +1,10 @@ +package models + +type Office struct { + ID uint `gorm:"primaryKey" json:"id"` + Locations []Location `json:"locations"` + AddressID uint `json:"addressId"` + Address Address `gorm:"foreignKey:AddressID" json:"address"` + + Name string `json:"name"` +} diff --git a/models/statusModel.go b/models/statusModel.go index 61b3fed..36cbb4a 100644 --- a/models/statusModel.go +++ b/models/statusModel.go @@ -1,6 +1,7 @@ package models type Status struct { - ID uint `gorm:"primaryKey" json:"id"` + ID uint `gorm:"primaryKey" json:"id"` + Name string `gorm:"unique" json:"name"` } diff --git a/models/userModel.go b/models/userModel.go index 9f616aa..a145989 100644 --- a/models/userModel.go +++ b/models/userModel.go @@ -1,10 +1,12 @@ package models -import "gorm.io/gorm" - type User struct { - gorm.Model - Email string `gorm:"unique" json:"email"` - Password string `json:"password"` + CommonModel + Investors []Investor `json:"investors"` Locations []Location `json:"locations"` + + FirstName string `json:"firstName"` + LastName string `json:"lastName"` + Email string `gorm:"unique" json:"email"` + Password string `json:"password"` } diff --git a/validators/usersValidator.go b/validators/usersValidator.go index 7d1cdf7..f816617 100644 --- a/validators/usersValidator.go +++ b/validators/usersValidator.go @@ -7,7 +7,7 @@ import ( "github.com/gin-gonic/gin" ) -func UserAlreadyExists(c *gin.Context, body models.Credentials) bool { +func UserAlreadyExists(c *gin.Context, body models.SignUpCredentials) bool { var user models.User result := initializers.DB.First(&user, "email = ?", body.Email)