5 Commits

Author SHA1 Message Date
tom
dafcd95428 CHANGE: Minor improvements + updated api docs 2025-02-28 13:13:37 +01:00
tom
23cb312644 CHANGE: added api_key to get params 2025-02-28 13:10:22 +01:00
tom
4dbd1ced0d CHANGE: added api endpoint for time path 2025-02-28 13:09:15 +01:00
tom
27bac5ff84 CHANGE: css 2025-02-26 15:06:35 +01:00
tom
54104d5a0e CHANGE: added report section 2025-02-26 15:05:50 +01:00
21 changed files with 948 additions and 556 deletions

View File

@@ -1,15 +1,30 @@
package endpoints package endpoints
import ( import (
"arbeitszeitmessung/helper"
"arbeitszeitmessung/models" "arbeitszeitmessung/models"
"arbeitszeitmessung/templates" "arbeitszeitmessung/templates"
"context"
"errors"
"log" "log"
"net/http" "net/http"
"strconv"
"time" "time"
) )
func TeamHandler(w http.ResponseWriter, r *http.Request) { func TeamHandler(w http.ResponseWriter, r *http.Request) {
helper.RequiresLogin(Session, w, r)
switch r.Method {
case http.MethodPost:
submitReport(w, r)
break
case http.MethodGet:
showWeeks(w, r) showWeeks(w, r)
break
default:
http.Error(w, "Method not allowed!", http.StatusMethodNotAllowed)
break
}
// user, err := (*models.User).GetUserFromSession(nil, Session, r.Context()) // user, err := (*models.User).GetUserFromSession(nil, Session, r.Context())
// if err != nil { // if err != nil {
// log.Println("No user found with the given personal number!") // log.Println("No user found with the given personal number!")
@@ -24,6 +39,39 @@ func TeamHandler(w http.ResponseWriter, r *http.Request) {
// templates.TeamPage(teamMembers, userWorkDays).Render(r.Context(), w) // templates.TeamPage(teamMembers, userWorkDays).Render(r.Context(), w)
} }
func submitReport(w http.ResponseWriter, r *http.Request) {
err := r.ParseForm()
if err != nil {
log.Println("Error parsing form", err)
return
}
userPN, _ := strconv.Atoi(r.FormValue("user"))
_weekTs := r.FormValue("week")
weekTs, err := time.Parse(time.DateOnly, _weekTs)
user, err := (*models.User).GetByPersonalNummer(nil, userPN)
workWeek := (*models.WorkWeek).GetWeek(nil, user, weekTs, false)
if err != nil {
log.Println("Could not get user!")
return
}
switch r.FormValue("method") {
case "send":
err = workWeek.Send()
break
case "accept":
err = workWeek.Accept()
break
default:
break
}
if errors.Is(err, models.ErrRunningWeek) {
showWeeks(w, r.WithContext(context.WithValue(r.Context(), "error", true)))
}
showWeeks(w, r)
}
func showWeeks(w http.ResponseWriter, r *http.Request) { func showWeeks(w http.ResponseWriter, r *http.Request) {
user, err := (*models.User).GetUserFromSession(nil, Session, r.Context()) user, err := (*models.User).GetUserFromSession(nil, Session, r.Context())
if err != nil { if err != nil {
@@ -37,16 +85,10 @@ func showWeeks(w http.ResponseWriter, r *http.Request) {
weeks := (*models.WorkWeek).GetSendWeeks(nil, member) weeks := (*models.WorkWeek).GetSendWeeks(nil, member)
workWeeks = append(workWeeks, weeks...) workWeeks = append(workWeeks, weeks...)
} }
// Somehow use this for the own users weeks
// lastSub := member.GetLastSubmission()
// weeks := getWeeksTillNow(lastSub)
// for _, week := range weeks {
// workWeek := (*models.WorkWeek).GetWeek(nil, member, week)
// workWeeks = append(workWeeks, workWeek)
// }
lastSub := user.GetLastSubmission() lastSub := user.GetLastSubmission()
// userWorkDays := (*models.WorkDay).GetWorkDays(nil, user.CardUID, lastSub, lastSub.AddDate(0, 0, 7)) log.Println(lastSub)
userWeek := (*models.WorkWeek).GetWeek(nil, user, lastSub) userWeek := (*models.WorkWeek).GetWeek(nil, user, lastSub, true)
// isRunningWeek := time.Since(lastSub) < 24*5*time.Hour //the last submission is this week and cannot be send yet
templates.TeamPage(workWeeks, userWeek).Render(r.Context(), w) templates.TeamPage(workWeeks, userWeek).Render(r.Context(), w)
} }

View File

@@ -14,17 +14,22 @@ import (
// Frontend relevant backend functionality -> not used by the arduino devices // Frontend relevant backend functionality -> not used by the arduino devices
func TimeHandler(w http.ResponseWriter, r *http.Request) { func TimeHandler(w http.ResponseWriter, r *http.Request) {
helper.RequiresLogin(Session, w, r)
helper.SetCors(w) helper.SetCors(w)
switch r.Method { switch r.Method {
case "GET": case http.MethodGet:
getBookings(w, r) getBookings(w, r)
case "POST": break
case http.MethodPost:
updateBooking(w, r) updateBooking(w, r)
case "OPTIONS": break
case http.MethodOptions:
// just support options header for non GET Requests from SWAGGER // just support options header for non GET Requests from SWAGGER
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
break
default: default:
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) http.Error(w, "Method not allowed!", http.StatusMethodNotAllowed)
break
} }
} }
@@ -70,6 +75,12 @@ func getBookings(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Internal Server Error", http.StatusInternalServerError) http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return return
} }
if r.Header.Get("Accept") == "application/json" {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(bookings)
return
}
ctx := context.WithValue(r.Context(), "user", user) ctx := context.WithValue(r.Context(), "user", user)
templates.TimePage(bookings).Render(ctx, w) templates.TimePage(bookings).Render(ctx, w)
} }

View File

@@ -16,13 +16,17 @@ func TimeCreateHandler(w http.ResponseWriter, r *http.Request) {
switch r.Method { switch r.Method {
case http.MethodPut: case http.MethodPut:
createBooking(w, r) createBooking(w, r)
break
case http.MethodGet: case http.MethodGet:
createBooking(w, r) createBooking(w, r)
break
case http.MethodOptions: case http.MethodOptions:
// just support options header for non GET Requests from SWAGGER // just support options header for non GET Requests from SWAGGER
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
break
default: default:
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
break
} }
} }
@@ -58,5 +62,13 @@ func checkPassword(r *http.Request) bool {
authToken := helper.GetEnv("API_TOKEN", "dont_access") authToken := helper.GetEnv("API_TOKEN", "dont_access")
authHeaders := r.Header.Get("Authorization") authHeaders := r.Header.Get("Authorization")
_authStart := len("Bearer ") _authStart := len("Bearer ")
if len(authHeaders) <= _authStart {
authHeaders = r.URL.Query().Get("api_key")
_authStart = 0
if len(authHeaders) <= _authStart {
return false
}
}
log.Println(authHeaders)
return authToken == authHeaders[_authStart:] return authToken == authHeaders[_authStart:]
} }

View File

