2024-01-16 00:36:49 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"azote-backend/api"
|
|
|
|
"azote-backend/controllers"
|
|
|
|
"azote-backend/initializers"
|
2024-01-18 23:45:06 +01:00
|
|
|
"azote-backend/middleware"
|
2024-01-16 00:36:49 +01:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2024-02-28 09:13:08 +01:00
|
|
|
var currentMode string
|
|
|
|
|
2024-01-16 00:36:49 +01:00
|
|
|
func init() {
|
|
|
|
initializers.LoadEnv()
|
2024-02-28 09:13:08 +01:00
|
|
|
currentMode = os.Getenv("GIN_MODE")
|
|
|
|
if currentMode == "debug" {
|
|
|
|
initializers.CreateAssetsFolder(initializers.DebugBasePath)
|
|
|
|
} else {
|
|
|
|
initializers.CreateAssetsFolder(initializers.ReleaseBasePath)
|
|
|
|
}
|
2024-01-16 00:36:49 +01:00
|
|
|
initializers.ConnectToDB()
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
gin.SetMode(os.Getenv("GIN_MODE"))
|
|
|
|
|
|
|
|
api.CreateRouter()
|
|
|
|
|
|
|
|
// Auth
|
|
|
|
api.Api.POST("/signup", controllers.Signup)
|
|
|
|
api.Api.POST("/login", controllers.Login)
|
2024-03-01 00:46:18 +01:00
|
|
|
api.Api.GET("/validate", middleware.RequireAuth, controllers.ValidateToken)
|
2024-01-16 00:36:49 +01:00
|
|
|
|
|
|
|
// Users
|
2024-03-04 17:07:01 +01:00
|
|
|
api.Api.GET("/users", middleware.RequireAuth, controllers.GetUsers)
|
|
|
|
api.Api.GET("/users/:id", middleware.RequireAuth, controllers.GetUserById)
|
2024-03-07 04:35:55 +01:00
|
|
|
api.Api.PUT("/users", middleware.RequireAuth, controllers.UpdateUser)
|
2024-01-16 00:36:49 +01:00
|
|
|
|
|
|
|
// Files
|
2024-02-28 09:13:08 +01:00
|
|
|
if currentMode == "debug" {
|
2024-03-02 00:04:00 +01:00
|
|
|
api.Router.Static("assets", initializers.DebugBasePath)
|
2024-02-28 09:13:08 +01:00
|
|
|
} else {
|
2024-03-02 00:04:00 +01:00
|
|
|
api.Router.Static("assets", initializers.ReleaseBasePath)
|
2024-02-28 09:13:08 +01:00
|
|
|
}
|
2024-01-16 00:36:49 +01:00
|
|
|
|
2024-02-28 09:13:08 +01:00
|
|
|
// Posts
|
2024-01-18 23:45:06 +01:00
|
|
|
api.Api.POST("/posts", middleware.RequireAuth, controllers.CreatePost)
|
2024-03-04 17:07:01 +01:00
|
|
|
api.Api.GET("/posts", middleware.RequireAuth, controllers.GetPosts)
|
|
|
|
api.Api.GET("/posts/:id", middleware.RequireAuth, controllers.GetPostById)
|
2024-01-16 00:36:49 +01:00
|
|
|
|
|
|
|
// Starting
|
|
|
|
err := api.Router.Run()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Router could not be created!\n" + err.Error())
|
|
|
|
}
|
|
|
|
}
|