added entering availabilities in the dashboard

This commit is contained in:
z1glr
2025-01-23 10:51:47 +00:00
parent c752bc6c14
commit 19e7d2b366
5 changed files with 69 additions and 5 deletions

View File

@@ -1,6 +1,8 @@
package router
import (
"strconv"
"github.com/gofiber/fiber/v2"
"github.com/johannesbuehl/golunteer/backend/pkg/db/events"
)
@@ -119,6 +121,32 @@ func (a *Handler) getEventsUserAssigned() {
}
}
func (a *Handler) putEventUserAvailability() {
// parse the query
if eventID := a.C.QueryInt("eventID", -1); eventID == -1 {
a.Status = fiber.StatusBadRequest
logger.Log().Msg("setting user-event-availability failed: query is missing \"eventID\"")
} else {
// parse the body
body := a.C.Body()
if availabilityID, err := strconv.Atoi(string(body)); err != nil {
a.Status = fiber.StatusBadRequest
logger.Log().Msgf("setting user-event-availability failed: can't get parse: %v", err)
// insert the availability into the database
} else if err := events.UserAvailability(a.UserName, eventID, availabilityID); err != nil {
a.Status = fiber.StatusInternalServerError
logger.Error().Msgf("setting user-event-availability failed: can't write availability to database: %v", err)
}
}
// parse the body
}
func (a *Handler) deleteEvent() {
// check for admin
if !a.Admin {

View File

@@ -107,7 +107,8 @@ func init() {
"tasks": (*Handler).patchTask, // modify a task
},
"PUT": {
"users/password": (*Handler).putPassword, // change the password
"users/password": (*Handler).putPassword, // change the password
"events/user/availability": (*Handler).putEventUserAvailability, // set or change the users availability for a specific event
},
"DELETE": {
"event": (*Handler).deleteEvent, // remove an event