@@ -1,6 +1,7 @@
package endpoints package endpoints
import ( import (
"arbeitszeitmessung/helper"
"arbeitszeitmessung/models" "arbeitszeitmessung/models"
"arbeitszeitmessung/templates" "arbeitszeitmessung/templates"
"log" "log"
@@ -18,27 +19,26 @@ func CreateSessionManager(lifetime time.Duration) *scs.SessionManager {
Session.Lifetime = lifetime Session.Lifetime = lifetime
return Session return Session
} }
func LoginHandler(w http.ResponseWriter, r *http.Request) { func LoginHandler(w http.ResponseWriter, r *http.Request) {
switch r.Method { switch r.Method {
case http.MethodGet: case http.MethodGet:
showLoginForm(w, r, false) showLoginPage(w, r, false)
break break
case http.MethodPost: case http.MethodPost:
loginUser(w, r) loginUser(w, r)
break break
default: default:
showLoginForm(w, r, false) http.Error(w, "Method not allowed!", http.StatusMethodNotAllowed)
break break
} }
} }
func UserHandler(w http.ResponseWriter, r *http.Request) { func UserHandler(w http.ResponseWriter, r *http.Request) {
// if !Session.Exists(r.Context(), "user") { helper.RequiresLogin(Session, w, r)
// http.Redirect(w, r, "/user/login", http.StatusSeeOther)
// }
switch r.Method { switch r.Method {
case http.MethodGet: case http.MethodGet:
showPWForm(w, r, 0) showUserPage(w, r, 0)
break break
case http.MethodPost: case http.MethodPost:
changePassword(w, r) changePassword(w, r)
@@ -49,7 +49,7 @@ func UserHandler(w http.ResponseWriter, r *http.Request) {
} }
} }
func showLoginForm(w http.ResponseWriter, r *http.Request, failed bool) { func showLoginPage(w http.ResponseWriter, r *http.Request, failed bool) {
templates.LoginPage(failed).Render(r.Context(), w) templates.LoginPage(failed).Render(r.Context(), w)
} }
@@ -85,10 +85,10 @@ func loginUser(w http.ResponseWriter, r *http.Request) {
Session.Put(r.Context(), "user", user.PersonalNummer) Session.Put(r.Context(), "user", user.PersonalNummer)
http.Redirect(w, r, "/time", http.StatusSeeOther) //with this browser always uses GET http.Redirect(w, r, "/time", http.StatusSeeOther) //with this browser always uses GET
} else { } else {
showLoginForm(w, r, true) showLoginPage(w, r, true)
return return
} }
showLoginForm(w, r, false) showLoginPage(w, r, false)
return return
} }
@@ -103,26 +103,26 @@ func changePassword(w http.ResponseWriter, r *http.Request) {
password := r.FormValue("password") password := r.FormValue("password")
newPassword := r.FormValue("new_password") newPassword := r.FormValue("new_password")
if password == "" || newPassword == "" || newPassword != r.FormValue("new_password_repeat") { if password == "" || newPassword == "" || newPassword != r.FormValue("new_password_repeat") {
showPWForm(w, r, http.StatusBadRequest) showUserPage(w, r, http.StatusBadRequest)
return return
} }
user, err := (*models.User).GetByPersonalNummer(nil, Session.GetInt(r.Context(), "user")) user, err := (*models.User).GetByPersonalNummer(nil, Session.GetInt(r.Context(), "user"))
if err != nil { if err != nil {
log.Println("Error getting user!", err) log.Println("Error getting user!", err)
showPWForm(w, r, http.StatusBadRequest) showUserPage(w, r, http.StatusBadRequest)
} }
auth, err := user.ChangePass(password, newPassword) auth, err := user.ChangePass(password, newPassword)
if err != nil { if err != nil {
log.Println("Error when changing password!", err) log.Println("Error when changing password!", err)
} }
if auth { if auth {
showPWForm(w, r, http.StatusOK) showUserPage(w, r, http.StatusOK)
return return
} }
showPWForm(w, r, http.StatusUnauthorized) showUserPage(w, r, http.StatusUnauthorized)
} }
func showPWForm(w http.ResponseWriter, r *http.Request, status int) { func showUserPage(w http.ResponseWriter, r *http.Request, status int) {
templates.UserPage(status).Render(r.Context(), w) templates.UserPage(status).Render(r.Context(), w)
return return
} }

View File

@@ -3,15 +3,28 @@ package helper
import ( import (
"net/http" "net/http"
"os" "os"
"github.com/alexedwards/scs/v2"
) )
// setting cors, important for later frontend use // setting cors, important for later frontend use
// //
// in DEBUG == "true" everything is set to "*" so that no cors errors will be happen // in DEBUG == "true" everything is set to "*" so that no cors errors will be happen
func SetCors(w http.ResponseWriter) { func SetCors(w http.ResponseWriter) {
if os.Getenv("DEBUG") == "true" { if os.Getenv("NO_CORS") == "true" {
w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "*") w.Header().Set("Access-Control-Allow-Methods", "*")
w.Header().Set("Access-Control-Allow-Headers", "*") w.Header().Set("Access-Control-Allow-Headers", "*")
// log.Println("Setting cors to *")
} }
} }
func RequiresLogin(session *scs.SessionManager, w http.ResponseWriter, r *http.Request) {
if GetEnv("GO_ENV", "production") == "debug" {
return
}
if session.Exists(r.Context(), "user") {
return
}
http.Redirect(w, r, "/user/login", http.StatusSeeOther)
}

View File

