UPDATE: Entity, Geo, Wiki
Some checks failed
Build and Release / release (push) Failing after 1m7s

This commit is contained in:
2026-04-22 17:45:09 +07:00
parent f127e2f029
commit adb65d8292
50 changed files with 3354 additions and 119 deletions

View File

@@ -0,0 +1,83 @@
package controllers
import (
"context"
"history-api/internal/dtos/request"
"history-api/internal/dtos/response"
"history-api/internal/services"
"history-api/pkg/validator"
"time"
"github.com/gofiber/fiber/v3"
)
type EntityController struct {
service services.EntityService
}
func NewEntityController(svc services.EntityService) *EntityController {
return &EntityController{service: svc}
}
// GetEntityById handles fetching a single entity by ID.
// @Summary Get entity by ID
// @Description Get detailed information about a specific entity
// @Tags Entities
// @Accept json
// @Produce json
// @Param id path string true "Entity ID"
// @Success 200 {object} response.CommonResponse
// @Failure 500 {object} response.CommonResponse
// @Router /entities/{id} [get]
func (h *EntityController) GetEntityById(c fiber.Ctx) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
id := c.Params("id")
res, err := h.service.GetEntityByID(ctx, id)
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(response.CommonResponse{
Status: false,
Message: err.Error(),
})
}
return c.Status(fiber.StatusOK).JSON(response.CommonResponse{
Status: true,
Data: res,
})
}
// SearchEntities handles searching for entities.
// @Summary Search entities
// @Description Search entities with cursor pagination
// @Tags Entities
// @Accept json
// @Produce json
// @Param query query request.SearchEntityDto false "Search Query"
// @Success 200 {object} response.CommonResponse
// @Failure 500 {object} response.CommonResponse
// @Router /entities [get]
func (h *EntityController) SearchEntities(c fiber.Ctx) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
dto := &request.SearchEntityDto{}
if err := validator.ValidateQueryDto(c, dto); err != nil {
return c.Status(fiber.StatusBadRequest).JSON(response.CommonResponse{
Status: false,
Errors: err,
})
}
res, err := h.service.SearchEntities(ctx, dto)
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(response.CommonResponse{
Status: false,
Message: err.Error(),
})
}
return c.Status(fiber.StatusOK).JSON(response.CommonResponse{
Status: true,
Data: res,
})
}

View File

@@ -0,0 +1,83 @@
package controllers
import (
"context"
"history-api/internal/dtos/request"
"history-api/internal/dtos/response"
"history-api/internal/services"
"history-api/pkg/validator"
"time"
"github.com/gofiber/fiber/v3"
)
type GeometryController struct {
service services.GeometryService
}
func NewGeometryController(svc services.GeometryService) *GeometryController {
return &GeometryController{service: svc}
}
// GetGeometryById handles fetching a single geometry by ID.
// @Summary Get geometry by ID
// @Description Get detailed information about a specific geometry
// @Tags Geometries
// @Accept json
// @Produce json
// @Param id path string true "Geometry ID"
// @Success 200 {object} response.CommonResponse
// @Failure 500 {object} response.CommonResponse
// @Router /geometries/{id} [get]
func (h *GeometryController) GetGeometryById(c fiber.Ctx) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
id := c.Params("id")
res, err := h.service.GetGeometryByID(ctx, id)
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(response.CommonResponse{
Status: false,
Message: err.Error(),
})
}
return c.Status(fiber.StatusOK).JSON(response.CommonResponse{
Status: true,
Data: res,
})
}
// SearchGeometries handles searching for geometries.
// @Summary Search geometries
// @Description Search geometries with cursor pagination and spatial filtering
// @Tags Geometries
// @Accept json
// @Produce json
// @Param query query request.SearchGeometryDto false "Search Query"
// @Success 200 {object} response.CommonResponse
// @Failure 500 {object} response.CommonResponse
// @Router /geometries [get]
func (h *GeometryController) SearchGeometries(c fiber.Ctx) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
dto := &request.SearchGeometryDto{}
if err := validator.ValidateQueryDto(c, dto); err != nil {
return c.Status(fiber.StatusBadRequest).JSON(response.CommonResponse{
Status: false,
Errors: err,
})
}
res, err := h.service.SearchGeometries(ctx, dto)
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(response.CommonResponse{
Status: false,
Message: err.Error(),
})
}
return c.Status(fiber.StatusOK).JSON(response.CommonResponse{
Status: true,
Data: res,
})
}

View File

@@ -0,0 +1,83 @@
package controllers
import (
"context"
"history-api/internal/dtos/request"
"history-api/internal/dtos/response"
"history-api/internal/services"
"history-api/pkg/validator"
"time"
"github.com/gofiber/fiber/v3"
)
type WikiController struct {
service services.WikiService
}
func NewWikiController(svc services.WikiService) *WikiController {
return &WikiController{service: svc}
}
// GetWikiById handles fetching a single wiki by ID.
// @Summary Get wiki by ID
// @Description Get detailed information about a specific wiki
// @Tags Wikis
// @Accept json
// @Produce json
// @Param id path string true "Wiki ID"
// @Success 200 {object} response.CommonResponse
// @Failure 500 {object} response.CommonResponse
// @Router /wikis/{id} [get]
func (h *WikiController) GetWikiById(c fiber.Ctx) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
id := c.Params("id")
res, err := h.service.GetWikiByID(ctx, id)
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(response.CommonResponse{
Status: false,
Message: err.Error(),
})
}
return c.Status(fiber.StatusOK).JSON(response.CommonResponse{
Status: true,
Data: res,
})
}
// SearchWikis handles searching for wikis.
// @Summary Search wikis
// @Description Search wikis with cursor pagination
// @Tags Wikis
// @Accept json
// @Produce json
// @Param query query request.SearchWikiDto false "Search Query"
// @Success 200 {object} response.CommonResponse
// @Failure 500 {object} response.CommonResponse
// @Router /wikis [get]
func (h *WikiController) SearchWikis(c fiber.Ctx) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
dto := &request.SearchWikiDto{}
if err := validator.ValidateQueryDto(c, dto); err != nil {
return c.Status(fiber.StatusBadRequest).JSON(response.CommonResponse{
Status: false,
Errors: err,
})
}
res, err := h.service.SearchWikis(ctx, dto)
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(response.CommonResponse{
Status: false,
Message: err.Error(),
})
}
return c.Status(fiber.StatusOK).JSON(response.CommonResponse{
Status: true,
Data: res,
})
}