small fixes and refactoring

This commit is contained in:
2025-04-10 09:11:17 +02:00
parent e60f19ee27
commit 19251eefed
10 changed files with 34 additions and 15 deletions

View File

@@ -1,6 +1,7 @@
package models
import (
"arbeitszeitmessung/helper"
"database/sql"
"fmt"
"log"
@@ -161,16 +162,23 @@ func (b Booking) Save() {
}
func (b *Booking) GetBookingType() string {
debug := (helper.GetEnv("GO_ENV", "production") == "debug")
switch b.CheckInOut {
case 1: //manuelle Änderung
return "kommen"
case 3:
if(debug){
return "kommen manuell"
}
return "kommen"
case 2: //manuelle Änderung
return "gehen"
case 4:
if(debug){
return "gehen manuell"
case 255:
}
return "gehen"
case 254:
return "abgemeldet"
default:
return "Buchungs Typ unbekannt"
@@ -221,11 +229,11 @@ func (b *Booking) UpdateTime(newTime time.Time) {
// TODO: add check for time overlap
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, b.Timestamp.Location())
if b.CheckInOut < 3 {
newBooking.CheckInOut = b.CheckInOut + 2
}
if b.CheckInOut == 255 {
if b.CheckInOut == 254 {
newBooking.CheckInOut = 4
}
b.Update(newBooking)

View File

@@ -68,7 +68,7 @@ func (u *User) GetAll() ([]User, error) {
// Returns true if there is a booking 1 for today -> meaning the user is at work
// Returns false if there is no booking today or the user is already booked out of the system
func (u *User) CheckAnwesenheit() bool {
qStr, err := DB.Prepare((`SELECT check_in_out FROM anwesenheit WHERE card_uid = $1 AND "timestamp" >= now()::date + interval '1h' ORDER BY "timestamp" DESC`))
qStr, err := DB.Prepare((`SELECT check_in_out FROM anwesenheit WHERE card_uid = $1 AND "timestamp" >= now()::date + interval '1h' ORDER BY "timestamp" DESC LIMIT 1;`))
if err != nil {
fmt.Printf("Error preparing query statement %v\n", err)
return false
@@ -79,12 +79,12 @@ func (u *User) CheckAnwesenheit() bool {
if err != nil {
return false
}
return check_in_out == 1
return check_in_out%2 == 1
}
// Creates a new booking for the user -> check_in_out will be 255 for automatic check out
// Creates a new booking for the user -> check_in_out will be 254 for automatic check out
func (u *User) Logout() error {
booking := (*Booking).New(nil, u.CardUID, 0, 255)
booking := (*Booking).New(nil, u.CardUID, 0, 254)
err := booking.Insert()
if err != nil {
fmt.Printf("Error inserting booking %v\n", err)