From b32c55d92b3867f815af2b597bef6da16ad3eeb9 Mon Sep 17 00:00:00 2001 From: Cedrik Hoffmann Date: Sat, 14 Sep 2024 20:16:35 +0200 Subject: [PATCH 1/8] feat: add treecluster entities and implement handler --- .../http/entities/treecluster/treecluster.go | 73 +++++++++ .../http/handler/v1/treecluster/handler.go | 141 ++++++++++++++++++ 2 files changed, 214 insertions(+) create mode 100644 internal/server/http/entities/treecluster/treecluster.go create mode 100644 internal/server/http/handler/v1/treecluster/handler.go diff --git a/internal/server/http/entities/treecluster/treecluster.go b/internal/server/http/entities/treecluster/treecluster.go new file mode 100644 index 000000000..424271872 --- /dev/null +++ b/internal/server/http/entities/treecluster/treecluster.go @@ -0,0 +1,73 @@ +package treecluster + +import ( + "time" + + "github.com/green-ecolution/green-ecolution-backend/internal/server/http/entities/pagination" + "github.com/green-ecolution/green-ecolution-backend/internal/server/http/entities/tree" +) + +type TreeClusterWateringStatus string // @Name WateringStatus + +const ( + TreeClusterWateringStatusGood TreeClusterWateringStatus = "good" + TreeClusterWateringStatusModerate TreeClusterWateringStatus = "moderate" + TreeClusterWateringStatusBad TreeClusterWateringStatus = "bad" + TreeClusterWateringStatusUnknown TreeClusterWateringStatus = "unknown" +) + +type TreeSoilCondition string // @Name SoilCondition + +const ( + TreeSoilConditionSchluffig TreeSoilCondition = "schluffig" +) + +type TreeClusterResponse struct { + ID int32 `json:"id,omitempty"` + CreatedAt time.Time `json:"created_at,omitempty"` + UpdatedAt time.Time `json:"updated_at,omitempty"` + WateringStatus TreeClusterWateringStatus `json:"watering_status,omitempty"` + LastWatered time.Time `json:"last_watered,omitempty"` + MoistureLevel float64 `json:"moisture_level,omitempty"` + Region string `json:"region,omitempty"` + Address string `json:"address,omitempty"` + Description string `json:"description,omitempty"` + Archived bool `json:"archived,omitempty"` + Latitude float64 `json:"latitude,omitempty"` + Longitude float64 `json:"longitude,omitempty"` + Trees []*tree.TreeResponse `json:"trees,omitempty"` + SoilCondition TreeSoilCondition `json:"soil_condition,omitempty"` +} // @Name TreeCluster + +type TreeClusterListResponse struct { + Data []*TreeClusterResponse `json:"data,omitempty"` + Pagination *pagination.Pagination `json:"pagination,omitempty"` +} // @Name TreeClusterList + +type TreeClusterCreateRequest struct { + WateringStatus TreeClusterWateringStatus `json:"watering_status,omitempty"` + LastWatered time.Time `json:"last_watered,omitempty"` + MoistureLevel float64 `json:"moisture_level,omitempty"` + Region string `json:"region,omitempty"` + Address string `json:"address,omitempty"` + Description string `json:"description,omitempty"` + Archived bool `json:"archived,omitempty"` + Latitude float64 `json:"latitude,omitempty"` + Longitude float64 `json:"longitude,omitempty"` + TreeIDs []*int32 `json:"tree_ids,omitempty"` + SoilCondition TreeSoilCondition `json:"soil_condition,omitempty"` +} // @Name TreeClusterCreate + +type TreeClusterUpdateRequest struct { + WateringStatus TreeClusterWateringStatus `json:"watering_status,omitempty"` + LastWatered time.Time `json:"last_watered,omitempty"` + MoistureLevel float64 `json:"moisture_level,omitempty"` + Region string `json:"region,omitempty"` + Address string `json:"address,omitempty"` + Description string `json:"description,omitempty"` + Archived bool `json:"archived,omitempty"` + Latitude float64 `json:"latitude,omitempty"` + Longitude float64 `json:"longitude,omitempty"` + TreeIDs []*int32 `json:"tree_ids,omitempty"` + SoilCondition TreeSoilCondition `json:"soil_condition,omitempty"` +} // @Name TreeClusterUpdate diff --git a/internal/server/http/handler/v1/treecluster/handler.go b/internal/server/http/handler/v1/treecluster/handler.go new file mode 100644 index 000000000..b9cc65c0c --- /dev/null +++ b/internal/server/http/handler/v1/treecluster/handler.go @@ -0,0 +1,141 @@ +package treecluster + +import ( + "github.com/gofiber/fiber/v2" + "github.com/green-ecolution/green-ecolution-backend/internal/server/http/entities/tree" + "github.com/green-ecolution/green-ecolution-backend/internal/server/http/entities/treecluster" + "github.com/green-ecolution/green-ecolution-backend/internal/service" +) + +// @Summary Get all tree clusters +// @Description Get all tree clusters +// @Id get-all-tree-clusters +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterListResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster [get] +// @Param page query string false "Page" +// @Param limit query string false "Limit" +// @Param status query string false "Status" +// @Param Authorization header string true "Insert your access token" default(Bearer ) +func GetAllTreeClusters(svc service.Service) fiber.Handler { + return func(c *fiber.Ctx) error { + // TODO: Implement + return c.JSON(treecluster.TreeClusterListResponse{}) + } +} + +// @Summary Get tree cluster by ID +// @Description Get tree cluster by ID +// @Id get-tree-cluster-by-id +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster/{treecluster_id} [get] +// @Param treecluster_id path string true "Tree Cluster ID" +// @Param Authorization header string true "Insert your access token" default(Bearer ) +func GetTreeClusterByID(svc service.Service) fiber.Handler { + return func(c *fiber.Ctx) error { + // TODO: Implement + return c.JSON(treecluster.TreeClusterResponse{}) + } +} + +// @Summary Create tree cluster +// @Description Create tree cluster +// @Id create-tree-cluster +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster [post] +// @Param body body treecluster.TreeClusterCreateRequest true "Tree Cluster Create Request" +// @Param Authorization header string true "Insert your access token" default(Bearer ) +func CreateTreeCluster(svc service.Service) fiber.Handler { + return func(c *fiber.Ctx) error { + // TODO: Implement + return c.JSON(treecluster.TreeClusterResponse{}) + } +} + +// @Summary Update tree cluster +// @Description Update tree cluster +// @Id update-tree-cluster +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster/{treecluster_id} [put] +// @Param treecluster_id path string true "Tree Cluster ID" +// @Param body body treecluster.TreeClusterUpdateRequest true "Tree Cluster Update Request" +// @Param Authorization header string true "Insert your access token" default(Bearer ) +func UpdateTreeCluster(svc service.Service) fiber.Handler { + return func(c *fiber.Ctx) error { + // TODO: Implement + return c.JSON(treecluster.TreeClusterResponse{}) + } +} + +// @Summary Delete tree cluster +// @Description Delete tree cluster +// @Id delete-tree-cluster +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster/{treecluster_id} [delete] +// @Param treecluster_id path string true "Tree Cluster ID" +// @Param Authorization header string true "Insert your access token" default(Bearer ) +func DeleteTreeCluster(svc service.Service) fiber.Handler { + return func(c *fiber.Ctx) error { + // TODO: Implement + return c.JSON(treecluster.TreeClusterResponse{}) + } +} + +// @Summary Get all trees in tree cluster +// @Description Get all trees in tree cluster +// @Id get-all-trees-in-tree-cluster +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} tree.TreeResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster/{treecluster_id}/trees [get] +// @Param treecluster_id path string true "Tree Cluster ID" +// @Param page query string false "Page" +// @Param limit query string false "Limit" +// @Param age query string false "Age" +// @Param Authorization header string true "Insert your access token" default(Bearer ) +func GetAllTreesInTreeCluster(svc service.Service) fiber.Handler { + // TODO: Change response @Success to tree.TreeListResponse + return func(c *fiber.Ctx) error { + // TODO: Implement + return c.JSON(tree.TreeResponse{}) + } +} From db6e8d6bb2080672a372169e6fca59664186d5ca Mon Sep 17 00:00:00 2001 From: Cedrik Hoffmann Date: Sat, 14 Sep 2024 20:21:48 +0200 Subject: [PATCH 2/8] feat: add more endpoints --- .../http/entities/treecluster/treecluster.go | 4 ++ .../http/handler/v1/treecluster/handler.go | 47 ++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/internal/server/http/entities/treecluster/treecluster.go b/internal/server/http/entities/treecluster/treecluster.go index 424271872..095b218ec 100644 --- a/internal/server/http/entities/treecluster/treecluster.go +++ b/internal/server/http/entities/treecluster/treecluster.go @@ -71,3 +71,7 @@ type TreeClusterUpdateRequest struct { TreeIDs []*int32 `json:"tree_ids,omitempty"` SoilCondition TreeSoilCondition `json:"soil_condition,omitempty"` } // @Name TreeClusterUpdate + +type TreeClusterAddTreesRequest struct { + TreeIDs []*int32 `json:"tree_ids,omitempty"` +} // @Name TreeClusterAddTrees diff --git a/internal/server/http/handler/v1/treecluster/handler.go b/internal/server/http/handler/v1/treecluster/handler.go index b9cc65c0c..46c1f2655 100644 --- a/internal/server/http/handler/v1/treecluster/handler.go +++ b/internal/server/http/handler/v1/treecluster/handler.go @@ -132,10 +132,55 @@ func DeleteTreeCluster(svc service.Service) fiber.Handler { // @Param limit query string false "Limit" // @Param age query string false "Age" // @Param Authorization header string true "Insert your access token" default(Bearer ) -func GetAllTreesInTreeCluster(svc service.Service) fiber.Handler { +func GetTreesInTreeCluster(svc service.Service) fiber.Handler { // TODO: Change response @Success to tree.TreeListResponse return func(c *fiber.Ctx) error { // TODO: Implement return c.JSON(tree.TreeResponse{}) } } + +// @Summary Add trees to tree cluster +// @Description Add trees to tree cluster +// @Id add-trees-to-tree-cluster +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster/{treecluster_id}/trees [post] +// @Param treecluster_id path string true "Tree Cluster ID" +// @Param body body treecluster.TreeClusterAddTreesRequest true "Tree Cluster Add Trees Request" +// @Param Authorization header string true "Insert your access token" default(Bearer ) +func AddTreesToTreeCluster(svc service.Service) fiber.Handler { + return func(c *fiber.Ctx) error { + // TODO: Implement + return c.JSON(treecluster.TreeClusterResponse{}) + } +} + +// @Summary Remove trees from tree cluster +// @Description Remove trees from tree cluster +// @Id remove-trees-from-tree-cluster +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster/{treecluster_id}/trees/{tree_id} [delete] +// @Param treecluster_id path string true "Tree Cluster ID" +// @Param tree_id path string true "Tree ID" +// @Param Authorization header string true "Insert your access token" default(Bearer ) +func RemoveTreesFromTreeCluster(svc service.Service) fiber.Handler { + return func(c *fiber.Ctx) error { + // TODO: Implement + return c.JSON(treecluster.TreeClusterResponse{}) + } +} + From 2a10dc6085eae4a87df849b787dec44e77b20aca Mon Sep 17 00:00:00 2001 From: Cedrik Hoffmann Date: Sat, 14 Sep 2024 20:22:05 +0200 Subject: [PATCH 3/8] feat: add handler to routes --- .../http/handler/v1/treecluster/routes.go | 21 +++++++++++++++++++ internal/server/http/router.go | 2 ++ 2 files changed, 23 insertions(+) create mode 100644 internal/server/http/handler/v1/treecluster/routes.go diff --git a/internal/server/http/handler/v1/treecluster/routes.go b/internal/server/http/handler/v1/treecluster/routes.go new file mode 100644 index 000000000..7e16747ba --- /dev/null +++ b/internal/server/http/handler/v1/treecluster/routes.go @@ -0,0 +1,21 @@ +package treecluster + +import ( + "github.com/gofiber/fiber/v2" + "github.com/green-ecolution/green-ecolution-backend/internal/service" +) + +func RegisterRoutes(svc service.Service) *fiber.App { + app := fiber.New() + + app.Get("/", GetAllTreeClusters(svc)) + app.Get("/:treecluster_id", GetTreeClusterByID(svc)) + app.Post("/", CreateTreeCluster(svc)) + app.Put("/:treecluster_id", UpdateTreeCluster(svc)) + app.Delete("/:treecluster_id", DeleteTreeCluster(svc)) + app.Get("/:treecluster_id/trees", GetTreesInTreeCluster(svc)) + app.Post("/:treecluster_id/trees", AddTreesToTreeCluster(svc)) + app.Delete("/:treecluster_id/trees/:tree_id", RemoveTreesFromTreeCluster(svc)) + + return app +} diff --git a/internal/server/http/router.go b/internal/server/http/router.go index f15363037..1441c9b47 100644 --- a/internal/server/http/router.go +++ b/internal/server/http/router.go @@ -5,6 +5,7 @@ import ( "github.com/gofiber/swagger" "github.com/green-ecolution/green-ecolution-backend/internal/server/http/handler/v1/auth" "github.com/green-ecolution/green-ecolution-backend/internal/server/http/handler/v1/info" + "github.com/green-ecolution/green-ecolution-backend/internal/server/http/handler/v1/treecluster" "github.com/green-ecolution/green-ecolution-backend/internal/server/http/middleware" ) @@ -12,6 +13,7 @@ func (s *Server) privateRoutes(app *fiber.App) { grp := app.Group("/api/v1") grp.Mount("/info", info.RegisterRoutes(s.services.InfoService)) + grp.Mount("/cluster", treecluster.RegisterRoutes(s.services.TreeService)) // TODO: Change to treecluster service } func (s *Server) publicRoutes(app *fiber.App) { From c91e3568a2ccdafade0b2d08d2dff0aa4a5205ed Mon Sep 17 00:00:00 2001 From: Cedrik Hoffmann Date: Sat, 14 Sep 2024 20:23:43 +0200 Subject: [PATCH 4/8] chore: run fmt and satisfy linter --- .../http/entities/treecluster/treecluster.go | 2 +- .../http/handler/v1/treecluster/handler.go | 273 +++++++++--------- .../http/handler/v1/treecluster/routes.go | 4 +- internal/server/http/router.go | 2 +- 4 files changed, 140 insertions(+), 141 deletions(-) diff --git a/internal/server/http/entities/treecluster/treecluster.go b/internal/server/http/entities/treecluster/treecluster.go index 095b218ec..ef80464c4 100644 --- a/internal/server/http/entities/treecluster/treecluster.go +++ b/internal/server/http/entities/treecluster/treecluster.go @@ -73,5 +73,5 @@ type TreeClusterUpdateRequest struct { } // @Name TreeClusterUpdate type TreeClusterAddTreesRequest struct { - TreeIDs []*int32 `json:"tree_ids,omitempty"` + TreeIDs []*int32 `json:"tree_ids,omitempty"` } // @Name TreeClusterAddTrees diff --git a/internal/server/http/handler/v1/treecluster/handler.go b/internal/server/http/handler/v1/treecluster/handler.go index 46c1f2655..bc2040aa3 100644 --- a/internal/server/http/handler/v1/treecluster/handler.go +++ b/internal/server/http/handler/v1/treecluster/handler.go @@ -7,132 +7,132 @@ import ( "github.com/green-ecolution/green-ecolution-backend/internal/service" ) -// @Summary Get all tree clusters -// @Description Get all tree clusters -// @Id get-all-tree-clusters -// @Tags Tree Cluster -// @Produce json -// @Success 200 {object} treecluster.TreeClusterListResponse -// @Failure 400 {object} HTTPError -// @Failure 401 {object} HTTPError -// @Failure 403 {object} HTTPError -// @Failure 404 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /v1/cluster [get] -// @Param page query string false "Page" -// @Param limit query string false "Limit" -// @Param status query string false "Status" -// @Param Authorization header string true "Insert your access token" default(Bearer ) -func GetAllTreeClusters(svc service.Service) fiber.Handler { +// @Summary Get all tree clusters +// @Description Get all tree clusters +// @Id get-all-tree-clusters +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterListResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster [get] +// @Param page query string false "Page" +// @Param limit query string false "Limit" +// @Param status query string false "Status" +// @Param Authorization header string true "Insert your access token" default(Bearer ) +func GetAllTreeClusters(_ service.Service) fiber.Handler { return func(c *fiber.Ctx) error { // TODO: Implement return c.JSON(treecluster.TreeClusterListResponse{}) } } -// @Summary Get tree cluster by ID -// @Description Get tree cluster by ID -// @Id get-tree-cluster-by-id -// @Tags Tree Cluster -// @Produce json -// @Success 200 {object} treecluster.TreeClusterResponse -// @Failure 400 {object} HTTPError -// @Failure 401 {object} HTTPError -// @Failure 403 {object} HTTPError -// @Failure 404 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /v1/cluster/{treecluster_id} [get] -// @Param treecluster_id path string true "Tree Cluster ID" -// @Param Authorization header string true "Insert your access token" default(Bearer ) -func GetTreeClusterByID(svc service.Service) fiber.Handler { +// @Summary Get tree cluster by ID +// @Description Get tree cluster by ID +// @Id get-tree-cluster-by-id +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster/{treecluster_id} [get] +// @Param treecluster_id path string true "Tree Cluster ID" +// @Param Authorization header string true "Insert your access token" default(Bearer ) +func GetTreeClusterByID(_ service.Service) fiber.Handler { return func(c *fiber.Ctx) error { // TODO: Implement return c.JSON(treecluster.TreeClusterResponse{}) } } -// @Summary Create tree cluster -// @Description Create tree cluster -// @Id create-tree-cluster -// @Tags Tree Cluster -// @Produce json -// @Success 200 {object} treecluster.TreeClusterResponse -// @Failure 400 {object} HTTPError -// @Failure 401 {object} HTTPError -// @Failure 403 {object} HTTPError -// @Failure 404 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /v1/cluster [post] -// @Param body body treecluster.TreeClusterCreateRequest true "Tree Cluster Create Request" -// @Param Authorization header string true "Insert your access token" default(Bearer ) -func CreateTreeCluster(svc service.Service) fiber.Handler { +// @Summary Create tree cluster +// @Description Create tree cluster +// @Id create-tree-cluster +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster [post] +// @Param body body treecluster.TreeClusterCreateRequest true "Tree Cluster Create Request" +// @Param Authorization header string true "Insert your access token" default(Bearer ) +func CreateTreeCluster(_ service.Service) fiber.Handler { return func(c *fiber.Ctx) error { // TODO: Implement return c.JSON(treecluster.TreeClusterResponse{}) } } -// @Summary Update tree cluster -// @Description Update tree cluster -// @Id update-tree-cluster -// @Tags Tree Cluster -// @Produce json -// @Success 200 {object} treecluster.TreeClusterResponse -// @Failure 400 {object} HTTPError -// @Failure 401 {object} HTTPError -// @Failure 403 {object} HTTPError -// @Failure 404 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /v1/cluster/{treecluster_id} [put] -// @Param treecluster_id path string true "Tree Cluster ID" -// @Param body body treecluster.TreeClusterUpdateRequest true "Tree Cluster Update Request" -// @Param Authorization header string true "Insert your access token" default(Bearer ) -func UpdateTreeCluster(svc service.Service) fiber.Handler { +// @Summary Update tree cluster +// @Description Update tree cluster +// @Id update-tree-cluster +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster/{treecluster_id} [put] +// @Param treecluster_id path string true "Tree Cluster ID" +// @Param body body treecluster.TreeClusterUpdateRequest true "Tree Cluster Update Request" +// @Param Authorization header string true "Insert your access token" default(Bearer ) +func UpdateTreeCluster(_ service.Service) fiber.Handler { return func(c *fiber.Ctx) error { // TODO: Implement return c.JSON(treecluster.TreeClusterResponse{}) } } -// @Summary Delete tree cluster -// @Description Delete tree cluster -// @Id delete-tree-cluster -// @Tags Tree Cluster -// @Produce json -// @Success 200 {object} treecluster.TreeClusterResponse -// @Failure 400 {object} HTTPError -// @Failure 401 {object} HTTPError -// @Failure 403 {object} HTTPError -// @Failure 404 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /v1/cluster/{treecluster_id} [delete] -// @Param treecluster_id path string true "Tree Cluster ID" -// @Param Authorization header string true "Insert your access token" default(Bearer ) -func DeleteTreeCluster(svc service.Service) fiber.Handler { +// @Summary Delete tree cluster +// @Description Delete tree cluster +// @Id delete-tree-cluster +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster/{treecluster_id} [delete] +// @Param treecluster_id path string true "Tree Cluster ID" +// @Param Authorization header string true "Insert your access token" default(Bearer ) +func DeleteTreeCluster(_ service.Service) fiber.Handler { return func(c *fiber.Ctx) error { // TODO: Implement return c.JSON(treecluster.TreeClusterResponse{}) } } -// @Summary Get all trees in tree cluster -// @Description Get all trees in tree cluster -// @Id get-all-trees-in-tree-cluster -// @Tags Tree Cluster -// @Produce json -// @Success 200 {object} tree.TreeResponse -// @Failure 400 {object} HTTPError -// @Failure 401 {object} HTTPError -// @Failure 403 {object} HTTPError -// @Failure 404 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /v1/cluster/{treecluster_id}/trees [get] -// @Param treecluster_id path string true "Tree Cluster ID" -// @Param page query string false "Page" -// @Param limit query string false "Limit" -// @Param age query string false "Age" -// @Param Authorization header string true "Insert your access token" default(Bearer ) -func GetTreesInTreeCluster(svc service.Service) fiber.Handler { +// @Summary Get all trees in tree cluster +// @Description Get all trees in tree cluster +// @Id get-all-trees-in-tree-cluster +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} tree.TreeResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster/{treecluster_id}/trees [get] +// @Param treecluster_id path string true "Tree Cluster ID" +// @Param page query string false "Page" +// @Param limit query string false "Limit" +// @Param age query string false "Age" +// @Param Authorization header string true "Insert your access token" default(Bearer ) +func GetTreesInTreeCluster(_ service.Service) fiber.Handler { // TODO: Change response @Success to tree.TreeListResponse return func(c *fiber.Ctx) error { // TODO: Implement @@ -140,47 +140,46 @@ func GetTreesInTreeCluster(svc service.Service) fiber.Handler { } } -// @Summary Add trees to tree cluster -// @Description Add trees to tree cluster -// @Id add-trees-to-tree-cluster -// @Tags Tree Cluster -// @Produce json -// @Success 200 {object} treecluster.TreeClusterResponse -// @Failure 400 {object} HTTPError -// @Failure 401 {object} HTTPError -// @Failure 403 {object} HTTPError -// @Failure 404 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /v1/cluster/{treecluster_id}/trees [post] -// @Param treecluster_id path string true "Tree Cluster ID" -// @Param body body treecluster.TreeClusterAddTreesRequest true "Tree Cluster Add Trees Request" -// @Param Authorization header string true "Insert your access token" default(Bearer ) -func AddTreesToTreeCluster(svc service.Service) fiber.Handler { - return func(c *fiber.Ctx) error { - // TODO: Implement - return c.JSON(treecluster.TreeClusterResponse{}) - } +// @Summary Add trees to tree cluster +// @Description Add trees to tree cluster +// @Id add-trees-to-tree-cluster +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster/{treecluster_id}/trees [post] +// @Param treecluster_id path string true "Tree Cluster ID" +// @Param body body treecluster.TreeClusterAddTreesRequest true "Tree Cluster Add Trees Request" +// @Param Authorization header string true "Insert your access token" default(Bearer ) +func AddTreesToTreeCluster(_ service.Service) fiber.Handler { + return func(c *fiber.Ctx) error { + // TODO: Implement + return c.JSON(treecluster.TreeClusterResponse{}) + } } -// @Summary Remove trees from tree cluster -// @Description Remove trees from tree cluster -// @Id remove-trees-from-tree-cluster -// @Tags Tree Cluster -// @Produce json -// @Success 200 {object} treecluster.TreeClusterResponse -// @Failure 400 {object} HTTPError -// @Failure 401 {object} HTTPError -// @Failure 403 {object} HTTPError -// @Failure 404 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /v1/cluster/{treecluster_id}/trees/{tree_id} [delete] -// @Param treecluster_id path string true "Tree Cluster ID" -// @Param tree_id path string true "Tree ID" -// @Param Authorization header string true "Insert your access token" default(Bearer ) -func RemoveTreesFromTreeCluster(svc service.Service) fiber.Handler { - return func(c *fiber.Ctx) error { - // TODO: Implement - return c.JSON(treecluster.TreeClusterResponse{}) - } +// @Summary Remove trees from tree cluster +// @Description Remove trees from tree cluster +// @Id remove-trees-from-tree-cluster +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster/{treecluster_id}/trees/{tree_id} [delete] +// @Param treecluster_id path string true "Tree Cluster ID" +// @Param tree_id path string true "Tree ID" +// @Param Authorization header string true "Insert your access token" default(Bearer ) +func RemoveTreesFromTreeCluster(_ service.Service) fiber.Handler { + return func(c *fiber.Ctx) error { + // TODO: Implement + return c.JSON(treecluster.TreeClusterResponse{}) + } } - diff --git a/internal/server/http/handler/v1/treecluster/routes.go b/internal/server/http/handler/v1/treecluster/routes.go index 7e16747ba..86f0fc622 100644 --- a/internal/server/http/handler/v1/treecluster/routes.go +++ b/internal/server/http/handler/v1/treecluster/routes.go @@ -14,8 +14,8 @@ func RegisterRoutes(svc service.Service) *fiber.App { app.Put("/:treecluster_id", UpdateTreeCluster(svc)) app.Delete("/:treecluster_id", DeleteTreeCluster(svc)) app.Get("/:treecluster_id/trees", GetTreesInTreeCluster(svc)) - app.Post("/:treecluster_id/trees", AddTreesToTreeCluster(svc)) - app.Delete("/:treecluster_id/trees/:tree_id", RemoveTreesFromTreeCluster(svc)) + app.Post("/:treecluster_id/trees", AddTreesToTreeCluster(svc)) + app.Delete("/:treecluster_id/trees/:tree_id", RemoveTreesFromTreeCluster(svc)) return app } diff --git a/internal/server/http/router.go b/internal/server/http/router.go index 1441c9b47..2b8f4a066 100644 --- a/internal/server/http/router.go +++ b/internal/server/http/router.go @@ -13,7 +13,7 @@ func (s *Server) privateRoutes(app *fiber.App) { grp := app.Group("/api/v1") grp.Mount("/info", info.RegisterRoutes(s.services.InfoService)) - grp.Mount("/cluster", treecluster.RegisterRoutes(s.services.TreeService)) // TODO: Change to treecluster service + grp.Mount("/cluster", treecluster.RegisterRoutes(s.services.TreeService)) // TODO: Change to treecluster service } func (s *Server) publicRoutes(app *fiber.App) { From 2343bb6f2823573ca366b8cfbbb6237c2af5a2f8 Mon Sep 17 00:00:00 2001 From: Cedrik Hoffmann Date: Sat, 14 Sep 2024 21:34:57 +0200 Subject: [PATCH 5/8] chore: unifying names in swagger --- .../http/handler/v1/treecluster/handler.go | 240 +++++++++--------- 1 file changed, 120 insertions(+), 120 deletions(-) diff --git a/internal/server/http/handler/v1/treecluster/handler.go b/internal/server/http/handler/v1/treecluster/handler.go index bc2040aa3..bdd5f0a5c 100644 --- a/internal/server/http/handler/v1/treecluster/handler.go +++ b/internal/server/http/handler/v1/treecluster/handler.go @@ -7,22 +7,22 @@ import ( "github.com/green-ecolution/green-ecolution-backend/internal/service" ) -// @Summary Get all tree clusters -// @Description Get all tree clusters -// @Id get-all-tree-clusters -// @Tags Tree Cluster -// @Produce json -// @Success 200 {object} treecluster.TreeClusterListResponse -// @Failure 400 {object} HTTPError -// @Failure 401 {object} HTTPError -// @Failure 403 {object} HTTPError -// @Failure 404 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /v1/cluster [get] -// @Param page query string false "Page" -// @Param limit query string false "Limit" -// @Param status query string false "Status" -// @Param Authorization header string true "Insert your access token" default(Bearer ) +// @Summary Get all tree clusters +// @Description Get all tree clusters +// @Id get-all-tree-clusters +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterListResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster [get] +// @Param page query string false "Page" +// @Param limit query string false "Limit" +// @Param status query string false "Status" +// @Param Authorization header string true "Insert your access token" default(Bearer ) func GetAllTreeClusters(_ service.Service) fiber.Handler { return func(c *fiber.Ctx) error { // TODO: Implement @@ -30,20 +30,20 @@ func GetAllTreeClusters(_ service.Service) fiber.Handler { } } -// @Summary Get tree cluster by ID -// @Description Get tree cluster by ID -// @Id get-tree-cluster-by-id -// @Tags Tree Cluster -// @Produce json -// @Success 200 {object} treecluster.TreeClusterResponse -// @Failure 400 {object} HTTPError -// @Failure 401 {object} HTTPError -// @Failure 403 {object} HTTPError -// @Failure 404 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /v1/cluster/{treecluster_id} [get] -// @Param treecluster_id path string true "Tree Cluster ID" -// @Param Authorization header string true "Insert your access token" default(Bearer ) +// @Summary Get tree cluster by ID +// @Description Get tree cluster by ID +// @Id get-tree-cluster-by-id +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster/{cluster_id} [get] +// @Param cluster_id path string true "Tree Cluster ID" +// @Param Authorization header string true "Insert your access token" default(Bearer ) func GetTreeClusterByID(_ service.Service) fiber.Handler { return func(c *fiber.Ctx) error { // TODO: Implement @@ -51,20 +51,20 @@ func GetTreeClusterByID(_ service.Service) fiber.Handler { } } -// @Summary Create tree cluster -// @Description Create tree cluster -// @Id create-tree-cluster -// @Tags Tree Cluster -// @Produce json -// @Success 200 {object} treecluster.TreeClusterResponse -// @Failure 400 {object} HTTPError -// @Failure 401 {object} HTTPError -// @Failure 403 {object} HTTPError -// @Failure 404 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /v1/cluster [post] -// @Param body body treecluster.TreeClusterCreateRequest true "Tree Cluster Create Request" -// @Param Authorization header string true "Insert your access token" default(Bearer ) +// @Summary Create tree cluster +// @Description Create tree cluster +// @Id create-tree-cluster +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster [post] +// @Param body body treecluster.TreeClusterCreateRequest true "Tree Cluster Create Request" +// @Param Authorization header string true "Insert your access token" default(Bearer ) func CreateTreeCluster(_ service.Service) fiber.Handler { return func(c *fiber.Ctx) error { // TODO: Implement @@ -72,21 +72,21 @@ func CreateTreeCluster(_ service.Service) fiber.Handler { } } -// @Summary Update tree cluster -// @Description Update tree cluster -// @Id update-tree-cluster -// @Tags Tree Cluster -// @Produce json -// @Success 200 {object} treecluster.TreeClusterResponse -// @Failure 400 {object} HTTPError -// @Failure 401 {object} HTTPError -// @Failure 403 {object} HTTPError -// @Failure 404 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /v1/cluster/{treecluster_id} [put] -// @Param treecluster_id path string true "Tree Cluster ID" -// @Param body body treecluster.TreeClusterUpdateRequest true "Tree Cluster Update Request" -// @Param Authorization header string true "Insert your access token" default(Bearer ) +// @Summary Update tree cluster +// @Description Update tree cluster +// @Id update-tree-cluster +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster/{cluster_id} [put] +// @Param cluster_id path string true "Tree Cluster ID" +// @Param body body treecluster.TreeClusterUpdateRequest true "Tree Cluster Update Request" +// @Param Authorization header string true "Insert your access token" default(Bearer ) func UpdateTreeCluster(_ service.Service) fiber.Handler { return func(c *fiber.Ctx) error { // TODO: Implement @@ -94,20 +94,20 @@ func UpdateTreeCluster(_ service.Service) fiber.Handler { } } -// @Summary Delete tree cluster -// @Description Delete tree cluster -// @Id delete-tree-cluster -// @Tags Tree Cluster -// @Produce json -// @Success 200 {object} treecluster.TreeClusterResponse -// @Failure 400 {object} HTTPError -// @Failure 401 {object} HTTPError -// @Failure 403 {object} HTTPError -// @Failure 404 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /v1/cluster/{treecluster_id} [delete] -// @Param treecluster_id path string true "Tree Cluster ID" -// @Param Authorization header string true "Insert your access token" default(Bearer ) +// @Summary Delete tree cluster +// @Description Delete tree cluster +// @Id delete-tree-cluster +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster/{cluster_id} [delete] +// @Param cluster_id path string true "Tree Cluster ID" +// @Param Authorization header string true "Insert your access token" default(Bearer ) func DeleteTreeCluster(_ service.Service) fiber.Handler { return func(c *fiber.Ctx) error { // TODO: Implement @@ -115,23 +115,23 @@ func DeleteTreeCluster(_ service.Service) fiber.Handler { } } -// @Summary Get all trees in tree cluster -// @Description Get all trees in tree cluster -// @Id get-all-trees-in-tree-cluster -// @Tags Tree Cluster -// @Produce json -// @Success 200 {object} tree.TreeResponse -// @Failure 400 {object} HTTPError -// @Failure 401 {object} HTTPError -// @Failure 403 {object} HTTPError -// @Failure 404 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /v1/cluster/{treecluster_id}/trees [get] -// @Param treecluster_id path string true "Tree Cluster ID" -// @Param page query string false "Page" -// @Param limit query string false "Limit" -// @Param age query string false "Age" -// @Param Authorization header string true "Insert your access token" default(Bearer ) +// @Summary Get all trees in tree cluster +// @Description Get all trees in tree cluster +// @Id get-all-trees-in-tree-cluster +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} tree.TreeResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster/{cluster_id}/trees [get] +// @Param cluster_id path string true "Tree Cluster ID" +// @Param page query string false "Page" +// @Param limit query string false "Limit" +// @Param age query string false "Age" +// @Param Authorization header string true "Insert your access token" default(Bearer ) func GetTreesInTreeCluster(_ service.Service) fiber.Handler { // TODO: Change response @Success to tree.TreeListResponse return func(c *fiber.Ctx) error { @@ -140,21 +140,21 @@ func GetTreesInTreeCluster(_ service.Service) fiber.Handler { } } -// @Summary Add trees to tree cluster -// @Description Add trees to tree cluster -// @Id add-trees-to-tree-cluster -// @Tags Tree Cluster -// @Produce json -// @Success 200 {object} treecluster.TreeClusterResponse -// @Failure 400 {object} HTTPError -// @Failure 401 {object} HTTPError -// @Failure 403 {object} HTTPError -// @Failure 404 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /v1/cluster/{treecluster_id}/trees [post] -// @Param treecluster_id path string true "Tree Cluster ID" -// @Param body body treecluster.TreeClusterAddTreesRequest true "Tree Cluster Add Trees Request" -// @Param Authorization header string true "Insert your access token" default(Bearer ) +// @Summary Add trees to tree cluster +// @Description Add trees to tree cluster +// @Id add-trees-to-tree-cluster +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster/{cluster_id}/trees [post] +// @Param cluster_id path string true "Tree Cluster ID" +// @Param body body treecluster.TreeClusterAddTreesRequest true "Tree Cluster Add Trees Request" +// @Param Authorization header string true "Insert your access token" default(Bearer ) func AddTreesToTreeCluster(_ service.Service) fiber.Handler { return func(c *fiber.Ctx) error { // TODO: Implement @@ -162,21 +162,21 @@ func AddTreesToTreeCluster(_ service.Service) fiber.Handler { } } -// @Summary Remove trees from tree cluster -// @Description Remove trees from tree cluster -// @Id remove-trees-from-tree-cluster -// @Tags Tree Cluster -// @Produce json -// @Success 200 {object} treecluster.TreeClusterResponse -// @Failure 400 {object} HTTPError -// @Failure 401 {object} HTTPError -// @Failure 403 {object} HTTPError -// @Failure 404 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /v1/cluster/{treecluster_id}/trees/{tree_id} [delete] -// @Param treecluster_id path string true "Tree Cluster ID" -// @Param tree_id path string true "Tree ID" -// @Param Authorization header string true "Insert your access token" default(Bearer ) +// @Summary Remove trees from tree cluster +// @Description Remove trees from tree cluster +// @Id remove-trees-from-tree-cluster +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster/{cluster_id}/trees/{tree_id} [delete] +// @Param cluster_id path string true "Tree Cluster ID" +// @Param tree_id path string true "Tree ID" +// @Param Authorization header string true "Insert your access token" default(Bearer ) func RemoveTreesFromTreeCluster(_ service.Service) fiber.Handler { return func(c *fiber.Ctx) error { // TODO: Implement From 5408965297b9373de5ea7b5c8574dfcb79b67d93 Mon Sep 17 00:00:00 2001 From: Cedrik Hoffmann Date: Sat, 14 Sep 2024 21:35:26 +0200 Subject: [PATCH 6/8] feat: remove last waterded and moisture level in create tree cluster --- internal/server/http/entities/treecluster/treecluster.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/server/http/entities/treecluster/treecluster.go b/internal/server/http/entities/treecluster/treecluster.go index ef80464c4..eef141b8b 100644 --- a/internal/server/http/entities/treecluster/treecluster.go +++ b/internal/server/http/entities/treecluster/treecluster.go @@ -46,8 +46,6 @@ type TreeClusterListResponse struct { type TreeClusterCreateRequest struct { WateringStatus TreeClusterWateringStatus `json:"watering_status,omitempty"` - LastWatered time.Time `json:"last_watered,omitempty"` - MoistureLevel float64 `json:"moisture_level,omitempty"` Region string `json:"region,omitempty"` Address string `json:"address,omitempty"` Description string `json:"description,omitempty"` From 3929661137355580d91fc8f399c54f98c2b46a36 Mon Sep 17 00:00:00 2001 From: Cedrik Hoffmann Date: Sat, 14 Sep 2024 21:37:05 +0200 Subject: [PATCH 7/8] chore: run go fmt --- .../http/handler/v1/treecluster/handler.go | 240 +++++++++--------- 1 file changed, 120 insertions(+), 120 deletions(-) diff --git a/internal/server/http/handler/v1/treecluster/handler.go b/internal/server/http/handler/v1/treecluster/handler.go index bdd5f0a5c..7b2eb7958 100644 --- a/internal/server/http/handler/v1/treecluster/handler.go +++ b/internal/server/http/handler/v1/treecluster/handler.go @@ -7,22 +7,22 @@ import ( "github.com/green-ecolution/green-ecolution-backend/internal/service" ) -// @Summary Get all tree clusters -// @Description Get all tree clusters -// @Id get-all-tree-clusters -// @Tags Tree Cluster -// @Produce json -// @Success 200 {object} treecluster.TreeClusterListResponse -// @Failure 400 {object} HTTPError -// @Failure 401 {object} HTTPError -// @Failure 403 {object} HTTPError -// @Failure 404 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /v1/cluster [get] -// @Param page query string false "Page" -// @Param limit query string false "Limit" -// @Param status query string false "Status" -// @Param Authorization header string true "Insert your access token" default(Bearer ) +// @Summary Get all tree clusters +// @Description Get all tree clusters +// @Id get-all-tree-clusters +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterListResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster [get] +// @Param page query string false "Page" +// @Param limit query string false "Limit" +// @Param status query string false "Status" +// @Param Authorization header string true "Insert your access token" default(Bearer ) func GetAllTreeClusters(_ service.Service) fiber.Handler { return func(c *fiber.Ctx) error { // TODO: Implement @@ -30,20 +30,20 @@ func GetAllTreeClusters(_ service.Service) fiber.Handler { } } -// @Summary Get tree cluster by ID -// @Description Get tree cluster by ID -// @Id get-tree-cluster-by-id -// @Tags Tree Cluster -// @Produce json -// @Success 200 {object} treecluster.TreeClusterResponse -// @Failure 400 {object} HTTPError -// @Failure 401 {object} HTTPError -// @Failure 403 {object} HTTPError -// @Failure 404 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /v1/cluster/{cluster_id} [get] -// @Param cluster_id path string true "Tree Cluster ID" -// @Param Authorization header string true "Insert your access token" default(Bearer ) +// @Summary Get tree cluster by ID +// @Description Get tree cluster by ID +// @Id get-tree-cluster-by-id +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster/{cluster_id} [get] +// @Param cluster_id path string true "Tree Cluster ID" +// @Param Authorization header string true "Insert your access token" default(Bearer ) func GetTreeClusterByID(_ service.Service) fiber.Handler { return func(c *fiber.Ctx) error { // TODO: Implement @@ -51,20 +51,20 @@ func GetTreeClusterByID(_ service.Service) fiber.Handler { } } -// @Summary Create tree cluster -// @Description Create tree cluster -// @Id create-tree-cluster -// @Tags Tree Cluster -// @Produce json -// @Success 200 {object} treecluster.TreeClusterResponse -// @Failure 400 {object} HTTPError -// @Failure 401 {object} HTTPError -// @Failure 403 {object} HTTPError -// @Failure 404 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /v1/cluster [post] -// @Param body body treecluster.TreeClusterCreateRequest true "Tree Cluster Create Request" -// @Param Authorization header string true "Insert your access token" default(Bearer ) +// @Summary Create tree cluster +// @Description Create tree cluster +// @Id create-tree-cluster +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster [post] +// @Param body body treecluster.TreeClusterCreateRequest true "Tree Cluster Create Request" +// @Param Authorization header string true "Insert your access token" default(Bearer ) func CreateTreeCluster(_ service.Service) fiber.Handler { return func(c *fiber.Ctx) error { // TODO: Implement @@ -72,21 +72,21 @@ func CreateTreeCluster(_ service.Service) fiber.Handler { } } -// @Summary Update tree cluster -// @Description Update tree cluster -// @Id update-tree-cluster -// @Tags Tree Cluster -// @Produce json -// @Success 200 {object} treecluster.TreeClusterResponse -// @Failure 400 {object} HTTPError -// @Failure 401 {object} HTTPError -// @Failure 403 {object} HTTPError -// @Failure 404 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /v1/cluster/{cluster_id} [put] -// @Param cluster_id path string true "Tree Cluster ID" -// @Param body body treecluster.TreeClusterUpdateRequest true "Tree Cluster Update Request" -// @Param Authorization header string true "Insert your access token" default(Bearer ) +// @Summary Update tree cluster +// @Description Update tree cluster +// @Id update-tree-cluster +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster/{cluster_id} [put] +// @Param cluster_id path string true "Tree Cluster ID" +// @Param body body treecluster.TreeClusterUpdateRequest true "Tree Cluster Update Request" +// @Param Authorization header string true "Insert your access token" default(Bearer ) func UpdateTreeCluster(_ service.Service) fiber.Handler { return func(c *fiber.Ctx) error { // TODO: Implement @@ -94,20 +94,20 @@ func UpdateTreeCluster(_ service.Service) fiber.Handler { } } -// @Summary Delete tree cluster -// @Description Delete tree cluster -// @Id delete-tree-cluster -// @Tags Tree Cluster -// @Produce json -// @Success 200 {object} treecluster.TreeClusterResponse -// @Failure 400 {object} HTTPError -// @Failure 401 {object} HTTPError -// @Failure 403 {object} HTTPError -// @Failure 404 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /v1/cluster/{cluster_id} [delete] -// @Param cluster_id path string true "Tree Cluster ID" -// @Param Authorization header string true "Insert your access token" default(Bearer ) +// @Summary Delete tree cluster +// @Description Delete tree cluster +// @Id delete-tree-cluster +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster/{cluster_id} [delete] +// @Param cluster_id path string true "Tree Cluster ID" +// @Param Authorization header string true "Insert your access token" default(Bearer ) func DeleteTreeCluster(_ service.Service) fiber.Handler { return func(c *fiber.Ctx) error { // TODO: Implement @@ -115,23 +115,23 @@ func DeleteTreeCluster(_ service.Service) fiber.Handler { } } -// @Summary Get all trees in tree cluster -// @Description Get all trees in tree cluster -// @Id get-all-trees-in-tree-cluster -// @Tags Tree Cluster -// @Produce json -// @Success 200 {object} tree.TreeResponse -// @Failure 400 {object} HTTPError -// @Failure 401 {object} HTTPError -// @Failure 403 {object} HTTPError -// @Failure 404 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /v1/cluster/{cluster_id}/trees [get] -// @Param cluster_id path string true "Tree Cluster ID" -// @Param page query string false "Page" -// @Param limit query string false "Limit" -// @Param age query string false "Age" -// @Param Authorization header string true "Insert your access token" default(Bearer ) +// @Summary Get all trees in tree cluster +// @Description Get all trees in tree cluster +// @Id get-all-trees-in-tree-cluster +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} tree.TreeResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster/{cluster_id}/trees [get] +// @Param cluster_id path string true "Tree Cluster ID" +// @Param page query string false "Page" +// @Param limit query string false "Limit" +// @Param age query string false "Age" +// @Param Authorization header string true "Insert your access token" default(Bearer ) func GetTreesInTreeCluster(_ service.Service) fiber.Handler { // TODO: Change response @Success to tree.TreeListResponse return func(c *fiber.Ctx) error { @@ -140,21 +140,21 @@ func GetTreesInTreeCluster(_ service.Service) fiber.Handler { } } -// @Summary Add trees to tree cluster -// @Description Add trees to tree cluster -// @Id add-trees-to-tree-cluster -// @Tags Tree Cluster -// @Produce json -// @Success 200 {object} treecluster.TreeClusterResponse -// @Failure 400 {object} HTTPError -// @Failure 401 {object} HTTPError -// @Failure 403 {object} HTTPError -// @Failure 404 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /v1/cluster/{cluster_id}/trees [post] -// @Param cluster_id path string true "Tree Cluster ID" -// @Param body body treecluster.TreeClusterAddTreesRequest true "Tree Cluster Add Trees Request" -// @Param Authorization header string true "Insert your access token" default(Bearer ) +// @Summary Add trees to tree cluster +// @Description Add trees to tree cluster +// @Id add-trees-to-tree-cluster +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster/{cluster_id}/trees [post] +// @Param cluster_id path string true "Tree Cluster ID" +// @Param body body treecluster.TreeClusterAddTreesRequest true "Tree Cluster Add Trees Request" +// @Param Authorization header string true "Insert your access token" default(Bearer ) func AddTreesToTreeCluster(_ service.Service) fiber.Handler { return func(c *fiber.Ctx) error { // TODO: Implement @@ -162,21 +162,21 @@ func AddTreesToTreeCluster(_ service.Service) fiber.Handler { } } -// @Summary Remove trees from tree cluster -// @Description Remove trees from tree cluster -// @Id remove-trees-from-tree-cluster -// @Tags Tree Cluster -// @Produce json -// @Success 200 {object} treecluster.TreeClusterResponse -// @Failure 400 {object} HTTPError -// @Failure 401 {object} HTTPError -// @Failure 403 {object} HTTPError -// @Failure 404 {object} HTTPError -// @Failure 500 {object} HTTPError -// @Router /v1/cluster/{cluster_id}/trees/{tree_id} [delete] -// @Param cluster_id path string true "Tree Cluster ID" -// @Param tree_id path string true "Tree ID" -// @Param Authorization header string true "Insert your access token" default(Bearer ) +// @Summary Remove trees from tree cluster +// @Description Remove trees from tree cluster +// @Id remove-trees-from-tree-cluster +// @Tags Tree Cluster +// @Produce json +// @Success 200 {object} treecluster.TreeClusterResponse +// @Failure 400 {object} HTTPError +// @Failure 401 {object} HTTPError +// @Failure 403 {object} HTTPError +// @Failure 404 {object} HTTPError +// @Failure 500 {object} HTTPError +// @Router /v1/cluster/{cluster_id}/trees/{tree_id} [delete] +// @Param cluster_id path string true "Tree Cluster ID" +// @Param tree_id path string true "Tree ID" +// @Param Authorization header string true "Insert your access token" default(Bearer ) func RemoveTreesFromTreeCluster(_ service.Service) fiber.Handler { return func(c *fiber.Ctx) error { // TODO: Implement From d6e471f7251f7095b0268df11284d1b53d27589f Mon Sep 17 00:00:00 2001 From: Cedrik Hoffmann Date: Sat, 14 Sep 2024 22:12:16 +0200 Subject: [PATCH 8/8] chore: go fmt --- internal/server/http/router.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/server/http/router.go b/internal/server/http/router.go index fceb4e8b0..c9a86ab73 100644 --- a/internal/server/http/router.go +++ b/internal/server/http/router.go @@ -5,9 +5,9 @@ import ( "github.com/gofiber/swagger" "github.com/green-ecolution/green-ecolution-backend/internal/server/http/handler/v1/auth" "github.com/green-ecolution/green-ecolution-backend/internal/server/http/handler/v1/info" - "github.com/green-ecolution/green-ecolution-backend/internal/server/http/handler/v1/treecluster" "github.com/green-ecolution/green-ecolution-backend/internal/server/http/handler/v1/sensor" "github.com/green-ecolution/green-ecolution-backend/internal/server/http/handler/v1/tree" + "github.com/green-ecolution/green-ecolution-backend/internal/server/http/handler/v1/treecluster" "github.com/green-ecolution/green-ecolution-backend/internal/server/http/middleware" )