Cards API
This commit is contained in:
parent
00d6a71365
commit
69df067520
|
@ -0,0 +1,61 @@
|
|||
package db
|
||||
|
||||
import "git.bhasher.com/bhasher/focus/backend/types"
|
||||
|
||||
func CreateCard(c types.Card) (int, error) {
|
||||
res, err := db.Exec("INSERT INTO cards (list_id, title, content) VALUES (?, ?, ?)", c.ListID, c.Title, c.Content)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
id, err := res.LastInsertId()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return int(id), nil
|
||||
}
|
||||
|
||||
func GetAllCardsOf(listID int) ([]types.Card, error) {
|
||||
rows, err := db.Query("SELECT * FROM cards WHERE list_id = ?", listID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var cards []types.Card
|
||||
for rows.Next() {
|
||||
var c types.Card
|
||||
if err := rows.Scan(&c.ID, &c.ListID, &c.Title, &c.Content); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cards = append(cards, c)
|
||||
}
|
||||
|
||||
if err = rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return cards, nil
|
||||
}
|
||||
|
||||
func GetCard(id int) (*types.Card, error) {
|
||||
var c types.Card
|
||||
|
||||
err := db.QueryRow("SELECT * FROM cards WHERE id = ?", id).Scan(&c.ID, &c.ListID, &c.Title, &c.Content)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &c, nil
|
||||
}
|
||||
|
||||
func DeleteCard(id int) error {
|
||||
_, err := db.Exec("DELETE FROM cards WHERE id = ?", id)
|
||||
return err
|
||||
}
|
||||
|
||||
func UpdateCard(c types.Card) error {
|
||||
_, err := db.Exec("UPDATE cards SET list_id = ?, title = ?, content = ? WHERE id = ?", c.ListID, c.Title, c.Content, c.ID)
|
||||
return err
|
||||
}
|
|
@ -1,42 +1,8 @@
|
|||
package main
|
||||
package db
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
import "git.bhasher.com/bhasher/focus/backend/types"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
var db *sql.DB
|
||||
|
||||
type List struct {
|
||||
ID int `json:"id"`
|
||||
ProjectID int `json:"project_id"`
|
||||
Title string `json:"title"`
|
||||
Color string `json:"color"`
|
||||
}
|
||||
|
||||
func InitDB(driver string, connStr string) error {
|
||||
var err error
|
||||
db, err = sql.Open(driver, connStr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS lists (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
project_id INTEGER,
|
||||
title TEXT,
|
||||
color TEXT
|
||||
);
|
||||
`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Create(l List) (int, error) {
|
||||
func CreateList(l types.List) (int, error) {
|
||||
res, err := db.Exec("INSERT INTO lists (project_id, title, color) VALUES (?, ?, ?)", l.ProjectID, l.Title, l.Color)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
@ -50,16 +16,16 @@ func Create(l List) (int, error) {
|
|||
return int(id), nil
|
||||
}
|
||||
|
||||
func GetAll(projectID int) ([]List, error) {
|
||||
func GetAllListsOf(projectID int) ([]types.List, error) {
|
||||
rows, err := db.Query("SELECT * FROM lists WHERE project_id = ?", projectID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var lists []List
|
||||
var lists []types.List
|
||||
for rows.Next() {
|
||||
var l List
|
||||
var l types.List
|
||||
if err := rows.Scan(&l.ID, &l.ProjectID, &l.Title, &l.Color); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -73,8 +39,8 @@ func GetAll(projectID int) ([]List, error) {
|
|||
return lists, nil
|
||||
}
|
||||
|
||||
func Get(id int) (*List, error) {
|
||||
var l List
|
||||
func GetList(id int) (*types.List, error) {
|
||||
var l types.List
|
||||
|
||||
err := db.QueryRow("SELECT * FROM lists WHERE id = ?", id).Scan(&l.ID, &l.ProjectID, &l.Title, &l.Color)
|
||||
if err != nil {
|
||||
|
@ -84,12 +50,12 @@ func Get(id int) (*List, error) {
|
|||
return &l, nil
|
||||
}
|
||||
|
||||
func Delete(id int) error {
|
||||
func DeleteList(id int) error {
|
||||
_, err := db.Exec("DELETE FROM lists WHERE id = ?", id)
|
||||
return err
|
||||
}
|
||||
|
||||
func Update(l List) error {
|
||||
func UpdateList(l types.List) error {
|
||||
_, err := db.Exec("UPDATE lists SET project_id = ?, title = ?, color = ? WHERE id = ?", l.ProjectID, l.Title, l.Color, l.ID)
|
||||
return err
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package db
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
var db *sql.DB
|
||||
|
||||
func InitDB(driver string, connStr string) error {
|
||||
var err error
|
||||
db, err = sql.Open(driver, connStr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS projects (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
title TEXT
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS lists (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
project_id INTEGER,
|
||||
title TEXT,
|
||||
color TEXT,
|
||||
FOREIGN KEY(project_id) REFERENCES projects(id)
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS cards (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
list_id INTEGER,
|
||||
title TEXT,
|
||||
content TEXT,
|
||||
FOREIGN KEY(list_id) REFERENCES lists(id)
|
||||
);
|
||||
`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -1,36 +1,10 @@
|
|||
package main
|
||||
package db
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"git.bhasher.com/bhasher/focus/backend/types"
|
||||
)
|
||||
|
||||
var db *sql.DB
|
||||
|
||||
type Project struct {
|
||||
ID int `json:"id"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
func InitDB(driver string, connStr string) error {
|
||||
var err error
|
||||
db, err = sql.Open(driver, connStr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS projects (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
title TEXT
|
||||
);
|
||||
`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Create(p Project) (int, error) {
|
||||
func CreateProject(p types.Project) (int, error) {
|
||||
res, err := db.Exec("INSERT INTO projects (title) VALUES (?)", p.Title)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
@ -44,16 +18,16 @@ func Create(p Project) (int, error) {
|
|||
return int(id), nil
|
||||
}
|
||||
|
||||
func GetAll() ([]Project, error) {
|
||||
func GetAllProjects() ([]types.Project, error) {
|
||||
rows, err := db.Query("SELECT * FROM projects")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var projects []Project
|
||||
var projects []types.Project
|
||||
for rows.Next() {
|
||||
var p Project
|
||||
var p types.Project
|
||||
if err := rows.Scan(&p.ID, &p.Title); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -67,8 +41,8 @@ func GetAll() ([]Project, error) {
|
|||
return projects, nil
|
||||
}
|
||||
|
||||
func Get(id int) (*Project, error) {
|
||||
var p Project
|
||||
func GetProject(id int) (*types.Project, error) {
|
||||
var p types.Project
|
||||
|
||||
err := db.QueryRow("SELECT * FROM projects WHERE id = ?", id).Scan(&p.ID, &p.Title)
|
||||
if err != nil {
|
||||
|
@ -78,12 +52,12 @@ func Get(id int) (*Project, error) {
|
|||
return &p, nil
|
||||
}
|
||||
|
||||
func Delete(id int) error {
|
||||
func DeleteProject(id int) error {
|
||||
_, err := db.Exec("DELETE FROM projects WHERE id = ?", id)
|
||||
return err
|
||||
}
|
||||
|
||||
func Update(p Project) error {
|
||||
func UpdateProject(p types.Project) error {
|
||||
_, err := db.Exec("UPDATE projects SET title = ? WHERE id = ?", p.Title, p.ID)
|
||||
return err
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
module git.bhasher.com/focus/focus-projects
|
||||
module git.bhasher.com/bhasher/focus/backend
|
||||
|
||||
go 1.21.4
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"git.bhasher.com/bhasher/focus/backend/db"
|
||||
"git.bhasher.com/bhasher/focus/backend/types"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func CreateCards(c *fiber.Ctx) error {
|
||||
card := types.Card{}
|
||||
if err := c.BodyParser(&card); err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Cannot parse request"})
|
||||
}
|
||||
|
||||
id, err := db.CreateCard(card)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Cannot create card"})
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusCreated).JSON(fiber.Map{"id": id})
|
||||
}
|
||||
|
||||
func GetAllCardsOf(c *fiber.Ctx) error {
|
||||
listID, err := strconv.Atoi(c.Params("list_id"))
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid list ID"})
|
||||
}
|
||||
|
||||
lists, err := db.GetAllListsOf(listID)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Cannot retrieve cards"})
|
||||
}
|
||||
|
||||
return c.JSON(lists)
|
||||
}
|
||||
|
||||
func GetCard(c *fiber.Ctx) error {
|
||||
id, err := strconv.Atoi(c.Params("id"))
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid card ID"})
|
||||
}
|
||||
|
||||
card, err := db.GetCard(id)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Cannot retrieve card"})
|
||||
}
|
||||
if card == nil {
|
||||
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{"error": "Card not found"})
|
||||
}
|
||||
|
||||
return c.JSON(card)
|
||||
}
|
||||
|
||||
func DeleteCard(c *fiber.Ctx) error {
|
||||
id, err := strconv.Atoi(c.Params("id"))
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid card ID"})
|
||||
}
|
||||
|
||||
err = db.DeleteCard(id)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Cannot delete card"})
|
||||
}
|
||||
|
||||
return c.SendStatus(fiber.StatusNoContent)
|
||||
}
|
||||
|
||||
func UpdateCard(c *fiber.Ctx) error {
|
||||
id, err := strconv.Atoi(c.Params("id"))
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid card ID"})
|
||||
}
|
||||
|
||||
card := types.Card{ID: id}
|
||||
if err := c.BodyParser(&card); err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Cannot parse request"})
|
||||
}
|
||||
|
||||
err = db.UpdateCard(card)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Cannot update card"})
|
||||
}
|
||||
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
|
@ -1,40 +1,20 @@
|
|||
package main
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
|
||||
"git.bhasher.com/bhasher/focus/backend/db"
|
||||
"git.bhasher.com/bhasher/focus/backend/types"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
driver := "sqlite3"
|
||||
connStr := "db.sqlite"
|
||||
port := "3001"
|
||||
|
||||
if err := InitDB(driver, connStr); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
app := fiber.New()
|
||||
|
||||
app.Post("/list", createListHandler)
|
||||
app.Get("/lists/:board_id", getAllListsHandler)
|
||||
app.Get("/list/:id", getListHandler)
|
||||
app.Delete("/list/:id", deleteListHandler)
|
||||
app.Put("/list/:id", updateListHandler)
|
||||
|
||||
log.Fatal(app.Listen(fmt.Sprintf(":%v", port)))
|
||||
}
|
||||
|
||||
func createListHandler(c *fiber.Ctx) error {
|
||||
list := List{}
|
||||
func CreateList(c *fiber.Ctx) error {
|
||||
list := types.List{}
|
||||
if err := c.BodyParser(&list); err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Cannot parse request"})
|
||||
}
|
||||
|
||||
id, err := Create(list)
|
||||
id, err := db.CreateList(list)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Cannot create list"})
|
||||
}
|
||||
|
@ -42,13 +22,13 @@ func createListHandler(c *fiber.Ctx) error {
|
|||
return c.Status(fiber.StatusCreated).JSON(fiber.Map{"id": id})
|
||||
}
|
||||
|
||||
func getAllListsHandler(c *fiber.Ctx) error {
|
||||
boardID, err := strconv.Atoi(c.Params("board_id"))
|
||||
func GetAllListsOf(c *fiber.Ctx) error {
|
||||
projectID, err := strconv.Atoi(c.Params("project_id"))
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid board ID"})
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid project ID"})
|
||||
}
|
||||
|
||||
lists, err := GetAll(boardID)
|
||||
lists, err := db.GetAllListsOf(projectID)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Cannot retrieve lists"})
|
||||
}
|
||||
|
@ -56,13 +36,13 @@ func getAllListsHandler(c *fiber.Ctx) error {
|
|||
return c.JSON(lists)
|
||||
}
|
||||
|
||||
func getListHandler(c *fiber.Ctx) error {
|
||||
func GetList(c *fiber.Ctx) error {
|
||||
id, err := strconv.Atoi(c.Params("id"))
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid list ID"})
|
||||
}
|
||||
|
||||
list, err := Get(id)
|
||||
list, err := db.GetList(id)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Cannot retrieve list"})
|
||||
}
|
||||
|
@ -73,13 +53,13 @@ func getListHandler(c *fiber.Ctx) error {
|
|||
return c.JSON(list)
|
||||
}
|
||||
|
||||
func deleteListHandler(c *fiber.Ctx) error {
|
||||
func DeleteList(c *fiber.Ctx) error {
|
||||
id, err := strconv.Atoi(c.Params("id"))
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid list ID"})
|
||||
}
|
||||
|
||||
err = Delete(id)
|
||||
err = db.DeleteList(id)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Cannot delete list"})
|
||||
}
|
||||
|
@ -87,18 +67,18 @@ func deleteListHandler(c *fiber.Ctx) error {
|
|||
return c.SendStatus(fiber.StatusNoContent)
|
||||
}
|
||||
|
||||
func updateListHandler(c *fiber.Ctx) error {
|
||||
func UpdateList(c *fiber.Ctx) error {
|
||||
id, err := strconv.Atoi(c.Params("id"))
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid list ID"})
|
||||
}
|
||||
|
||||
list := List{ID: id}
|
||||
list := types.List{ID: id}
|
||||
if err := c.BodyParser(&list); err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Cannot parse request"})
|
||||
}
|
||||
|
||||
err = Update(list)
|
||||
err = db.UpdateList(list)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Cannot update list"})
|
||||
}
|
|
@ -1,35 +1,15 @@
|
|||
package main
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"git.bhasher.com/bhasher/focus/backend/db"
|
||||
"git.bhasher.com/bhasher/focus/backend/types"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
func main() {
|
||||
driver := "sqlite3"
|
||||
connStr := "db.sqlite"
|
||||
port := "3000"
|
||||
|
||||
if err := InitDB(driver, connStr); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
app := fiber.New()
|
||||
|
||||
app.Get("/projects", getAllProjectsHandler)
|
||||
app.Get("/project/:id", getProjectHandler)
|
||||
app.Post("/project", createProjectHandler)
|
||||
app.Put("/project/:id", updateProjectHandler)
|
||||
app.Delete("/project/:id", deleteProjectHandler)
|
||||
|
||||
log.Fatal(app.Listen(fmt.Sprintf(":%v", port)))
|
||||
}
|
||||
|
||||
func getAllProjectsHandler(c *fiber.Ctx) error {
|
||||
projects, err := GetAll()
|
||||
func GetAllProjects(c *fiber.Ctx) error {
|
||||
projects, err := db.GetAllProjects()
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Cannot retrieve projects"})
|
||||
}
|
||||
|
@ -39,13 +19,13 @@ func getAllProjectsHandler(c *fiber.Ctx) error {
|
|||
return c.JSON(projects)
|
||||
}
|
||||
|
||||
func getProjectHandler(c *fiber.Ctx) error {
|
||||
func GetProject(c *fiber.Ctx) error {
|
||||
id, err := c.ParamsInt("id")
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid project ID"})
|
||||
}
|
||||
|
||||
project, err := Get(id)
|
||||
project, err := db.GetProject(id)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Error fetching project"})
|
||||
}
|
||||
|
@ -55,13 +35,13 @@ func getProjectHandler(c *fiber.Ctx) error {
|
|||
return c.JSON(project)
|
||||
}
|
||||
|
||||
func createProjectHandler(c *fiber.Ctx) error {
|
||||
p := new(Project)
|
||||
func CreateProject(c *fiber.Ctx) error {
|
||||
p := new(types.Project)
|
||||
if err := c.BodyParser(p); err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Error parsing request"})
|
||||
}
|
||||
|
||||
id, err := Create(*p)
|
||||
id, err := db.CreateProject(*p)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Error creating project"})
|
||||
}
|
||||
|
@ -69,18 +49,18 @@ func createProjectHandler(c *fiber.Ctx) error {
|
|||
return c.Status(fiber.StatusCreated).JSON(fiber.Map{"id": id})
|
||||
}
|
||||
|
||||
func updateProjectHandler(c *fiber.Ctx) error {
|
||||
func UpdateProject(c *fiber.Ctx) error {
|
||||
id, err := c.ParamsInt("id")
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid project ID"})
|
||||
}
|
||||
|
||||
p := Project{ID: id}
|
||||
p := types.Project{ID: id}
|
||||
if err := c.BodyParser(&p); err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Error parsing request"})
|
||||
}
|
||||
|
||||
err = Update(p)
|
||||
err = db.UpdateProject(p)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Error updating project"})
|
||||
}
|
||||
|
@ -88,13 +68,13 @@ func updateProjectHandler(c *fiber.Ctx) error {
|
|||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func deleteProjectHandler(c *fiber.Ctx) error {
|
||||
func DeleteProject(c *fiber.Ctx) error {
|
||||
id, err := c.ParamsInt("id")
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid project ID"})
|
||||
}
|
||||
|
||||
err = Delete(id)
|
||||
err = db.DeleteProject(id)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Error deleting project"})
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
_ "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"
|
||||
|
||||
if err := db.InitDB(driver, connStr); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
app := fiber.New()
|
||||
|
||||
app.Get("/projects", handlers.GetAllProjects)
|
||||
app.Get("/project/:id", handlers.GetProject)
|
||||
app.Post("/project", handlers.CreateProject)
|
||||
app.Put("/project/:id", handlers.UpdateProject)
|
||||
app.Delete("/project/:id", handlers.DeleteProject)
|
||||
|
||||
app.Post("/list", handlers.CreateList)
|
||||
app.Get("/lists/:board_id", handlers.GetAllListsOf)
|
||||
app.Get("/list/:id", handlers.GetList)
|
||||
app.Delete("/list/:id", handlers.DeleteList)
|
||||
app.Put("/list/:id", handlers.UpdateList)
|
||||
|
||||
log.Fatal(app.Listen(fmt.Sprintf(":%v", port)))
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package types
|
||||
|
||||
type Card struct {
|
||||
ID int `json:"id"`
|
||||
ListID int `json:"list_id"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package types
|
||||
|
||||
type List struct {
|
||||
ID int `json:"id"`
|
||||
ProjectID int `json:"project_id"`
|
||||
Title string `json:"title"`
|
||||
Color string `json:"color"`
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package types
|
||||
|
||||
type Project struct {
|
||||
ID int `json:"id"`
|
||||
Title string `json:"title"`
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
module git.bhasher.com/focus/focus-lists
|
||||
|
||||
go 1.21.4
|
||||
|
||||
require github.com/gofiber/fiber/v2 v2.51.0
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.0.5 // indirect
|
||||
github.com/google/uuid v1.4.0 // indirect
|
||||
github.com/klauspost/compress v1.16.7 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasthttp v1.50.0 // indirect
|
||||
github.com/valyala/tcplisten v1.0.0 // indirect
|
||||
golang.org/x/sys v0.14.0 // indirect
|
||||
)
|
||||
|
||||
require github.com/mattn/go-sqlite3 v1.14.19
|
|
@ -1,41 +0,0 @@
|
|||
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
|
||||
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/andybalholm/brotli v1.0.6 h1:Yf9fFpf49Zrxb9NlQaluyE92/+X7UVHlhMNJN2sxfOI=
|
||||
github.com/andybalholm/brotli v1.0.6/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/gofiber/fiber/v2 v2.51.0 h1:JNACcZy5e2tGApWB2QrRpenTWn0fq0hkFm6k0C86gKQ=
|
||||
github.com/gofiber/fiber/v2 v2.51.0/go.mod h1:xaQRZQJGqnKOQnbQw+ltvku3/h8QxvNi8o6JiJ7Ll0U=
|
||||
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
|
||||
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
|
||||
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=
|
||||
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
||||
github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4=
|
||||
github.com/klauspost/compress v1.17.4/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
||||
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/mattn/go-sqlite3 v1.14.19 h1:fhGleo2h1p8tVChob4I9HpmVFIAkKGpiukdrgQbWfGI=
|
||||
github.com/mattn/go-sqlite3 v1.14.19/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
|
||||
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasthttp v1.50.0 h1:H7fweIlBm0rXLs2q0XbalvJ6r0CUPFWK3/bB4N13e9M=
|
||||
github.com/valyala/fasthttp v1.50.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA=
|
||||
github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA=
|
||||
github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g=
|
||||
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
|
||||
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
|
||||
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
|
||||
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
|
@ -1,2 +0,0 @@
|
|||
github.com/philhofer/fwd v1.1.2/go.mod h1:qkPdfjR2SIEbspLqpe1tO4n5yICnr2DY7mqEx2tUTP0=
|
||||
github.com/tinylib/msgp v1.1.8/go.mod h1:qkpG+2ldGg4xRFmx+jfTvZPxfGFhi64BcnL9vkCm/Tw=
|
Loading…
Reference in New Issue