added routes package and serve in server package
This commit is contained in:
1 parent
303b9344f8
commit
547949795f
8 files changed
+74
-77
No files matched your search
@@ -1,41 +0,0 @@
|
|||||||
package category
|
|
||||||
|
|
||||||
import "backend/model"
|
|
||||||
|
|
||||||
func GetAllCategories() ([]model.Category, error) {
|
|
||||||
return []model.Category{
|
|
||||||
{
|
|
||||||
Title: "Electronics",
|
|
||||||
Icon: "😀",
|
|
||||||
Type: "expense",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Title: "Clothing",
|
|
||||||
Icon: "😁",
|
|
||||||
Type: "expense",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Title: "Books",
|
|
||||||
Icon: "😂",
|
|
||||||
Subcategories: []model.Subcategory{
|
|
||||||
{
|
|
||||||
Title: "Fiction",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Title: "Non-Fiction",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Type: "expense",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Title: "Salary",
|
|
||||||
Icon: "😀",
|
|
||||||
Type: "income",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Title: "asdf",
|
|
||||||
Icon: "😀",
|
|
||||||
Type: "income",
|
|
||||||
},
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
+1
-22
@@ -2,33 +2,12 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"backend/server"
|
"backend/server"
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := fiber.New()
|
app := fiber.New()
|
||||||
|
|
||||||
server.Configure(app)
|
server.Configure(app)
|
||||||
|
server.Serve(app)
|
||||||
enableTls, err := strconv.ParseBool(os.Getenv("ENABLE_TLS"))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("error read tls configuration, %v", err)
|
|
||||||
}
|
|
||||||
if enableTls {
|
|
||||||
log.Fatal(
|
|
||||||
app.ListenTLS(
|
|
||||||
os.Getenv("HTTP_ADDRESS"),
|
|
||||||
os.Getenv("CERT_FILE"),
|
|
||||||
os.Getenv("KEY_FILE"),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
log.Fatal(
|
|
||||||
app.Listen(os.Getenv("HTTP_ADDRESS")),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package routes
|
||||||
|
|
||||||
|
import (
|
||||||
|
"backend/api"
|
||||||
|
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CategoryRoutes(group fiber.Router) {
|
||||||
|
categoryGroup := group.Group("/category")
|
||||||
|
categoryGroup.Get("/", api.GetAllCategories)
|
||||||
|
categoryGroup.Post("/", api.CreateCategory)
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package routes
|
||||||
|
|
||||||
|
import (
|
||||||
|
"backend/api"
|
||||||
|
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func OperationRoutes(group fiber.Router) {
|
||||||
|
operationGroup := group.Group("/operation")
|
||||||
|
operationGroup.Get("/", api.GetAllOperation)
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package routes
|
||||||
|
|
||||||
|
import (
|
||||||
|
"backend/api"
|
||||||
|
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func UsersRoutes(group fiber.Router) {
|
||||||
|
usersGroup := group.Group("/users")
|
||||||
|
usersGroup.Get("/", api.GetAllUsers)
|
||||||
|
usersGroup.Get("/user", api.GetUserData)
|
||||||
|
}
|
||||||
@@ -12,9 +12,9 @@ func InitMiddlewares(app *fiber.App) {
|
|||||||
app.Use(
|
app.Use(
|
||||||
cors.New(
|
cors.New(
|
||||||
cors.Config{
|
cors.Config{
|
||||||
AllowOrigins: "https://localhost:3000,https://localhost:43243",
|
AllowOrigins: "*",
|
||||||
AllowHeaders: "*",
|
AllowHeaders: "*",
|
||||||
AllowCredentials: true,
|
AllowCredentials: false,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
jwtware.New(
|
jwtware.New(
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package server
|
|||||||
import (
|
import (
|
||||||
"backend/api"
|
"backend/api"
|
||||||
"backend/database"
|
"backend/database"
|
||||||
|
"backend/routes"
|
||||||
"backend/utils"
|
"backend/utils"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
@@ -13,21 +14,12 @@ func Configure(app *fiber.App) {
|
|||||||
utils.LoadEnv("wallet.conf")
|
utils.LoadEnv("wallet.conf")
|
||||||
database.InitDatabase()
|
database.InitDatabase()
|
||||||
log.SetLevel(log.LevelDebug)
|
log.SetLevel(log.LevelDebug)
|
||||||
|
|
||||||
app.Static("/", "../frontend/build")
|
app.Static("/", "../frontend/build")
|
||||||
apiGroup := app.Group("/api")
|
apiGroup := app.Group("/api")
|
||||||
|
|
||||||
apiGroup.Post("/token", api.Login)
|
apiGroup.Post("/token", api.Login)
|
||||||
InitMiddlewares(app)
|
InitMiddlewares(app)
|
||||||
|
|
||||||
usersGroup := apiGroup.Group("/users")
|
routes.UsersRoutes(apiGroup)
|
||||||
usersGroup.Get("/", api.GetAllUsers)
|
routes.OperationRoutes(apiGroup)
|
||||||
usersGroup.Get("/user", api.GetUserData)
|
routes.CategoryRoutes(apiGroup)
|
||||||
|
|
||||||
operationGroup := apiGroup.Group("/operation")
|
|
||||||
operationGroup.Get("/", api.GetAllOperation)
|
|
||||||
|
|
||||||
categoryGroup := apiGroup.Group("/category")
|
|
||||||
categoryGroup.Get("/", api.GetAllCategories)
|
|
||||||
categoryGroup.Post("/", api.CreateCategory)
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Serve(app *fiber.App) {
|
||||||
|
enableTls, err := strconv.ParseBool(os.Getenv("ENABLE_TLS"))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("error read tls configuration, %v", err)
|
||||||
|
}
|
||||||
|
if enableTls {
|
||||||
|
log.Fatal(
|
||||||
|
app.ListenTLS(
|
||||||
|
os.Getenv("HTTP_ADDRESS"),
|
||||||
|
os.Getenv("CERT_FILE"),
|
||||||
|
os.Getenv("KEY_FILE"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
log.Fatal(
|
||||||
|
app.Listen(os.Getenv("HTTP_ADDRESS")),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user