From b3aabdf285baeb9b5d9481491cad287604389644 Mon Sep 17 00:00:00 2001 From: Denis Istratov Date: Sat, 26 Oct 2024 12:00:00 +0300 Subject: [PATCH] update config.yml, handler.go --- configs/config.yml | 6 ++++ pkg/handler/handler.go | 70 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 configs/config.yml create mode 100644 pkg/handler/handler.go diff --git a/configs/config.yml b/configs/config.yml new file mode 100644 index 0000000..2e323a1 --- /dev/null +++ b/configs/config.yml @@ -0,0 +1,6 @@ +port: "8012" +db: + host: "mysql-pl-wa10.joinserver.xyz" + port: "3306" + username: "u45925_HjjJCz8EVf" + dbname: "s45925_tentula" \ No newline at end of file diff --git a/pkg/handler/handler.go b/pkg/handler/handler.go new file mode 100644 index 0000000..b2010be --- /dev/null +++ b/pkg/handler/handler.go @@ -0,0 +1,70 @@ +package handler + +import ( + "esaccount/pkg/repository" + "esaccount/pkg/service" + "net/http" + + "esaccount/docs" + + "github.com/gin-gonic/gin" + swaggerFiles "github.com/swaggo/files" + ginSwagger "github.com/swaggo/gin-swagger" +) + +type Handler struct { + services *service.Service + repo *repository.Repository +} + +func NewHandler(services *service.Service, repo *repository.Repository) *Handler { + return &Handler{services: services, repo: repo} +} + +// @title EasyStartup Account +// @version 1.0 +// @description Account service for EasyStartup. +// +// @contact.name API Support +// @contact.email red.tea.dev@gmail.com +// +// @host account.easystartup.su +// @BasePath /api +// + +func (h *Handler) InitRoutes() *gin.Engine { + router := gin.New() + docs.SwaggerInfo.BasePath = "/" + + router.StaticFS("/static", http.Dir("./public/usercontent")) + + router.GET("/api/public/:id", h.getPublic) + account := router.Group("/api/account", h.userIdentity) + { + account.GET("/", h.getAccount) + account.POST("/", h.editAccount) //edit + account.POST("/picture", h.picture) + + //admin + account.GET("/:id", h.getAccountById) + account.POST("/:id", h.editAccountById) //edit + account.DELETE("/:id", h.delete) + } + + conf := router.Group("/api/confidential", h.userIdentity) + { + conf.GET("/", h.getConfidential) + conf.POST("/", h.setConfidential) + conf.GET("/:id", h.getConfidentialById) + conf.POST("/:id", h.setConfidentialById) + } + + following := router.Group("/api/following", h.userIdentity) + { + following.PUT("/follow/:id", h.follow) + following.PUT("/unfollow/:id", h.unfollow) + } + + router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) + return router +}