feat: change Manual time entry to work with hours instead of start and end time

according to add hours as well the logic was changed to accept ours for
manual entries instead of start and end time. This allows to add
negative numbers as well, which are added to working time.
This commit is contained in:
Patryk Hegenberg 2025-11-08 11:27:42 +01:00
parent c07019e3eb
commit 84def05c50
4 changed files with 84 additions and 135 deletions

View file

@ -90,17 +90,15 @@ func (app *App) GetYearlyHoursSummaryHandler(c echo.Context) error {
func (app *App) AdminCreateTimeEntryHandler(c echo.Context) error {
isAdmin, _ := c.Get("is_admin").(bool)
if !isAdmin {
return echo.NewHTTPError(http.StatusForbidden, "Only admins can create entries for others")
}
var req struct {
UserID int `json:"user_id"`
Date string `json:"date"`
StartTime string `json:"start_time"`
EndTime string `json:"end_time"`
Type string `json:"type"`
UserID int `json:"user_id"`
Date string `json:"date"`
Hours float64 `json:"hours"`
Type string `json:"type"`
}
if err := c.Bind(&req); err != nil {
@ -110,16 +108,16 @@ func (app *App) AdminCreateTimeEntryHandler(c echo.Context) error {
entry := TimeEntry{
UserID: req.UserID,
Date: req.Date,
StartTime: req.StartTime,
EndTime: req.EndTime,
Type: req.Type,
StartTime: "00:00",
EndTime: "00:00",
Type: "manual",
}
if err := CreateTimeEntry(app.DB, &entry); err != nil {
if err := CreateManualTimeEntry(app.DB, &entry, req.Hours); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
return c.JSON(http.StatusCreated, map[string]string{"message": "time entry created"})
return c.NoContent(http.StatusCreated)
}
func (app *App) GetUsersHandler(c echo.Context) error {