feat: завершён этап 3 - API структура Core Service
- Созданы репозитории для locations, items, operations - Реализованы сервисы с бизнес-логикой - Созданы HTTP handlers для всех API endpoints - Добавлена функция GetClaims в middleware - Обновлён server.go для интеграции всех компонентов - Поддержка JSON полей в PostgreSQL - Organization-scope фильтрация во всех операциях - Валидация запросов через validator Готово для этапа 4 - Шаблоны помещений
This commit is contained in:
@@ -23,10 +23,16 @@ type Server struct {
|
||||
router *gin.Engine
|
||||
|
||||
// Services
|
||||
authService service.AuthService
|
||||
authService service.AuthService
|
||||
locationService service.LocationService
|
||||
itemService service.ItemService
|
||||
operationsService service.OperationsService
|
||||
|
||||
// Handlers
|
||||
authHandler *handlers.AuthHandler
|
||||
authHandler *handlers.AuthHandler
|
||||
locationHandler *handlers.LocationHandler
|
||||
itemHandler *handlers.ItemHandler
|
||||
operationsHandler *handlers.OperationsHandler
|
||||
|
||||
// Middleware
|
||||
authMiddleware *middleware.AuthMiddleware
|
||||
@@ -39,24 +45,39 @@ func NewServer(cfg *config.Config, db *sql.DB, log logger.Logger) *Server {
|
||||
// Инициализируем репозитории
|
||||
orgRepo := repository.NewOrganizationRepository(db)
|
||||
userRepo := repository.NewUserRepository(db)
|
||||
locationRepo := repository.NewLocationRepository(db)
|
||||
itemRepo := repository.NewItemRepository(db)
|
||||
operationsRepo := repository.NewOperationsRepository(db)
|
||||
|
||||
// Инициализируем сервисы
|
||||
authService := service.NewAuthService(orgRepo, userRepo, jwtService)
|
||||
locationService := service.NewLocationService(locationRepo)
|
||||
itemService := service.NewItemService(itemRepo)
|
||||
operationsService := service.NewOperationsService(operationsRepo, itemRepo, locationRepo)
|
||||
|
||||
// Инициализируем handlers
|
||||
authHandler := handlers.NewAuthHandler(authService)
|
||||
locationHandler := handlers.NewLocationHandler(locationService)
|
||||
itemHandler := handlers.NewItemHandler(itemService)
|
||||
operationsHandler := handlers.NewOperationsHandler(operationsService)
|
||||
|
||||
// Инициализируем middleware
|
||||
authMiddleware := middleware.NewAuthMiddleware(jwtService)
|
||||
|
||||
server := &Server{
|
||||
config: cfg,
|
||||
db: db,
|
||||
logger: log,
|
||||
router: gin.Default(),
|
||||
authService: authService,
|
||||
authHandler: authHandler,
|
||||
authMiddleware: authMiddleware,
|
||||
config: cfg,
|
||||
db: db,
|
||||
logger: log,
|
||||
router: gin.Default(),
|
||||
authService: authService,
|
||||
locationService: locationService,
|
||||
itemService: itemService,
|
||||
operationsService: operationsService,
|
||||
authHandler: authHandler,
|
||||
locationHandler: locationHandler,
|
||||
itemHandler: itemHandler,
|
||||
operationsHandler: operationsHandler,
|
||||
authMiddleware: authMiddleware,
|
||||
}
|
||||
|
||||
server.setupRoutes()
|
||||
@@ -86,23 +107,29 @@ func (s *Server) setupRoutes() {
|
||||
protected.PUT("/organizations/:id", s.updateOrganization)
|
||||
|
||||
// Locations
|
||||
protected.GET("/locations", s.getLocations)
|
||||
protected.POST("/locations", s.createLocation)
|
||||
protected.GET("/locations/:id", s.getLocation)
|
||||
protected.PUT("/locations/:id", s.updateLocation)
|
||||
protected.DELETE("/locations/:id", s.deleteLocation)
|
||||
protected.GET("/locations", s.locationHandler.GetLocations)
|
||||
protected.POST("/locations", s.locationHandler.CreateLocation)
|
||||
protected.GET("/locations/:id", s.locationHandler.GetLocation)
|
||||
protected.PUT("/locations/:id", s.locationHandler.UpdateLocation)
|
||||
protected.DELETE("/locations/:id", s.locationHandler.DeleteLocation)
|
||||
protected.GET("/locations/:id/children", s.locationHandler.GetChildren)
|
||||
|
||||
// Items
|
||||
protected.GET("/items", s.getItems)
|
||||
protected.POST("/items", s.createItem)
|
||||
protected.GET("/items/:id", s.getItem)
|
||||
protected.PUT("/items/:id", s.updateItem)
|
||||
protected.DELETE("/items/:id", s.deleteItem)
|
||||
protected.GET("/items", s.itemHandler.GetItems)
|
||||
protected.POST("/items", s.itemHandler.CreateItem)
|
||||
protected.GET("/items/:id", s.itemHandler.GetItem)
|
||||
protected.PUT("/items/:id", s.itemHandler.UpdateItem)
|
||||
protected.DELETE("/items/:id", s.itemHandler.DeleteItem)
|
||||
protected.GET("/items/search", s.itemHandler.SearchItems)
|
||||
|
||||
// Operations
|
||||
protected.POST("/operations/place-item", s.placeItem)
|
||||
protected.POST("/operations/move-item", s.moveItem)
|
||||
protected.GET("/operations/search", s.search)
|
||||
protected.POST("/operations/place-item", s.operationsHandler.PlaceItem)
|
||||
protected.POST("/operations/move-item/:id", s.operationsHandler.MoveItem)
|
||||
protected.GET("/operations/search", s.operationsHandler.Search)
|
||||
protected.GET("/operations/items/:item_id/placements", s.operationsHandler.GetItemPlacements)
|
||||
protected.GET("/operations/locations/:location_id/placements", s.operationsHandler.GetLocationPlacements)
|
||||
protected.PUT("/operations/placements/:id/quantity", s.operationsHandler.UpdateQuantity)
|
||||
protected.DELETE("/operations/placements/:id", s.operationsHandler.DeletePlacement)
|
||||
|
||||
// Templates
|
||||
protected.GET("/templates", s.getTemplates)
|
||||
@@ -127,58 +154,6 @@ func (s *Server) updateOrganization(c *gin.Context) {
|
||||
c.JSON(http.StatusNotImplemented, gin.H{"error": "Not implemented yet"})
|
||||
}
|
||||
|
||||
func (s *Server) getLocations(c *gin.Context) {
|
||||
c.JSON(http.StatusNotImplemented, gin.H{"error": "Not implemented yet"})
|
||||
}
|
||||
|
||||
func (s *Server) createLocation(c *gin.Context) {
|
||||
c.JSON(http.StatusNotImplemented, gin.H{"error": "Not implemented yet"})
|
||||
}
|
||||
|
||||
func (s *Server) getLocation(c *gin.Context) {
|
||||
c.JSON(http.StatusNotImplemented, gin.H{"error": "Not implemented yet"})
|
||||
}
|
||||
|
||||
func (s *Server) updateLocation(c *gin.Context) {
|
||||
c.JSON(http.StatusNotImplemented, gin.H{"error": "Not implemented yet"})
|
||||
}
|
||||
|
||||
func (s *Server) deleteLocation(c *gin.Context) {
|
||||
c.JSON(http.StatusNotImplemented, gin.H{"error": "Not implemented yet"})
|
||||
}
|
||||
|
||||
func (s *Server) getItems(c *gin.Context) {
|
||||
c.JSON(http.StatusNotImplemented, gin.H{"error": "Not implemented yet"})
|
||||
}
|
||||
|
||||
func (s *Server) createItem(c *gin.Context) {
|
||||
c.JSON(http.StatusNotImplemented, gin.H{"error": "Not implemented yet"})
|
||||
}
|
||||
|
||||
func (s *Server) getItem(c *gin.Context) {
|
||||
c.JSON(http.StatusNotImplemented, gin.H{"error": "Not implemented yet"})
|
||||
}
|
||||
|
||||
func (s *Server) updateItem(c *gin.Context) {
|
||||
c.JSON(http.StatusNotImplemented, gin.H{"error": "Not implemented yet"})
|
||||
}
|
||||
|
||||
func (s *Server) deleteItem(c *gin.Context) {
|
||||
c.JSON(http.StatusNotImplemented, gin.H{"error": "Not implemented yet"})
|
||||
}
|
||||
|
||||
func (s *Server) placeItem(c *gin.Context) {
|
||||
c.JSON(http.StatusNotImplemented, gin.H{"error": "Not implemented yet"})
|
||||
}
|
||||
|
||||
func (s *Server) moveItem(c *gin.Context) {
|
||||
c.JSON(http.StatusNotImplemented, gin.H{"error": "Not implemented yet"})
|
||||
}
|
||||
|
||||
func (s *Server) search(c *gin.Context) {
|
||||
c.JSON(http.StatusNotImplemented, gin.H{"error": "Not implemented yet"})
|
||||
}
|
||||
|
||||
func (s *Server) getTemplates(c *gin.Context) {
|
||||
c.JSON(http.StatusNotImplemented, gin.H{"error": "Not implemented yet"})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user