awesome-back/cmd/main.go

61 lines
1.8 KiB
Go
Raw Normal View History

2025-10-16 12:55:36 +03:00
package main
import (
2025-10-16 12:57:19 +03:00
"code.linberg.su/linberg/awesome-back/internal/datastore"
"code.linberg.su/linberg/awesome-back/internal/handler"
"code.linberg.su/linberg/awesome-back/internal/service"
2025-10-16 12:55:36 +03:00
"github.com/gin-gonic/gin"
)
func main() {
// Инициализация репозиториев
coffeeRepo := datastore.NewMockCoffeeRepository()
pastryRepo := datastore.NewMockPastryRepository()
orderRepo := datastore.NewMockOrderRepository()
// Инициализация сервисов
coffeeService := service.NewCoffeeService(coffeeRepo)
pastryService := service.NewPastryService(pastryRepo)
orderService := service.NewOrderService(orderRepo)
// Инициализация обработчиков
coffeeHandler := handler.NewCoffeeHandler(coffeeService)
pastryHandler := handler.NewPastryHandler(pastryService)
orderHandler := handler.NewOrderHandler(orderService)
// Настройка маршрутов
router := gin.Default()
setupRoutes(router, coffeeHandler, pastryHandler, orderHandler)
router.Run(":8080")
}
func setupRoutes(router *gin.Engine, coffeeHandler *handler.CoffeeHandler, pastryHandler *handler.PastryHandler, orderHandler *handler.OrderHandler) {
api := router.Group("/api/v1")
{
// Кофе
coffeeRoutes := api.Group("/coffees")
{
coffeeRoutes.GET("/", coffeeHandler.GetCoffees)
coffeeRoutes.GET("/:id", coffeeHandler.GetCoffeeByID)
}
// Выпечка
pastryRoutes := api.Group("/pastries")
{
pastryRoutes.GET("/", pastryHandler.GetPastries)
pastryRoutes.GET("/:id", pastryHandler.GetPastryByID)
pastryRoutes.GET("/category/:category", pastryHandler.GetPastriesByCategory)
}
// Заказы
orderRoutes := api.Group("/orders")
{
orderRoutes.GET("/", orderHandler.GetOrders)
orderRoutes.GET("/:id", orderHandler.GetOrderByID)
orderRoutes.POST("/", orderHandler.CreateOrder)
}
}
}