- Удалены зависимости: grpc, redis, prometheus - Упрощена конфигурация (Server, Database, JWT) - Создан логгер на основе logrus - Добавлено подключение к PostgreSQL - Создана миграция с базовыми таблицами - Обновлены модели с валидацией - Создан базовый API сервер с health check - Добавлен .env.example Готово для этапа 2 - Аутентификация
180 lines
4.6 KiB
Go
180 lines
4.6 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"net/http"
|
|
|
|
"erp-mvp/core-service/internal/config"
|
|
"erp-mvp/core-service/internal/logger"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type Server struct {
|
|
config *config.Config
|
|
db *sql.DB
|
|
logger logger.Logger
|
|
router *gin.Engine
|
|
}
|
|
|
|
func NewServer(cfg *config.Config, db *sql.DB, log logger.Logger) *Server {
|
|
server := &Server{
|
|
config: cfg,
|
|
db: db,
|
|
logger: log,
|
|
router: gin.Default(),
|
|
}
|
|
|
|
server.setupRoutes()
|
|
return server
|
|
}
|
|
|
|
func (s *Server) setupRoutes() {
|
|
// Health check
|
|
s.router.GET("/health", s.healthCheck)
|
|
|
|
// API routes
|
|
api := s.router.Group("/api")
|
|
{
|
|
// Auth routes
|
|
auth := api.Group("/auth")
|
|
{
|
|
auth.POST("/register", s.register)
|
|
auth.POST("/login", s.login)
|
|
}
|
|
|
|
// Protected routes
|
|
protected := api.Group("/")
|
|
protected.Use(s.authMiddleware())
|
|
{
|
|
// Organizations
|
|
protected.GET("/organizations/:id", s.getOrganization)
|
|
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)
|
|
|
|
// 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)
|
|
|
|
// Operations
|
|
protected.POST("/operations/place-item", s.placeItem)
|
|
protected.POST("/operations/move-item", s.moveItem)
|
|
protected.GET("/operations/search", s.search)
|
|
|
|
// Templates
|
|
protected.GET("/templates", s.getTemplates)
|
|
protected.POST("/templates/:id/apply", s.applyTemplate)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (s *Server) healthCheck(c *gin.Context) {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"status": "ok",
|
|
"service": "erp-mvp-core",
|
|
})
|
|
}
|
|
|
|
// Placeholder handlers - will be implemented in next stages
|
|
func (s *Server) register(c *gin.Context) {
|
|
c.JSON(http.StatusNotImplemented, gin.H{"error": "Not implemented yet"})
|
|
}
|
|
|
|
func (s *Server) login(c *gin.Context) {
|
|
c.JSON(http.StatusNotImplemented, gin.H{"error": "Not implemented yet"})
|
|
}
|
|
|
|
func (s *Server) authMiddleware() gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "Auth not implemented yet"})
|
|
c.Abort()
|
|
}
|
|
}
|
|
|
|
func (s *Server) getOrganization(c *gin.Context) {
|
|
c.JSON(http.StatusNotImplemented, gin.H{"error": "Not implemented yet"})
|
|
}
|
|
|
|
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"})
|
|
}
|
|
|
|
func (s *Server) applyTemplate(c *gin.Context) {
|
|
c.JSON(http.StatusNotImplemented, gin.H{"error": "Not implemented yet"})
|
|
}
|
|
|
|
func (s *Server) Start() error {
|
|
return s.router.Run(s.config.Server.Host + ":" + s.config.Server.Port)
|
|
}
|
|
|
|
func (s *Server) Shutdown(ctx context.Context) error {
|
|
// Graceful shutdown logic will be added later
|
|
return nil
|
|
}
|