some minor improvements
This commit is contained in:
parent
28013fac4a
commit
0c99d186a4
3 changed files with 16 additions and 11 deletions
6
.vscode/launch.json
vendored
6
.vscode/launch.json
vendored
|
@ -6,7 +6,11 @@
|
|||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "auto",
|
||||
"program": "${workspaceFolder}/main.go"
|
||||
"program": "${workspaceFolder}/main.go",
|
||||
"args": [
|
||||
"-c",
|
||||
"/home/velvettear/worklog/config.yml"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -9,6 +9,7 @@ import (
|
|||
"velvettear/worklog/internal/config"
|
||||
"velvettear/worklog/internal/database"
|
||||
"velvettear/worklog/internal/log"
|
||||
"velvettear/worklog/internal/tools"
|
||||
"velvettear/worklog/internal/workday"
|
||||
)
|
||||
|
||||
|
@ -109,7 +110,7 @@ func handlePost(user string, writer http.ResponseWriter, request *http.Request)
|
|||
if !success {
|
||||
if workday.ID > 0 {
|
||||
writer.WriteHeader(400)
|
||||
writer.Write([]byte("workday for today has already been started at " + strconv.Itoa(workday.Start.Hour()) + ":" + strconv.Itoa(workday.Start.Minute()) + ":" + strconv.Itoa(workday.Start.Second()) + "\n"))
|
||||
writer.Write([]byte("workday for today has already been started at " + tools.TimeToHHMMSS(workday.Start) + "\n"))
|
||||
} else {
|
||||
writer.WriteHeader(500)
|
||||
writer.Write([]byte("encountered an error starting a new workday\n"))
|
||||
|
@ -117,21 +118,21 @@ func handlePost(user string, writer http.ResponseWriter, request *http.Request)
|
|||
break
|
||||
}
|
||||
writer.WriteHeader(200)
|
||||
writer.Write([]byte("started new workday for user '" + workday.User + "' at " + strconv.Itoa(workday.Start.Hour()) + ":" + strconv.Itoa(workday.Start.Minute()) + ":" + strconv.Itoa(workday.Start.Second()) + "\n"))
|
||||
writer.Write([]byte("started new workday for user '" + workday.User + "' at " + tools.TimeToHHMMSS(workday.Start) + "\n"))
|
||||
case "/stop":
|
||||
success, workday := database.StopTimestamp()
|
||||
success, workday := database.StopTimestamp(user)
|
||||
if !success {
|
||||
if workday.ID > 0 {
|
||||
writer.WriteHeader(500)
|
||||
writer.Write([]byte("encountered an error stopping workday for user '" + workday.User + "'\n"))
|
||||
writer.Write([]byte("encountered an error stopping workday for user '" + user + "'\n"))
|
||||
} else {
|
||||
writer.WriteHeader(400)
|
||||
writer.Write([]byte("there is no open workday to stop\n"))
|
||||
writer.Write([]byte("there is no open workday for user '" + user + "' to stop\n"))
|
||||
}
|
||||
break
|
||||
}
|
||||
writer.WriteHeader(200)
|
||||
writer.Write([]byte("stopped workday for user '" + workday.User + "' started at " + strconv.Itoa(workday.Start.Hour()) + ":" + strconv.Itoa(workday.Start.Minute()) + ":" + strconv.Itoa(workday.Start.Second()) + "\n"))
|
||||
writer.Write([]byte("stopped workday for user '" + workday.User + "' started at " + tools.TimeToHHMMSS(workday.Start) + "\n"))
|
||||
default:
|
||||
handled = false
|
||||
}
|
||||
|
|
|
@ -32,15 +32,15 @@ func StartTimestamp(user string) (bool, Timestamp) {
|
|||
return success, workday
|
||||
}
|
||||
|
||||
func StopTimestamp() (bool, Timestamp) {
|
||||
func StopTimestamp(user string) (bool, Timestamp) {
|
||||
var timestamp Timestamp
|
||||
result := connection.Last(×tamp)
|
||||
result := connection.Where("end = ? and user = ?", tools.ZeroDate, user).Last(×tamp)
|
||||
if result.Error != nil {
|
||||
log.Error("encountered an error selecting the last workday", result.Error.Error())
|
||||
log.Error("encountered an error selecting the last workday for user '"+user+"'", result.Error.Error())
|
||||
return false, timestamp
|
||||
}
|
||||
if timestamp.ID == 0 || !timestamp.End.Equal(tools.ZeroDate) {
|
||||
log.Debug("there is no open workday to stop")
|
||||
log.Debug("there is no open workday for user '" + user + "' to stop")
|
||||
timestamp.ID = 0
|
||||
return false, timestamp
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue