feat: updated docs and added description to files
This commit is contained in:
@@ -1,8 +1,19 @@
|
||||
// the models package contains the datamodels for the whole webserver
|
||||
// most of them are also in the DB
|
||||
//
|
||||
// in the future it would be good to change it to create a repository structure,
|
||||
// so that there would be a second pacakge handling db requests
|
||||
|
||||
package models
|
||||
|
||||
// this file has all functions and types to handle absences
|
||||
// the absence type implements the iWorkDay interface so that
|
||||
// it can be used as one workday
|
||||
//
|
||||
// the absence data is based on the entries in the "abwesenheit" database table
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
@@ -27,25 +38,6 @@ func (a *Absence) IsEmpty() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func NewAbsence(card_uid string, abwesenheit_typ int, datum time.Time) (Absence, error) {
|
||||
if abwesenheit_typ < 0 {
|
||||
return Absence{
|
||||
CardUID: card_uid,
|
||||
AbwesenheitTyp: AbsenceType{0, "Custom absence", 100},
|
||||
DateFrom: datum,
|
||||
}, nil
|
||||
}
|
||||
_absenceType, ok := GetAbsenceTypesCached()[int8(abwesenheit_typ)]
|
||||
if !ok {
|
||||
return Absence{}, errors.New("Invalid absencetype")
|
||||
}
|
||||
return Absence{
|
||||
CardUID: card_uid,
|
||||
AbwesenheitTyp: _absenceType,
|
||||
DateFrom: datum,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a *Absence) Date() time.Time {
|
||||
return a.Day.Truncate(24 * time.Hour)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package models_test
|
||||
|
||||
// all the files with *_test.go are used to test the functions inside the respective file
|
||||
// the tests are partially complete
|
||||
|
||||
import (
|
||||
"arbeitszeitmessung/helper"
|
||||
"arbeitszeitmessung/models"
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package models
|
||||
|
||||
// this file has all functions and types to handle bookings
|
||||
// the bookings itself are later combined to a workday to save on
|
||||
// db requests and computation
|
||||
//
|
||||
// the booking data is based on the entries in the "anwesenheit" database table
|
||||
|
||||
import (
|
||||
"arbeitszeitmessung/helper"
|
||||
"arbeitszeitmessung/helper/logs"
|
||||
@@ -39,7 +45,7 @@ type IDatabase interface {
|
||||
|
||||
var DB IDatabase
|
||||
|
||||
func (b *Booking) New(cardUid string, gereatId int16, checkInOut int16, typeId int8) Booking {
|
||||
func (b *Booking) NewBooking(cardUid string, gereatId int16, checkInOut int16, typeId int8) Booking {
|
||||
bookingType, err := GetBookingTypeById(typeId)
|
||||
if err != nil {
|
||||
log.Printf("Cannot get booking type %d, from database!", typeId)
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
package models
|
||||
|
||||
// this file contains all functions for the compound day class
|
||||
// the compound can merge all kinds of daytypes together, as long as they
|
||||
// implement the IWorkDay interface. This is used to have an absence + bookings
|
||||
// in one day
|
||||
//
|
||||
// the compound day is a meta type, which means its not in the database
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package models
|
||||
|
||||
// this file is only used as cache for the diffenrent absence and booking types,
|
||||
// in the future this should be two chaching variables each in their own place
|
||||
|
||||
import (
|
||||
"arbeitszeitmessung/helper"
|
||||
)
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package models
|
||||
|
||||
// this file desribes the IWorkDay interface which is used, to combine the diffent kinds
|
||||
// of day types (absence, holidy, workday) and make them more compatimble with the rest
|
||||
//
|
||||
// the IWorkDay as an interface is not in the database
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package models
|
||||
|
||||
// the public holiday is used the describe all holidays
|
||||
// the publicholiday implements the IWorkDay interface
|
||||
//
|
||||
// the PublicHoliday data is based on the entries in the "s_feiertage" database table
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package models
|
||||
|
||||
// the user type represents the user of the software
|
||||
// it has functions to request the bookings and other data based
|
||||
// on either the "PersonalNummer" or "CardUID"
|
||||
//
|
||||
// users and their passwords are stored in the "s_personal_daten" and "user_pass" tables
|
||||
|
||||
import (
|
||||
"arbeitszeitmessung/helper"
|
||||
"context"
|
||||
@@ -149,7 +155,7 @@ func (u *User) CheckAnwesenheit() bool {
|
||||
|
||||
// Creates a new booking for the user -> check_in_out will be 254 for automatic check out
|
||||
func (u *User) CheckOut() error {
|
||||
booking := (*Booking).New(nil, u.CardUID, 0, 254, 1)
|
||||
booking := (*Booking).NewBooking(nil, u.CardUID, 0, 254, 1)
|
||||
err := booking.Insert()
|
||||
if err != nil {
|
||||
fmt.Printf("Error inserting booking %v -> %v\n", booking, err)
|
||||
@@ -282,15 +288,6 @@ func (u *User) GetNextWeek() WorkWeek {
|
||||
|
||||
}
|
||||
|
||||
func parseUser(rows *sql.Rows) (User, error) {
|
||||
var user User
|
||||
if err := rows.Scan(&user.PersonalNummer, &user.CardUID, &user.Vorname, &user.Name, &user.ArbeitszeitPerTag); err != nil {
|
||||
log.Println("Error scanning row!", err)
|
||||
return user, err
|
||||
}
|
||||
return user, nil
|
||||
}
|
||||
|
||||
// returns the start of the week, the last submission was made, submission == first booking or last send wochen_report to team leader
|
||||
func (u *User) GetLastWorkWeekSubmission() time.Time {
|
||||
var lastSub time.Time
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package models
|
||||
|
||||
// the workday combines all bookings of a day into a single type and is the third
|
||||
// type of workday which implements the IWorkDay interface
|
||||
//
|
||||
// this is a meta type and not present in the db
|
||||
|
||||
import (
|
||||
"arbeitszeitmessung/helper"
|
||||
"encoding/json"
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package models
|
||||
|
||||
// the WorkWeek describes the weekly reports used the check on worktimes and
|
||||
// calculate the running overtime
|
||||
//
|
||||
// this type is based on the "wochen_report" table
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
|
||||
Reference in New Issue
Block a user