focus/backend/main.go

53 lines
1.4 KiB
Go
Raw Normal View History

2023-12-27 22:23:10 +01:00
package main
import (
"fmt"
"log"
"github.com/gofiber/fiber/v2"
2023-12-27 23:38:06 +01:00
"github.com/gofiber/fiber/v2/middleware/cors"
2023-12-27 22:23:10 +01:00
_ "github.com/mattn/go-sqlite3"
"git.bhasher.com/bhasher/focus/backend/db"
"git.bhasher.com/bhasher/focus/backend/handlers"
)
func main() {
driver := "sqlite3"
connStr := "db.sqlite"
port := "3000"
2023-12-27 23:38:06 +01:00
origins := "*"
2023-12-27 22:23:10 +01:00
if err := db.InitDB(driver, connStr); err != nil {
log.Fatal(err)
}
app := fiber.New()
2023-12-27 23:38:06 +01:00
app.Use(cors.New(cors.Config{
AllowOrigins: origins,
AllowMethods: "GET,POST,PUT,DELETE",
AllowHeaders: "Origin, Content-Type, Accept",
}))
2023-12-29 01:49:09 +01:00
app.Post("/api/project", handlers.CreateProject)
2023-12-28 01:19:29 +01:00
app.Get("/api/projects", handlers.GetAllProjects)
app.Get("/api/project/:id", handlers.GetProject)
app.Put("/api/project/:id", handlers.UpdateProject)
app.Delete("/api/project/:id", handlers.DeleteProject)
app.Post("/api/list", handlers.CreateList)
2023-12-29 01:49:09 +01:00
app.Get("/api/lists/:project_id", handlers.GetAllListsOf)
2023-12-28 01:19:29 +01:00
app.Get("/api/list/:id", handlers.GetList)
app.Delete("/api/list/:id", handlers.DeleteList)
app.Put("/api/list/:id", handlers.UpdateList)
2023-12-27 22:23:10 +01:00
2023-12-29 01:49:09 +01:00
app.Post("/api/card", handlers.CreateCards)
app.Get("/api/cards/:project_id", handlers.GetAllCardsOf)
app.Get("/api/card/:id", handlers.GetCard)
app.Delete("/api/card/:id", handlers.DeleteCard)
app.Put("/api/card/:id", handlers.UpdateCard)
2023-12-27 22:23:10 +01:00
log.Fatal(app.Listen(fmt.Sprintf(":%v", port)))
}