Fix cards

This commit is contained in:
Brieuc Dubois 2023-12-28 03:12:33 +01:00
parent 18c94bd7a0
commit ef4355e2b6
3 changed files with 12 additions and 12 deletions

View File

@ -3,7 +3,7 @@ package db
import "git.bhasher.com/bhasher/focus/backend/types" import "git.bhasher.com/bhasher/focus/backend/types"
func CreateCard(c types.Card) (int, error) { 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) res, err := db.Exec("INSERT INTO cards (project_id, title, content) VALUES (?, ?, ?)", c.ProjectID, c.Title, c.Content)
if err != nil { if err != nil {
return 0, err return 0, err
} }
@ -16,8 +16,8 @@ func CreateCard(c types.Card) (int, error) {
return int(id), nil return int(id), nil
} }
func GetAllCardsOf(listID int) ([]types.Card, error) { func GetAllCardsOf(projectID int) ([]types.Card, error) {
rows, err := db.Query("SELECT * FROM cards WHERE list_id = ?", listID) rows, err := db.Query("SELECT * FROM cards WHERE project_id = ?", projectID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -26,7 +26,7 @@ func GetAllCardsOf(listID int) ([]types.Card, error) {
var cards []types.Card var cards []types.Card
for rows.Next() { for rows.Next() {
var c types.Card var c types.Card
if err := rows.Scan(&c.ID, &c.ListID, &c.Title, &c.Content); err != nil { if err := rows.Scan(&c.ID, &c.ProjectID, &c.Title, &c.Content); err != nil {
return nil, err return nil, err
} }
cards = append(cards, c) cards = append(cards, c)
@ -42,7 +42,7 @@ func GetAllCardsOf(listID int) ([]types.Card, error) {
func GetCard(id int) (*types.Card, error) { func GetCard(id int) (*types.Card, error) {
var c types.Card var c types.Card
err := db.QueryRow("SELECT * FROM cards WHERE id = ?", id).Scan(&c.ID, &c.ListID, &c.Title, &c.Content) err := db.QueryRow("SELECT * FROM cards WHERE id = ?", id).Scan(&c.ID, &c.ProjectID, &c.Title, &c.Content)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -56,6 +56,6 @@ func DeleteCard(id int) error {
} }
func UpdateCard(c types.Card) error { 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) _, err := db.Exec("UPDATE cards SET project_id = ?, title = ?, content = ? WHERE id = ?", c.ProjectID, c.Title, c.Content, c.ID)
return err return err
} }

View File

@ -23,9 +23,9 @@ func CreateCards(c *fiber.Ctx) error {
} }
func GetAllCardsOf(c *fiber.Ctx) error { func GetAllCardsOf(c *fiber.Ctx) error {
listID, err := strconv.Atoi(c.Params("list_id")) listID, err := strconv.Atoi(c.Params("project_id"))
if err != nil { if err != nil {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid list ID"}) return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid project_id"})
} }
lists, err := db.GetAllListsOf(listID) lists, err := db.GetAllListsOf(listID)

View File

@ -2,7 +2,7 @@ package types
type Card struct { type Card struct {
ID int `json:"id"` ID int `json:"id"`
ListID int `json:"list_id"` ProjectID int `json:"project_id"`
Title string `json:"title"` Title string `json:"title"`
Content string `json:"content"` Content string `json:"content"`
} }