@@ -4,12 +4,14 @@ import (
"arbeitszeitmessung/endpoints" "arbeitszeitmessung/endpoints"
"arbeitszeitmessung/helper" "arbeitszeitmessung/helper"
"arbeitszeitmessung/models" "arbeitszeitmessung/models"
"arbeitszeitmessung/templates"
"context" "context"
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
"time" "time"
"github.com/a-h/templ"
"github.com/joho/godotenv" "github.com/joho/godotenv"
_ "github.com/lib/pq" _ "github.com/lib/pq"
) )
@@ -40,6 +42,7 @@ func main() {
server.HandleFunc("/user/login", endpoints.LoginHandler) server.HandleFunc("/user/login", endpoints.LoginHandler)
server.HandleFunc("/user", endpoints.UserHandler) server.HandleFunc("/user", endpoints.UserHandler)
server.HandleFunc("/team", endpoints.TeamHandler) server.HandleFunc("/team", endpoints.TeamHandler)
server.Handle("/", templ.Handler(templates.NavPage()))
server.Handle("/static/", http.StripPrefix("/static/", fs)) server.Handle("/static/", http.StripPrefix("/static/", fs))
serverSessionMiddleware := endpoints.Session.LoadAndSave(server) serverSessionMiddleware := endpoints.Session.LoadAndSave(server)

View File

@@ -119,7 +119,7 @@ func (b *Booking) GetBookingsByCardID(card_uid string, tsFrom time.Time, tsTo ti
func (b *Booking) GetBookingsGrouped(card_uid string, tsFrom time.Time, tsTo time.Time) ([]WorkDay, error) { func (b *Booking) GetBookingsGrouped(card_uid string, tsFrom time.Time, tsTo time.Time) ([]WorkDay, error) {
var grouped = make(map[string][]Booking) var grouped = make(map[string][]Booking)
bookings, err := b.GetBookingsByCardID(card_uid, tsFrom, tsTo) bookings, err := b.GetBookingsByCardID(card_uid, tsFrom, tsTo)
if (err != nil){ if err != nil {
log.Println("Failed to get bookings", err) log.Println("Failed to get bookings", err)
return []WorkDay{}, nil return []WorkDay{}, nil
} }
@@ -183,7 +183,7 @@ func (b *Booking) Update(nb Booking) {
if b.GeraetID != nb.GeraetID && nb.GeraetID != 0 { if b.GeraetID != nb.GeraetID && nb.GeraetID != 0 {
b.GeraetID = nb.GeraetID b.GeraetID = nb.GeraetID
} }
if(b.Timestamp != nb.Timestamp){ if b.Timestamp != nb.Timestamp {
b.Timestamp = nb.Timestamp b.Timestamp = nb.Timestamp
} }
} }
@@ -203,7 +203,7 @@ func checkLastBooking(b Booking) bool {
log.Println("Error checking last booking: ", err) log.Println("Error checking last booking: ", err)
return false return false
} }
if int16(check_in_out) == b.CheckInOut { if int16(check_in_out)%2 == b.CheckInOut%2 {
return false return false
} }
return true return true
@@ -211,17 +211,17 @@ func checkLastBooking(b Booking) bool {
func (b *Booking) UpdateTime(newTime time.Time) { func (b *Booking) UpdateTime(newTime time.Time) {
hour, minute, _ := newTime.Clock() hour, minute, _ := newTime.Clock()
if(hour == b.Timestamp.Hour() && minute == b.Timestamp.Minute()){ if hour == b.Timestamp.Hour() && minute == b.Timestamp.Minute() {
return return
} }
// TODO: add check for time overlap // TODO: add check for time overlap
var newBooking Booking var newBooking Booking
newBooking.Timestamp = time.Date(b.Timestamp.Year(), b.Timestamp.Month(), b.Timestamp.Day(), hour, minute, 0, 0, time.Local) newBooking.Timestamp = time.Date(b.Timestamp.Year(), b.Timestamp.Month(), b.Timestamp.Day(), hour, minute, 0, 0, time.Local)
if(b.CheckInOut < 3){ if b.CheckInOut < 3 {
newBooking.CheckInOut = b.CheckInOut + 2 newBooking.CheckInOut = b.CheckInOut + 2
} }
if(b.CheckInOut == 255){ if b.CheckInOut == 255 {
newBooking.CheckInOut = 4 newBooking.CheckInOut = 4
} }
b.Update(newBooking) b.Update(newBooking)

View File

@@ -194,17 +194,38 @@ func parseUser(rows *sql.Rows) (User, error) {
return user, nil return user, nil
} }
// returns the start of the week, the last submission was made, submission == first booking or last send booking_report to team leader
func (u *User) GetLastSubmission() time.Time { func (u *User) GetLastSubmission() time.Time {
var lastSub time.Time var lastSub time.Time
qStr, err := DB.Prepare("SELECT woche_start FROM buchung_wochen WHERE personal_nummer = $1 ORDER BY woche_start DESC LIMIT 1") qStr, err := DB.Prepare(`
SELECT COALESCE(
(SELECT woche_start + INTERVAL '1 week' FROM wochen_report WHERE personal_nummer = $1 ORDER BY woche_start DESC LIMIT 1),
(SELECT timestamp FROM anwesenheit WHERE card_uid = $2 ORDER BY timestamp LIMIT 1)
) AS letzte_buchung;
`)
if err != nil { if err != nil {
log.Println("Error preparing statement!", err) log.Println("Error preparing statement!", err)
return lastSub return lastSub
} }
err = qStr.QueryRow(u.PersonalNummer).Scan(&lastSub) err = qStr.QueryRow(u.PersonalNummer, u.CardUID).Scan(&lastSub)
if err != nil { if err != nil {
log.Println("Error executing query!", err) log.Println("Error executing query!", err)
return lastSub return lastSub
} }
log.Println("From DB: ", lastSub)
lastSub = getMonday(lastSub)
lastSub = lastSub.Round(24 * time.Hour)
log.Println("After truncate: ", lastSub)
return lastSub return lastSub
} }
func getMonday(ts time.Time) time.Time {
if ts.Weekday() != time.Monday {
if ts.Weekday() == time.Sunday {
ts = ts.AddDate(0, 0, -6)
} else {
ts = ts.AddDate(0, 0, -int(ts.Weekday()-1))
}
}
return ts
}

View File

@@ -7,8 +7,8 @@ import (
) )
type WorkDay struct { type WorkDay struct {
Day time.Time Day time.Time `json:"day"`
Bookings []Booking Bookings []Booking `json:"bookings"`
workTime time.Duration workTime time.Duration
pauseTime time.Duration pauseTime time.Duration
} }

View File

@@ -1,27 +1,45 @@
package models package models
import ( import (
"errors"
"log" "log"
"time" "time"
) )
type WorkWeek struct { type WorkWeek struct {
Id int
WorkDays []WorkDay WorkDays []WorkDay
User User User User
WeekStart time.Time WeekStart time.Time
WorkHours time.Duration
} }
func (w *WorkWeek) GetWeek(user User, tsMonday time.Time) WorkWeek { func (w *WorkWeek) GetWeek(user User, tsMonday time.Time, populateDays bool) WorkWeek {
var week WorkWeek var week WorkWeek
if populateDays {
week.WorkDays = (*WorkDay).GetWorkDays(nil, user.CardUID, tsMonday, tsMonday.Add(7*24*time.Hour)) week.WorkDays = (*WorkDay).GetWorkDays(nil, user.CardUID, tsMonday, tsMonday.Add(7*24*time.Hour))
week.WorkHours = aggregateWorkTime(week.WorkDays)
}
week.User = user week.User = user
week.WeekStart = tsMonday week.WeekStart = tsMonday
return week return week
} }
func (w *WorkWeek) GetWorkHourString() string {
return formatDuration(w.WorkHours)
}
func aggregateWorkTime(days []WorkDay) time.Duration {
var workTime time.Duration
for _, day := range days {
workTime += day.workTime
}
return workTime
}
func (w *WorkWeek) GetSendWeeks(user User) []WorkWeek { func (w *WorkWeek) GetSendWeeks(user User) []WorkWeek {
var weeks []WorkWeek var weeks []WorkWeek
qStr, err := DB.Prepare(`SELECT woche_start::DATE FROM buchung_wochen WHERE bestaetigt = FALSE AND personal_nummer = $1;`) qStr, err := DB.Prepare(`SELECT id, woche_start::DATE FROM wochen_report WHERE bestaetigt = FALSE AND personal_nummer = $1;`)
if err != nil { if err != nil {
log.Println("Error preparing SQL statement", err) log.Println("Error preparing SQL statement", err)
return weeks return weeks
@@ -37,11 +55,12 @@ func (w *WorkWeek) GetSendWeeks(user User) []WorkWeek {
for rows.Next() { for rows.Next() {
var week WorkWeek var week WorkWeek
week.User = user week.User = user
if err := rows.Scan(&week.WeekStart); err != nil { if err := rows.Scan(&week.Id, &week.WeekStart); err != nil {
log.Println("Error scanning row!", err) log.Println("Error scanning row!", err)
return weeks return weeks
} }
week.WorkDays = (*WorkDay).GetWorkDays(nil, user.CardUID, week.WeekStart, week.WeekStart.Add(7*24*time.Hour)) week.WorkDays = (*WorkDay).GetWorkDays(nil, user.CardUID, week.WeekStart, week.WeekStart.Add(7*24*time.Hour))
week.WorkHours = aggregateWorkTime(week.WorkDays)
weeks = append(weeks, week) weeks = append(weeks, week)
} }
if err = rows.Err(); err != nil { if err = rows.Err(); err != nil {
@@ -50,3 +69,39 @@ func (w *WorkWeek) GetSendWeeks(user User) []WorkWeek {
return weeks return weeks
} }
var ErrRunningWeek = errors.New("Week is in running week")
// creates a new entry in the woche_report table with the given workweek
func (w *WorkWeek) Send() error {
if time.Since(w.WeekStart) < 5*24*time.Hour {
log.Println("Cannot send week, because it's the running week!")
return ErrRunningWeek
}
qStr, err := DB.Prepare(`INSERT INTO wochen_report (personal_nummer, woche_start) VALUES ($1, $2);`)
if err != nil {
log.Println("Error preparing SQL statement", err)
return err
}
_, err = qStr.Exec(w.User.PersonalNummer, w.WeekStart)
if err != nil {
log.Println("Error executing query!", err)
return err
}
return nil
}
func (w *WorkWeek) Accept() error {
qStr, err := DB.Prepare(`UPDATE "wochen_report" SET bestaetigt = TRUE WHERE personal_nummer = $1 AND woche_start = $2;`)
if err != nil {
log.Println("Error preparing SQL statement", err)
return err
}
_, err = qStr.Exec(w.User.PersonalNummer, w.WeekStart)
if err != nil {
log.Println("Error executing query!", err)
return err
}
return nil
}

View File

@@ -541,12 +541,6 @@
} }
} }
@layer utilities { @layer utilities {
.collapse {
visibility: collapse;
}
.relative {
position: relative;
}
.static { .static {
position: static; position: static;
} }
@@ -562,33 +556,18 @@
.mt-1 { .mt-1 {
margin-top: calc(var(--spacing) * 1); margin-top: calc(var(--spacing) * 1);
} }
.-mb-1 {
margin-bottom: calc(var(--spacing) * -1);
}
.mb-2 { .mb-2 {
margin-bottom: calc(var(--spacing) * 2); margin-bottom: calc(var(--spacing) * 2);
} }
.block {
display: block;
}
.flex { .flex {
display: flex; display: flex;
} }
.grid {
display: grid;
}
.hidden { .hidden {
display: none; display: none;
} }
.inline { .inline {
display: inline; display: inline;
} }
.inline-flex {
display: inline-flex;
}
.list-item {
display: list-item;
}
.table { .table {
display: table; display: table;
} }
@@ -615,9 +594,6 @@
.w-4 { .w-4 {
width: calc(var(--spacing) * 4); width: calc(var(--spacing) * 4);
} }
.w-9 {
width: calc(var(--spacing) * 9);
}
.w-9\/10 { .w-9\/10 {
width: calc(9/10 * 100%); width: calc(9/10 * 100%);
} }
@@ -633,18 +609,9 @@
.grow-1 { .grow-1 {
flex-grow: 1; flex-grow: 1;
} }
.border-collapse {
border-collapse: collapse;
}
.transform {
transform: var(--tw-rotate-x) var(--tw-rotate-y) var(--tw-rotate-z) var(--tw-skew-x) var(--tw-skew-y);
}
.cursor-pointer { .cursor-pointer {
cursor: pointer; cursor: pointer;
} }
.resize {
resize: both;
}
.grid-cols-2 { .grid-cols-2 {
grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-columns: repeat(2, minmax(0, 1fr));
} }
@@ -666,9 +633,6 @@
.justify-center { .justify-center {
justify-content: center; justify-content: center;
} }
.justify-end {
justify-content: flex-end;
}
.gap-2 { .gap-2 {
gap: calc(var(--spacing) * 2); gap: calc(var(--spacing) * 2);
} }
@@ -695,6 +659,11 @@
.justify-self-end { .justify-self-end {
justify-self: flex-end; justify-self: flex-end;
} }
.truncate {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.overflow-hidden { .overflow-hidden {
overflow: hidden; overflow: hidden;
} }
@@ -783,20 +752,9 @@
.uppercase { .uppercase {
text-transform: uppercase; text-transform: uppercase;
} }
.underline {
text-decoration-line: underline;
}
.outline {
outline-style: var(--tw-outline-style);
outline-width: 1px;
}
.filter { .filter {
filter: var(--tw-blur,) var(--tw-brightness,) var(--tw-contrast,) var(--tw-grayscale,) var(--tw-hue-rotate,) var(--tw-invert,) var(--tw-saturate,) var(--tw-sepia,) var(--tw-drop-shadow,); filter: var(--tw-blur,) var(--tw-brightness,) var(--tw-contrast,) var(--tw-grayscale,) var(--tw-hue-rotate,) var(--tw-invert,) var(--tw-saturate,) var(--tw-sepia,) var(--tw-drop-shadow,);
} }
.backdrop-filter {
-webkit-backdrop-filter: var(--tw-backdrop-blur,) var(--tw-backdrop-brightness,) var(--tw-backdrop-contrast,) var(--tw-backdrop-grayscale,) var(--tw-backdrop-hue-rotate,) var(--tw-backdrop-invert,) var(--tw-backdrop-opacity,) var(--tw-backdrop-saturate,) var(--tw-backdrop-sepia,);
backdrop-filter: var(--tw-backdrop-blur,) var(--tw-backdrop-brightness,) var(--tw-backdrop-contrast,) var(--tw-backdrop-grayscale,) var(--tw-backdrop-hue-rotate,) var(--tw-backdrop-invert,) var(--tw-backdrop-opacity,) var(--tw-backdrop-saturate,) var(--tw-backdrop-sepia,);
}
.transition { .transition {
transition-property: color, background-color, border-color, outline-color, text-decoration-color, fill, stroke, --tw-gradient-from, --tw-gradient-via, --tw-gradient-to, opacity, box-shadow, transform, translate, scale, rotate, filter, -webkit-backdrop-filter, backdrop-filter; transition-property: color, background-color, border-color, outline-color, text-decoration-color, fill, stroke, --tw-gradient-from, --tw-gradient-via, --tw-gradient-to, opacity, box-shadow, transform, translate, scale, rotate, filter, -webkit-backdrop-filter, backdrop-filter;
transition-timing-function: var(--tw-ease, var(--default-transition-timing-function)); transition-timing-function: var(--tw-ease, var(--default-transition-timing-function));
@@ -811,10 +769,6 @@
--tw-duration: 300ms; --tw-duration: 300ms;
transition-duration: 300ms; transition-duration: 300ms;
} }
.ease-in-out {
--tw-ease: var(--ease-in-out);
transition-timing-function: var(--ease-in-out);
}
.group-\[\.edit\]\:hidden { .group-\[\.edit\]\:hidden {
&:is(:where(.group):is(.edit) *) { &:is(:where(.group):is(.edit) *) {
display: none; display: none;
@@ -858,6 +812,13 @@
} }
} }
} }
.hover\:text-accent {
&:hover {
@media (hover: hover) {
color: var(--color-accent);
}
}
}
.hover\:text-white { .hover\:text-white {
&:hover { &:hover {
@media (hover: hover) { @media (hover: hover) {
@@ -1017,31 +978,6 @@
animation-timing-function: cubic-bezier(0, 0, 0.2, 1); animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
} }
} }
@property --tw-rotate-x {
syntax: "*";
inherits: false;
initial-value: rotateX(0);
}
@property --tw-rotate-y {
syntax: "*";
inherits: false;
initial-value: rotateY(0);
}
@property --tw-rotate-z {
syntax: "*";
inherits: false;
initial-value: rotateZ(0);
}
@property --tw-skew-x {
syntax: "*";
inherits: false;
initial-value: skewX(0);
}
@property --tw-skew-y {
syntax: "*";
inherits: false;
initial-value: skewY(0);
}
@property --tw-divide-x-reverse { @property --tw-divide-x-reverse {
syntax: "*"; syntax: "*";
inherits: false; inherits: false;
@@ -1061,11 +997,6 @@
syntax: "*"; syntax: "*";
inherits: false; inherits: false;
} }
@property --tw-outline-style {
syntax: "*";
inherits: false;
initial-value: solid;
}
@property --tw-blur { @property --tw-blur {
syntax: "*"; syntax: "*";
inherits: false; inherits: false;
@@ -1102,47 +1033,7 @@
syntax: "*"; syntax: "*";
inherits: false; inherits: false;
} }
@property --tw-backdrop-blur {
syntax: "*";
inherits: false;
}
@property --tw-backdrop-brightness {
syntax: "*";
inherits: false;
}
@property --tw-backdrop-contrast {
syntax: "*";
inherits: false;
}
@property --tw-backdrop-grayscale {
syntax: "*";
inherits: false;
}
@property --tw-backdrop-hue-rotate {
syntax: "*";
inherits: false;
}
@property --tw-backdrop-invert {
syntax: "*";
inherits: false;
}
@property --tw-backdrop-opacity {
syntax: "*";
inherits: false;
}
@property --tw-backdrop-saturate {
syntax: "*";
inherits: false;
}
@property --tw-backdrop-sepia {
syntax: "*";
inherits: false;
}
@property --tw-duration { @property --tw-duration {
syntax: "*"; syntax: "*";
inherits: false; inherits: false;
} }
@property --tw-ease {
syntax: "*";
inherits: false;
}

View File

@@ -3,6 +3,8 @@ package templates
import ( import (
"arbeitszeitmessung/models" "arbeitszeitmessung/models"
"fmt" "fmt"
"strconv"
"time"
) )
templ Base() { templ Base() {
@@ -69,30 +71,47 @@ templ UserPage(status int) {
</div> </div>
} }
templ TeamPage(weeks []models.WorkWeek, week models.WorkWeek) { templ TeamPage(weeks []models.WorkWeek, userWeek models.WorkWeek) {
{{ {{
year, kw := week.WeekStart.ISOWeek() year, kw := userWeek.WeekStart.ISOWeek()
}} }}
@Base() @Base()
@headerComponent() @headerComponent()
<div class="grid-main divide-y-1"> <div class="grid-main divide-y-1">
<div class="grid-sub divide-x-1 bg-neutral-300"> <div class="grid-sub divide-x-1 bg-neutral-300">
<div class="grid-cell font-bold uppercase">{ fmt.Sprintf("%s %s", week.User.Vorname, week.User.Name) }</div> <div class="grid-cell font-bold uppercase">{ fmt.Sprintf("%s %s", userWeek.User.Vorname, userWeek.User.Name) }</div>
<div class="grid-cell col-span-3 flex flex-col gap-2"> <div class="grid-cell col-span-3 flex flex-col gap-2">
for _, day := range week.WorkDays { for _, day := range userWeek.WorkDays {
@weekDayComponent(week.User, day) @weekDayComponent(userWeek.User, day)
} }
</div> </div>
<div class="grid-cell flex flex-col gap-2"> <form class="grid-cell flex flex-col gap-2" method="post">
<div> <div>
<p class="text-sm"><span class="">Woche:</span> { fmt.Sprintf("%02d-%d", kw, year) }</p> <p class="text-sm"><span class="">Woche:</span> { fmt.Sprintf("%02d-%d", kw, year) }</p>
<p class="text-sm">an Vorgesetzten senden</p> <p class="text-sm">an Vorgesetzten senden</p>
</div> </div>
<input type="hidden" name="method" value="send"/>
<input type="hidden" name="user" value={ strconv.Itoa(userWeek.User.PersonalNummer) }/>
<input type="hidden" name="week" value={ userWeek.WeekStart.Format(time.DateOnly) }/>
// if failed {
// <p>Fehlgeschlagen</p>
// }
<button type="submit" class="w-full cursor-pointer rounded-md text-neutral-800 p-2 md:px-4 border text-center text-sm hover:text-white transition-colors border-neutral-800 focus:bg-neutral-700 active:bg-neutral-700 hover:bg-neutral-700 disabled:pointer-events-none disabled:opacity-50">Senden</button> <button type="submit" class="w-full cursor-pointer rounded-md text-neutral-800 p-2 md:px-4 border text-center text-sm hover:text-white transition-colors border-neutral-800 focus:bg-neutral-700 active:bg-neutral-700 hover:bg-neutral-700 disabled:pointer-events-none disabled:opacity-50">Senden</button>
</div> </form>
</div> </div>
for _, week := range weeks { for _, week := range weeks {
@employeComponent(week) @employeComponent(week)
} }
</div> </div>
} }
templ NavPage() {
@Base()
<div class="w-full h-[100vh] flex flex-col justify-center items-center">
<div class="flex flex-col justify-between w-full md:w-1/2 py-2">
<a class="text-xl hover:text-accent transition-colors1" href="/time">Zeitverwaltung</a>
<a class="text-xl hover:text-accent transition-colors1" href="/team">Mitarbeiter</a>
<a class="text-xl hover:text-accent transition-colors1" href="/user">Nutzer</a>
</div>
</div>
}

View File

@@ -11,6 +11,8 @@ import templruntime "github.com/a-h/templ/runtime"
import ( import (
"arbeitszeitmessung/models" "arbeitszeitmessung/models"
"fmt" "fmt"
"strconv"
"time"
) )
func Base() templ.Component { func Base() templ.Component {
@@ -198,7 +200,7 @@ func UserPage(status int) templ.Component {
}) })
} }
func TeamPage(weeks []models.WorkWeek, week models.WorkWeek) templ.Component { func TeamPage(weeks []models.WorkWeek, userWeek models.WorkWeek) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
@@ -220,7 +222,7 @@ func TeamPage(weeks []models.WorkWeek, week models.WorkWeek) templ.Component {
} }
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
year, kw := week.WeekStart.ISOWeek() year, kw := userWeek.WeekStart.ISOWeek()
templ_7745c5c3_Err = Base().Render(ctx, templ_7745c5c3_Buffer) templ_7745c5c3_Err = Base().Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
@@ -234,9 +236,9 @@ func TeamPage(weeks []models.WorkWeek, week models.WorkWeek) templ.Component {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var6 string var templ_7745c5c3_Var6 string
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%s %s", week.User.Vorname, week.User.Name)) templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%s %s", userWeek.User.Vorname, userWeek.User.Name))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/pages.templ`, Line: 80, Col: 103} return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/pages.templ`, Line: 82, Col: 111}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
@@ -246,26 +248,52 @@ func TeamPage(weeks []models.WorkWeek, week models.WorkWeek) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
for _, day := range week.WorkDays { for _, day := range userWeek.WorkDays {
templ_7745c5c3_Err = weekDayComponent(week.User, day).Render(ctx, templ_7745c5c3_Buffer) templ_7745c5c3_Err = weekDayComponent(userWeek.User, day).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "</div><div class=\"grid-cell flex flex-col gap-2\"><div><p class=\"text-sm\"><span class=\"\">Woche:</span> ") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "</div><form class=\"grid-cell flex flex-col gap-2\" method=\"post\"><div><p class=\"text-sm\"><span class=\"\">Woche:</span> ")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var7 string var templ_7745c5c3_Var7 string
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%02d-%d", kw, year)) templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%02d-%d", kw, year))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/pages.templ`, Line: 88, Col: 87} return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/pages.templ`, Line: 90, Col: 87}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "</p><p class=\"text-sm\">an Vorgesetzten senden</p></div><button type=\"submit\" class=\"w-full cursor-pointer rounded-md text-neutral-800 p-2 md:px-4 border text-center text-sm hover:text-white transition-colors border-neutral-800 focus:bg-neutral-700 active:bg-neutral-700 hover:bg-neutral-700 disabled:pointer-events-none disabled:opacity-50\">Senden</button></div></div>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "</p><p class=\"text-sm\">an Vorgesetzten senden</p></div><input type=\"hidden\" name=\"method\" value=\"send\"> <input type=\"hidden\" name=\"user\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var8 string
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(userWeek.User.PersonalNummer))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/pages.templ`, Line: 94, Col: 87}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "\"> <input type=\"hidden\" name=\"week\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var9 string
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(userWeek.WeekStart.Format(time.DateOnly))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/pages.templ`, Line: 95, Col: 85}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "\"><button type=\"submit\" class=\"w-full cursor-pointer rounded-md text-neutral-800 p-2 md:px-4 border text-center text-sm hover:text-white transition-colors border-neutral-800 focus:bg-neutral-700 active:bg-neutral-700 hover:bg-neutral-700 disabled:pointer-events-none disabled:opacity-50\">Senden</button></form></div>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@@ -275,7 +303,40 @@ func TeamPage(weeks []models.WorkWeek, week models.WorkWeek) templ.Component {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "</div>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "</div>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
}
func NavPage() templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer {
defer func() {
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var10 := templ.GetChildren(ctx)
if templ_7745c5c3_Var10 == nil {
templ_7745c5c3_Var10 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Err = Base().Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "<div class=\"w-full h-[100vh] flex flex-col justify-center items-center\"><div class=\"flex flex-col justify-between w-full md:w-1/2 py-2\"><a class=\"text-xl hover:text-accent transition-colors1\" href=\"/time\">Zeitverwaltung</a> <a class=\"text-xl hover:text-accent transition-colors1\" href=\"/team\">Mitarbeiter</a> <a class=\"text-xl hover:text-accent transition-colors1\" href=\"/user\">Nutzer</a></div></div>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }

View File

@@ -1,8 +1,11 @@
package templates package templates
import "arbeitszeitmessung/models" import (
"arbeitszeitmessung/models"
import "fmt" "fmt"
"strconv"
"time"
)
templ weekDayComponent(user models.User, day models.WorkDay) { templ weekDayComponent(user models.User, day models.WorkDay) {
{{ work, pause := day.GetWorkTimeString() }} {{ work, pause := day.GetWorkTimeString() }}
@@ -26,18 +29,21 @@ templ employeComponent(week models.WorkWeek) {
<div class="grid-cell"> <div class="grid-cell">
<p class="font-bold uppercase">{ week.User.Vorname } { week.User.Name }</p> <p class="font-bold uppercase">{ week.User.Vorname } { week.User.Name }</p>
<p class="text-sm">Arbeitszeit</p> <p class="text-sm">Arbeitszeit</p>
<p class="text-accent">40h 12min</p> <p class="text-accent">{ week.GetWorkHourString() }</p>
</div> </div>
<div class="grid-cell col-span-3 flex flex-col gap-2"> <div class="grid-cell col-span-3 flex flex-col gap-2">
for _, day := range week.WorkDays { for _, day := range week.WorkDays {
@weekDayComponent(week.User, day) @weekDayComponent(week.User, day)
} }
</div> </div>
<div class="grid-cell flex flex-col justify-between gap-2"> <form class="grid-cell flex flex-col justify-between gap-2" method="post">
<p class="text-sm"><span class="">Woche:</span> { fmt.Sprintf("%02d-%d", kw, year) }</p> <p class="text-sm"><span class="">Woche:</span> { fmt.Sprintf("%02d-%d", kw, year) }</p>
<input type="hidden" name="method" value="accept"/>
<input type="hidden" name="user" value={ strconv.Itoa(week.User.PersonalNummer) }/>
<input type="hidden" name="week" value={ week.WeekStart.Format(time.DateOnly) }/>
<button type="submit" class="w-full bg-neutral-100 cursor-pointer rounded-md text-neutral-800 p-2 md:px-4 border text-center text-sm hover:text-white transition-colors border-neutral-900 focus:bg-neutral-700 active:bg-neutral-700 hover:bg-neutral-700 disabled:pointer-events-none disabled:opacity-50"> <button type="submit" class="w-full bg-neutral-100 cursor-pointer rounded-md text-neutral-800 p-2 md:px-4 border text-center text-sm hover:text-white transition-colors border-neutral-900 focus:bg-neutral-700 active:bg-neutral-700 hover:bg-neutral-700 disabled:pointer-events-none disabled:opacity-50">
<p class="">Bestätigen</p> <p class="">Bestätigen</p>
</button> </button>
</div> </form>
</div> </div>
} }

View File

@@ -8,9 +8,12 @@ package templates
import "github.com/a-h/templ" import "github.com/a-h/templ"
import templruntime "github.com/a-h/templ/runtime" import templruntime "github.com/a-h/templ/runtime"
import "arbeitszeitmessung/models" import (
"arbeitszeitmessung/models"
import "fmt" "fmt"
"strconv"
"time"
)
func weekDayComponent(user models.User, day models.WorkDay) templ.Component { func weekDayComponent(user models.User, day models.WorkDay) templ.Component {
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
@@ -49,7 +52,7 @@ func weekDayComponent(user models.User, day models.WorkDay) templ.Component {
var templ_7745c5c3_Var2 string var templ_7745c5c3_Var2 string
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(day.Day.Format("Mon")) templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(day.Day.Format("Mon"))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/teamComponents.templ`, Line: 12, Col: 89} return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/teamComponents.templ`, Line: 15, Col: 89}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
@@ -62,7 +65,7 @@ func weekDayComponent(user models.User, day models.WorkDay) templ.Component {
var templ_7745c5c3_Var3 string var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(day.Day.Format("02.01.2006")) templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(day.Day.Format("02.01.2006"))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/teamComponents.templ`, Line: 12, Col: 130} return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/teamComponents.templ`, Line: 15, Col: 130}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
@@ -75,7 +78,7 @@ func weekDayComponent(user models.User, day models.WorkDay) templ.Component {
var templ_7745c5c3_Var4 string var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(work) templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(work)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/teamComponents.templ`, Line: 14, Col: 36} return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/teamComponents.templ`, Line: 17, Col: 36}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
@@ -88,7 +91,7 @@ func weekDayComponent(user models.User, day models.WorkDay) templ.Component {
var templ_7745c5c3_Var5 string var templ_7745c5c3_Var5 string
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(pause) templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(pause)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/teamComponents.templ`, Line: 15, Col: 42} return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/teamComponents.templ`, Line: 18, Col: 42}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
@@ -132,7 +135,7 @@ func employeComponent(week models.WorkWeek) templ.Component {
var templ_7745c5c3_Var7 string var templ_7745c5c3_Var7 string
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(week.User.Vorname) templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(week.User.Vorname)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/teamComponents.templ`, Line: 27, Col: 53} return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/teamComponents.templ`, Line: 30, Col: 53}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
@@ -145,13 +148,26 @@ func employeComponent(week models.WorkWeek) templ.Component {
var templ_7745c5c3_Var8 string var templ_7745c5c3_Var8 string
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(week.User.Name) templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(week.User.Name)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/teamComponents.templ`, Line: 27, Col: 72} return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/teamComponents.templ`, Line: 30, Col: 72}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "</p><p class=\"text-sm\">Arbeitszeit</p><p class=\"text-accent\">40h 12min</p></div><div class=\"grid-cell col-span-3 flex flex-col gap-2\">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "</p><p class=\"text-sm\">Arbeitszeit</p><p class=\"text-accent\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var9 string
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(week.GetWorkHourString())
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/teamComponents.templ`, Line: 32, Col: 52}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "</p></div><div class=\"grid-cell col-span-3 flex flex-col gap-2\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@@ -161,20 +177,46 @@ func employeComponent(week models.WorkWeek) templ.Component {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "</div><div class=\"grid-cell flex flex-col justify-between gap-2\"><p class=\"text-sm\"><span class=\"\">Woche:</span> ") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "</div><form class=\"grid-cell flex flex-col justify-between gap-2\" method=\"post\"><p class=\"text-sm\"><span class=\"\">Woche:</span> ")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var9 string var templ_7745c5c3_Var10 string
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%02d-%d", kw, year)) templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%02d-%d", kw, year))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/teamComponents.templ`, Line: 37, Col: 85} return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/teamComponents.templ`, Line: 40, Col: 85}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "</p><button type=\"submit\" class=\"w-full bg-neutral-100 cursor-pointer rounded-md text-neutral-800 p-2 md:px-4 border text-center text-sm hover:text-white transition-colors border-neutral-900 focus:bg-neutral-700 active:bg-neutral-700 hover:bg-neutral-700 disabled:pointer-events-none disabled:opacity-50\"><p class=\"\">Bestätigen</p></button></div></div>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "</p><input type=\"hidden\" name=\"method\" value=\"accept\"> <input type=\"hidden\" name=\"user\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var11 string
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(week.User.PersonalNummer))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/teamComponents.templ`, Line: 42, Col: 82}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "\"> <input type=\"hidden\" name=\"week\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var12 string
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(week.WeekStart.Format(time.DateOnly))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/teamComponents.templ`, Line: 43, Col: 80}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "\"> <button type=\"submit\" class=\"w-full bg-neutral-100 cursor-pointer rounded-md text-neutral-800 p-2 md:px-4 border text-center text-sm hover:text-white transition-colors border-neutral-900 focus:bg-neutral-700 active:bg-neutral-700 hover:bg-neutral-700 disabled:pointer-events-none disabled:opacity-50\"><p class=\"\">Bestätigen</p></button></form></div>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }

View File

@@ -61,12 +61,13 @@ EXECUTE FUNCTION update_zuletzt_geandert();
-- audittabelle für arbeitsstunden bestätigung -- audittabelle für arbeitsstunden bestätigung
DROP TABLE IF EXISTS "buchung_wochen"; DROP TABLE IF EXISTS "wochen_report";
CREATE TABLE "buchung_wochen" ( CREATE TABLE "wochen_report" (
"id" serial PRIMARY KEY, "id" serial PRIMARY KEY,
"personal_nummer" int4, "personal_nummer" int4,
"woche_start" date, "woche_start" date,
"bestaetigt" bool DEFAULT FALSE "bestaetigt" bool DEFAULT FALSE,
UNIQUE ("personal_nummer", "woche_start")
); );
-- Adds crypto extension -- Adds crypto extension

View File

@@ -7,7 +7,7 @@ psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-E
CREATE USER $POSTGRES_API_USER WITH ENCRYPTED PASSWORD '$POSTGRES_API_PASSWORD'; CREATE USER $POSTGRES_API_USER WITH ENCRYPTED PASSWORD '$POSTGRES_API_PASSWORD';
GRANT CONNECT ON DATABASE $POSTGRES_DB TO $POSTGRES_API_USER; GRANT CONNECT ON DATABASE $POSTGRES_DB TO $POSTGRES_API_USER;
GRANT USAGE ON SCHEMA public TO $POSTGRES_API_USER; GRANT USAGE ON SCHEMA public TO $POSTGRES_API_USER;
GRANT SELECT, INSERT, UPDATE ON anwesenheit, personal_daten, user_password, buchung_wochen TO $POSTGRES_API_USER; GRANT SELECT, INSERT, UPDATE ON anwesenheit, personal_daten, user_password, wochen_report TO $POSTGRES_API_USER;
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO $POSTGRES_API_USER; GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO $POSTGRES_API_USER;
EOSQL EOSQL

View File

@@ -11,7 +11,12 @@
}, },
"servers": [ "servers": [
{ {
"url": "http://localhost:8000" "url": "http://localhost:8000",
"description": "Docker Server"
},
{
"url": "http://localhost:8080",
"description": "Local Development"
} }
], ],
"tags": [ "tags": [
@@ -22,55 +27,11 @@
], ],
"paths": { "paths": {
"/time": { "/time": {
"put": {
"tags": ["booking"],
"summary": "Update a existing booking",
"description": "Update an existing booking by Id",
"operationId": "updateBooking",
"parameters": [
{
"name": "counter_id",
"in": "query",
"description": "Booking ID to update",
"required": true,
"schema": {
"type": "string"
}
}
],
"requestBody": {
"description": "Update an existent booking in the db. Not all values have to be updated",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Booking"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Booking Updated",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Booking"
}
}
}
},
"400": {
"description": "Invalid ID supplied"
},
"500": {
"description": "Server Error"
}
}
},
"get": { "get": {
"tags": ["booking"], "tags": [
"summary": "Gets all the bookings limited", "booking"
],
"summary": "Gets all the bookings from one card_uid",
"description": "Returns all the bookings optionally filtered with cardID", "description": "Returns all the bookings optionally filtered with cardID",
"operationId": "getBooking", "operationId": "getBooking",
"parameters": [ "parameters": [
@@ -78,10 +39,30 @@
"name": "card_uid", "name": "card_uid",
"in": "query", "in": "query",
"description": "CardID to filter for", "description": "CardID to filter for",
"required": false, "required": true,
"schema": { "schema": {
"type": "string" "type": "string"
} }
},
{
"name": "time_from",
"in": "query",
"description": "Timestamp since when all bookings are shown (default=1 month ago)",
"required": false,
"schema": {
"type": "string",
"example": "2025-02-28"
}
},
{
"name": "time_to",
"in": "query",
"description": "Timestamp till when all bookings are shown (default=today)",
"required": false,
"schema": {
"type": "string",
"example": "2025-02-28"
}
} }
], ],
"responses": { "responses": {
@@ -92,7 +73,51 @@
"schema": { "schema": {
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/components/schemas/Booking" "type": "object",
"properties": {
"day": {
"type": "string",
"format": "date"
},
"bookings": {
"type": "array",
"items": {
"type": "object",
"properties": {
"counter_id": {
"type": "integer",
"format": "int64",
"example": 100
},
"card_uid": {
"type": "string",
"example": "test_card"
},
"geraet_id": {
"type": "string",
"example": "test_reader"
},
"check_in_out": {
"type": "integer",
"example": 1,
"enum": [
1,
2,
255
]
},
"timestamp": {
"type": "string",
"format": "date-time",
"example": "2024-09-05T08:51:12.670Z"
}
},
"xml": {
"name": "booking"
}
}
}
}
} }
} }
} }
@@ -106,11 +131,21 @@
}, },
"/time/new": { "/time/new": {
"put": { "put": {
"tags": ["booking"], "tags": [
"booking"
],
"summary": "Create new Booking", "summary": "Create new Booking",
"description": "Creates a new booking with the supplied parameters", "description": "Creates a new booking with the supplied parameters",
"operationId": "pcreateBooking", "operationId": "pcreateBooking",
"parameters": [ "parameters": [
{
"in": "header",
"name": "Authorization",
"description": "Predefined API Key to authorize access",
"schema": {
"type": "string"
}
},
{ {
"name": "card_uid", "name": "card_uid",
"in": "query", "in": "query",
@@ -136,7 +171,11 @@
"required": true, "required": true,
"schema": { "schema": {
"type": "integer", "type": "integer",
"enum": [1, 2, 255] "enum": [
1,
2,
255
]
} }
} }
], ],
@@ -146,7 +185,39 @@
"content": { "content": {
"application/json": { "application/json": {
"schema": { "schema": {
"$ref": "#/components/schemas/Booking" "type": "object",
"properties": {
"counter_id": {
"type": "integer",
"format": "int64",
"example": 100
},
"card_uid": {
"type": "string",
"example": "test_card"
},
"geraet_id": {
"type": "string",
"example": "test_reader"
},
"check_in_out": {
"type": "integer",
"example": 1,
"enum": [
1,
2,
255
]
},
"timestamp": {
"type": "string",
"format": "date-time",
"example": "2024-09-05T08:51:12.670Z"
}
},
"xml": {
"name": "booking"
}
} }
} }
} }
@@ -157,11 +228,30 @@
} }
}, },
"get": { "get": {
"tags": ["booking"], "tags": [
"booking"
],
"summary": "Create new Booking", "summary": "Create new Booking",
"description": "Creates a new booking with the supplied parameters", "description": "Creates a new booking with the supplied parameters",
"operationId": "gcreateBooking", "operationId": "gcreateBooking",
"parameters": [ "parameters": [
{
"in": "header",
"name": "Authorization",
"description": "Predefined API Key to authorize access",
"schema": {
"type": "string"
}
},
{
"in": "query",
"name": "api_key",
"description": "Predefined API Key to authorize access",
"required": false,
"schema": {
"type": "string"
}
},
{ {
"name": "card_uid", "name": "card_uid",
"in": "query", "in": "query",
@@ -187,7 +277,11 @@
"required": true, "required": true,
"schema": { "schema": {
"type": "integer", "type": "integer",
"enum": [1, 2, 255] "enum": [
1,
2,
255
]
} }
} }
], ],
@@ -197,10 +291,45 @@
"content": { "content": {
"application/json": { "application/json": {
"schema": { "schema": {
"$ref": "#/components/schemas/Booking" "type": "object",
"properties": {
"counter_id": {
"type": "integer",
"format": "int64",
"example": 100
},
"card_uid": {
"type": "string",
"example": "test_card"
},
"geraet_id": {
"type": "string",
"example": "test_reader"
},
"check_in_out": {
"type": "integer",
"example": 1,
"enum": [
1,
2,
255
]
},
"timestamp": {
"type": "string",
"format": "date-time",
"example": "2024-09-05T08:51:12.670Z"
}
},
"xml": {
"name": "booking"
} }
} }
} }
}
},
"401": {
"description": "none or wrong api key provided!"
}, },
"409": { "409": {
"description": "Same booking type as last booking" "description": "Same booking type as last booking"
@@ -210,7 +339,9 @@
}, },
"/logout": { "/logout": {
"get": { "get": {
"tags": ["booking"], "tags": [
"booking"
],
"summary": "Logs out all logged in users", "summary": "Logs out all logged in users",
"description": "With this call all actively logged in users (last booking today has check_in_out=1) will be logged out automaticly (check_in_out=255)", "description": "With this call all actively logged in users (last booking today has check_in_out=1) will be logged out automaticly (check_in_out=255)",
"operationId": "autoLogout", "operationId": "autoLogout",
@@ -222,7 +353,26 @@
"schema": { "schema": {
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/components/schemas/User" "type": "object",
"properties": {
"card_uid": {
"type": "string",
"example": "test_card"
},
"name": {
"type": "string",
"example": "Mustermann"
},
"vorname": {
"type": "string",
"example": "Max"
},
"hauptbeschäftigungsort": {
"type": "integer",
"format": "int8",
"example": 1
}
}
} }
} }
} }
@@ -234,6 +384,53 @@
}, },
"components": { "components": {
"schemas": { "schemas": {
"BookingGrouped": {
"type": "object",
"properties": {
"day": {
"type": "string",
"format": "date"
},
"bookings": {
"type": "array",
"items": {
"type": "object",
"properties": {
"counter_id": {
"type": "integer",
"format": "int64",
"example": 100
},
"card_uid": {
"type": "string",
"example": "test_card"
},
"geraet_id": {
"type": "string",
"example": "test_reader"
},
"check_in_out": {
"type": "integer",
"example": 1,
"enum": [
1,
2,
255
]
},
"timestamp": {
"type": "string",
"format": "date-time",
"example": "2024-09-05T08:51:12.670Z"
}
},
"xml": {
"name": "booking"
}
}
}
}
},
"Booking": { "Booking": {
"type": "object", "type": "object",
"properties": { "properties": {
@@ -253,7 +450,11 @@
"check_in_out": { "check_in_out": {
"type": "integer", "type": "integer",
"example": 1, "example": 1,
"enum": [1, 2, 255] "enum": [
1,
2,
255
]
}, },
"timestamp": { "timestamp": {
"type": "string", "type": "string",

View File

@@ -1,74 +1,58 @@
openapi: 3.0.3 openapi: 3.0.3
info: info:
title: Arbeitszeitmessung - OpenAPI 3.0 title: Arbeitszeitmessung - OpenAPI 3.0
description: 'This demos the API for the Arbeitszeitmessung Project ' description: "This demos the API for the Arbeitszeitmessung Project "
version: 0.1.0 version: 0.1.0
externalDocs: externalDocs:
description: Git-Repository description: Git-Repository
url: https://git.letsstein.de/tom/arbeitszeitmessung url: https://git.letsstein.de/tom/arbeitszeitmessung
servers: servers:
- url: http://localhost:8000 - url: http://localhost:8000
description: Docker Server
- url: http://localhost:8080
description: Local Development
tags: tags:
- name: booking - name: booking
description: all Bookings description: all Bookings
paths: paths:
/time: /time:
put:
tags:
- booking
summary: Update a existing booking
description: Update an existing booking by Id
operationId: updateBooking
parameters:
- name: counter_id
in: query
description: Booking ID to update
required: true
schema:
type: string
requestBody:
description: >-
Update an existent booking in the db. Not all values have to be
updated
content:
application/json:
schema:
$ref: '#/components/schemas/Booking'
required: true
responses:
'200':
description: Booking Updated
content:
application/json:
schema:
$ref: '#/components/schemas/Booking'
'400':
description: Invalid ID supplied
'500':
description: Server Error
get: get:
tags: tags:
- booking - booking
summary: Gets all the bookings limited summary: Gets all the bookings from one card_uid
description: Returns all the bookings optionally filtered with cardID description: Returns all the bookings optionally filtered with cardID
operationId: getBooking operationId: getBooking
parameters: parameters:
- name: card_uid - name: card_uid
in: query in: query
description: CardID to filter for description: CardID to filter for
required: true
schema:
type: string
- name: time_from
in: query
description: Timestamp since when all bookings are shown (default=1 month ago)
required: false required: false
schema: schema:
type: string type: string
example: "2025-02-28"
- name: time_to
in: query
description: Timestamp till when all bookings are shown (default=today)
required: false
schema:
type: string
example: "2025-02-28"
responses: responses:
'200': "200":
description: Successful operation description: Successful operation
content: content:
application/json: application/json:
schema: schema:
type: array type: array
items: items:
$ref: '#/components/schemas/Booking' $ref: "#/components/schemas/BookingGrouped"
'400': "400":
description: Invalid cardID description: Invalid cardID
/time/new: /time/new:
put: put:
@@ -78,6 +62,11 @@ paths:
description: Creates a new booking with the supplied parameters description: Creates a new booking with the supplied parameters
operationId: pcreateBooking operationId: pcreateBooking
parameters: parameters:
- in: header
name: Authorization
description: Predefined API Key to authorize access
schema:
type: string
- name: card_uid - name: card_uid
in: query in: query
description: id of the RFID card scanned description: id of the RFID card scanned
@@ -101,13 +90,13 @@ paths:
- 2 - 2
- 255 - 255
responses: responses:
'200': "200":
description: successfully created booking description: successfully created booking
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/Booking' $ref: "#/components/schemas/Booking"
'409': "409":
description: Same booking type as last booking description: Same booking type as last booking
get: get:
tags: tags:
@@ -116,6 +105,17 @@ paths:
description: Creates a new booking with the supplied parameters description: Creates a new booking with the supplied parameters
operationId: gcreateBooking operationId: gcreateBooking
parameters: parameters:
- in: header
name: Authorization
description: Predefined API Key to authorize access
schema:
type: string
- in: query
name: api_key
description: Predefined API Key to authorize access
required: false
schema:
type: string
- name: card_uid - name: card_uid
in: query in: query
description: id of the RFID card scanned description: id of the RFID card scanned
@@ -139,13 +139,15 @@ paths:
- 2 - 2
- 255 - 255
responses: responses:
'200': "200":
description: successfully created booking description: successfully created booking
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/Booking' $ref: "#/components/schemas/Booking"
'409': "401":
description: none or wrong api key provided!
"409":
description: Same booking type as last booking description: Same booking type as last booking
/logout: /logout:
get: get:
@@ -155,16 +157,26 @@ paths:
description: With this call all actively logged in users (last booking today has check_in_out=1) will be logged out automaticly (check_in_out=255) description: With this call all actively logged in users (last booking today has check_in_out=1) will be logged out automaticly (check_in_out=255)
operationId: autoLogout operationId: autoLogout
responses: responses:
'200': "200":
description: Succesful description: Succesful
content: content:
application/json: application/json:
schema: schema:
type: array type: array
items: items:
$ref: '#/components/schemas/User' $ref: "#/components/schemas/User"
components: components:
schemas: schemas:
BookingGrouped:
type: object
properties:
day:
type: string
format: date
bookings:
type: array
items:
$ref: "#/components/schemas/Booking"
Booking: Booking:
type: object type: object
properties: properties:
@@ -188,7 +200,7 @@ components:
timestamp: timestamp:
type: string type: string
format: date-time format: date-time
example: '2024-09-05T08:51:12.670Z' example: "2024-09-05T08:51:12.670Z"
xml: xml:
name: booking name: booking
User: User:

View File

@@ -20,16 +20,16 @@ services:
- 8001:8080 - 8001:8080
backend: backend:
build: ../Backend build: ../Backend
image: git.letsstein.de/tom/arbeitszeit-backend image: git.letsstein.de/tom/arbeitszeit-backend:0.1.1
env_file: env_file:
- .env - .env
environment: environment:
POSTGRES_HOST: db POSTGRES_HOST: db
POSTGRES_DB: ${POSTGRES_DB} POSTGRES_DB: ${POSTGRES_DB}
EXPOSED_PORT: ${EXPOSED_PORT} EXPOSED_PORT: ${EXPOSED_PORT}
DEBUG: true NO_CORS: true
ports: ports:
- 8000:8080 - ${EXPOSED_PORT}:8080
depends_on: depends_on:
- db - db
swagger: swagger:

View File

@@ -13,6 +13,8 @@ services:
volumes: volumes:
- ${POSTGRES_PATH}:/var/lib/postgresql/data - ${POSTGRES_PATH}:/var/lib/postgresql/data
- ${POSTGRES_PATH}/initdb:/docker-entrypoint-initdb.d - ${POSTGRES_PATH}/initdb:/docker-entrypoint-initdb.d
ports:
- 5432:5432
backend: backend:
image: git.letsstein.de/tom/arbeitszeit-backend image: git.letsstein.de/tom/arbeitszeit-backend