2024-08-01 23:03:51 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-11-19 09:13:02 +01:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2024-08-06 13:32:10 +02:00
|
|
|
"time"
|
|
|
|
|
2024-08-02 17:14:06 +02:00
|
|
|
"github.com/swaggo/files"
|
|
|
|
"github.com/swaggo/gin-swagger"
|
2024-08-01 23:03:51 +02:00
|
|
|
|
2024-11-19 09:13:02 +01:00
|
|
|
"git.qowevisa.me/Qowevisa/fin-check-api/db"
|
2024-11-04 16:55:14 +01:00
|
|
|
docs "git.qowevisa.me/Qowevisa/fin-check-api/docs"
|
|
|
|
"git.qowevisa.me/Qowevisa/fin-check-api/handlers"
|
|
|
|
"git.qowevisa.me/Qowevisa/fin-check-api/middleware"
|
|
|
|
"git.qowevisa.me/Qowevisa/fin-check-api/tokens"
|
2024-08-06 13:32:10 +02:00
|
|
|
"github.com/gin-contrib/cors"
|
2024-08-02 17:14:06 +02:00
|
|
|
"github.com/gin-gonic/gin"
|
2024-08-01 23:03:51 +02:00
|
|
|
)
|
|
|
|
|
2024-08-02 17:14:06 +02:00
|
|
|
// @title Swagger Example API
|
|
|
|
// @version 1.0
|
|
|
|
// @description This is a sample server celler server.
|
|
|
|
// @termsOfService http://swagger.io/terms/
|
|
|
|
|
|
|
|
// @contact.name API Support
|
|
|
|
// @contact.url http://www.swagger.io/support
|
|
|
|
// @contact.email support@swagger.io
|
|
|
|
|
|
|
|
// @license.name Apache 2.0
|
|
|
|
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
|
|
|
|
|
2024-08-08 19:30:59 +02:00
|
|
|
// @host gonapi.qowevisa.click
|
2024-08-02 17:14:06 +02:00
|
|
|
// @BasePath /api
|
2024-08-01 23:03:51 +02:00
|
|
|
func main() {
|
2024-11-19 09:13:02 +01:00
|
|
|
if err := db.Init(); err != nil {
|
|
|
|
fmt.Printf("ERROR: db.Init: %v\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2024-08-02 17:14:06 +02:00
|
|
|
r := gin.Default()
|
|
|
|
docs.SwaggerInfo.BasePath = "/api"
|
2024-08-06 13:32:10 +02:00
|
|
|
r.Use(cors.New(cors.Config{
|
2024-11-06 18:43:43 +01:00
|
|
|
AllowOrigins: []string{"http://localhost:5173"},
|
2024-08-06 21:51:34 +02:00
|
|
|
AllowMethods: []string{"GET", "DELETE", "PUT", "PATCH", "OPTIONS"},
|
2024-08-14 14:05:55 +02:00
|
|
|
AllowHeaders: []string{"Origin", "Content-Type"},
|
2024-08-06 13:32:10 +02:00
|
|
|
ExposeHeaders: []string{"Content-Length"},
|
|
|
|
AllowCredentials: true,
|
2024-08-06 21:51:34 +02:00
|
|
|
MaxAge: 12 * time.Hour,
|
2024-08-06 13:32:10 +02:00
|
|
|
}))
|
2024-08-02 17:14:06 +02:00
|
|
|
|
|
|
|
// Routes defined in the routes package
|
2024-08-02 23:07:14 +02:00
|
|
|
api := r.Group("/api")
|
2024-08-02 17:14:06 +02:00
|
|
|
{
|
2024-08-06 21:51:34 +02:00
|
|
|
api.GET("/ping", handlers.PingGet)
|
2024-11-06 18:43:20 +01:00
|
|
|
api.GET("/authping", middleware.AuthMiddleware(), handlers.PingGet)
|
2024-08-02 23:07:14 +02:00
|
|
|
userRoutes := api.Group("/user")
|
2024-08-02 23:06:21 +02:00
|
|
|
{
|
|
|
|
userRoutes.POST("/register", handlers.UserRegister)
|
|
|
|
userRoutes.POST("/login", handlers.UserLogin)
|
|
|
|
}
|
2024-08-03 07:43:41 +02:00
|
|
|
cardsRoutes := api.Group("/card", middleware.AuthMiddleware())
|
2024-08-03 07:16:55 +02:00
|
|
|
{
|
2024-08-03 07:43:41 +02:00
|
|
|
cardsRoutes.POST("/add", handlers.CardAdd)
|
2024-08-03 08:53:50 +02:00
|
|
|
cardsRoutes.GET("/:id", handlers.CardGetId)
|
2024-11-10 07:25:44 +01:00
|
|
|
cardsRoutes.GET("/all", handlers.CardGetAll)
|
2024-08-03 08:53:50 +02:00
|
|
|
cardsRoutes.PUT("/edit/:id", handlers.CardPutId)
|
|
|
|
cardsRoutes.DELETE("/delete/:id", handlers.CardDeleteId)
|
2024-08-03 07:16:55 +02:00
|
|
|
}
|
2024-08-03 12:40:17 +02:00
|
|
|
categoriesRoutes := api.Group("/category", middleware.AuthMiddleware())
|
|
|
|
{
|
|
|
|
categoriesRoutes.POST("/add", handlers.CategoryAdd)
|
|
|
|
categoriesRoutes.GET("/:id", handlers.CategoryGetId)
|
2024-11-11 21:27:16 +01:00
|
|
|
categoriesRoutes.GET("/all", handlers.CategoryGetAll)
|
2024-08-03 12:40:17 +02:00
|
|
|
categoriesRoutes.PUT("/edit/:id", handlers.CategoryPutId)
|
|
|
|
categoriesRoutes.DELETE("/delete/:id", handlers.CategoryDeleteId)
|
|
|
|
}
|
2024-08-12 17:33:17 +02:00
|
|
|
debtRoutes := api.Group("/debt", middleware.AuthMiddleware())
|
|
|
|
{
|
|
|
|
debtRoutes.POST("/add", handlers.DebtAdd)
|
|
|
|
debtRoutes.GET("/:id", handlers.DebtGetId)
|
|
|
|
debtRoutes.PUT("/edit/:id", handlers.DebtPutId)
|
|
|
|
debtRoutes.DELETE("/delete/:id", handlers.DebtDeleteId)
|
|
|
|
}
|
2024-08-14 17:21:03 +02:00
|
|
|
incomeRoutes := api.Group("/income", middleware.AuthMiddleware())
|
|
|
|
{
|
|
|
|
incomeRoutes.POST("/add", handlers.IncomeAdd)
|
|
|
|
incomeRoutes.GET("/:id", handlers.IncomeGetId)
|
2024-11-19 09:12:04 +01:00
|
|
|
incomeRoutes.GET("/all", handlers.IncomeGetAll)
|
2024-08-14 17:21:03 +02:00
|
|
|
incomeRoutes.PUT("/edit/:id", handlers.IncomePutId)
|
|
|
|
incomeRoutes.DELETE("/delete/:id", handlers.IncomeDeleteId)
|
|
|
|
}
|
2024-10-31 10:41:49 +01:00
|
|
|
typesRoutes := api.Group("/type", middleware.AuthMiddleware())
|
|
|
|
{
|
|
|
|
typesRoutes.POST("/add", handlers.TypeAdd)
|
|
|
|
typesRoutes.GET("/:id", handlers.TypeGetId)
|
2024-11-11 20:30:40 +01:00
|
|
|
typesRoutes.GET("/all", handlers.TypeGetAll)
|
2024-10-31 10:41:49 +01:00
|
|
|
typesRoutes.PUT("/edit/:id", handlers.TypePutId)
|
|
|
|
typesRoutes.DELETE("/delete/:id", handlers.TypeDeleteId)
|
|
|
|
}
|
2024-11-16 10:43:32 +01:00
|
|
|
expensesRoutes := api.Group("/expense", middleware.AuthMiddleware())
|
|
|
|
{
|
|
|
|
expensesRoutes.POST("/add", handlers.ExpenseAdd)
|
|
|
|
expensesRoutes.GET("/:id", handlers.ExpenseGetId)
|
|
|
|
expensesRoutes.GET("/all", handlers.ExpenseGetAll)
|
|
|
|
expensesRoutes.PUT("/edit/:id", handlers.ExpensePutId)
|
|
|
|
expensesRoutes.DELETE("/delete/:id", handlers.ExpenseDeleteId)
|
|
|
|
}
|
2024-11-16 19:31:36 +01:00
|
|
|
transfersRoutes := api.Group("/transfer", middleware.AuthMiddleware())
|
|
|
|
{
|
|
|
|
transfersRoutes.POST("/add", handlers.TransferAdd)
|
|
|
|
transfersRoutes.GET("/:id", handlers.TransferGetId)
|
|
|
|
transfersRoutes.GET("/all", handlers.TransferGetAll)
|
|
|
|
transfersRoutes.PUT("/edit/:id", handlers.TransferPutId)
|
|
|
|
transfersRoutes.DELETE("/delete/:id", handlers.TransferDeleteId)
|
|
|
|
}
|
2024-11-18 08:55:34 +01:00
|
|
|
itemRoutes := api.Group("/item", middleware.AuthMiddleware())
|
|
|
|
{
|
|
|
|
itemRoutes.GET("/:id", handlers.ItemGetId)
|
|
|
|
itemRoutes.GET("/all", handlers.ItemGetAll)
|
|
|
|
itemRoutes.POST("/filter", handlers.ItemPostFilter)
|
|
|
|
itemRoutes.DELETE("/delete/:id", handlers.ItemDeleteId)
|
|
|
|
}
|
2024-11-19 09:13:41 +01:00
|
|
|
metricRoutes := api.Group("/metric", middleware.AuthMiddleware())
|
|
|
|
{
|
|
|
|
metricRoutes.GET("/all", handlers.MetricGetAll)
|
|
|
|
}
|
2024-11-20 17:19:57 +01:00
|
|
|
paymentRoutes := api.Group("/payment", middleware.AuthMiddleware())
|
|
|
|
{
|
|
|
|
paymentRoutes.POST("/add", handlers.PaymentAdd)
|
|
|
|
}
|
2024-11-20 19:29:00 +01:00
|
|
|
currencyRoutes := api.Group("/currency", middleware.AuthMiddleware())
|
|
|
|
{
|
|
|
|
currencyRoutes.GET("/all", handlers.CurrencyGetAll)
|
|
|
|
}
|
2024-08-02 17:14:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
2024-08-03 12:43:58 +02:00
|
|
|
r.GET("/swagger", func(c *gin.Context) {
|
|
|
|
c.Redirect(301, "/swagger/index.html")
|
|
|
|
})
|
|
|
|
r.GET("/docs", func(c *gin.Context) {
|
|
|
|
c.Redirect(301, "/swagger/index.html")
|
|
|
|
})
|
2024-08-02 17:14:06 +02:00
|
|
|
|
2024-08-02 22:37:16 +02:00
|
|
|
go tokens.StartTokens()
|
2024-11-04 16:53:03 +01:00
|
|
|
r.Run("127.0.0.1:3000")
|
2024-08-02 17:14:06 +02:00
|
|
|
}
|