Completed db rewrite

This commit is contained in:
Manuel Forcén Muñoz 2025-04-16 23:24:23 +02:00
parent 54d7d14ef9
commit cf4b8e0119
19 changed files with 481 additions and 276 deletions

View file

@ -8,6 +8,7 @@ import (
"github.com/gin-gonic/gin"
"planner/core"
. "planner/core"
)
@ -22,7 +23,7 @@ func createPlan(c *gin.Context) {
}
c.Bind(&plan_req)
_, err := CreatePlan(db, u, plan_req.Name)
_, err := PlanCreate(db, u, plan_req.Name)
if err != nil {
c.JSON(http.StatusInternalServerError, err)
@ -144,7 +145,7 @@ func joinPlan(c *gin.Context) {
c.Status(http.StatusBadRequest)
return
}
plan, err := GetPlan(db, uint(plan_id))
plan, err := PlanGet(db, uint(plan_id))
if err != nil || plan == nil {
c.Status(http.StatusInternalServerError)
return
@ -171,7 +172,7 @@ func joinPlan(c *gin.Context) {
c.String(http.StatusConflict, "User already a member")
return
}
plan.AddMember(db, &Member{UserID: user.Username})
plan.AddMember(db, &Member{UserId: &user.Username})
c.Status(http.StatusOK)
}
@ -212,10 +213,10 @@ func createPlanPoll(c *gin.Context) {
}
poll := Poll{
PlanID: plan.ID,
PlanId: plan.Id,
Options: poll_opts.Options,
}
db.Create(&poll)
poll.Create(db)
c.JSON(http.StatusCreated, poll)
}
@ -236,8 +237,11 @@ func listPlanPolls(c *gin.Context) {
return
}
var polls []Poll
db.Where("plan_id = ?", params.Id).Find(&polls)
polls, err := core.PollsList(db, int(params.Id))
if err != nil {
c.String(http.StatusInternalServerError, err.Error())
return
}
c.JSON(http.StatusOK, polls)
}