Skip to content

Commit

Permalink
Modified Next Dose Time Query
Browse files Browse the repository at this point in the history
  • Loading branch information
FFCoder committed Aug 26, 2024
1 parent fea98c9 commit 47b6e13
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3,083 deletions.
12 changes: 6 additions & 6 deletions build_prod.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash

# Set some variables
APP_NAME="kratom_tracker"
VITE_API_URL="/api"
CGO_ENABLED=1 # Required for sqlite3
export APP_NAME="kratom_tracker"
export VITE_API_URL="/api"
export CGO_ENABLED=1 # Required for sqlite3

# Make the output
mkdir -p output
Expand All @@ -12,11 +12,11 @@ mkdir -p output
rm -rf output/*

# Build the frontend
cd frontend
cd frontend || exit 1

# Remove package-lock.json
rm -f package-lock.json
npm install --legacy-peer-deps
#npm install --legacy-peer-deps
npm run build:prod

# Build the backend
Expand All @@ -25,4 +25,4 @@ cd ..
# Build for Linux
echo "Building Binary"
go mod tidy
CGO_ENABLED=1 go build -o output/$APP_NAME
go build -o output/$APP_NAME
13 changes: 12 additions & 1 deletion doses/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package doses

import (
"database/sql"
"errors"
"fmt"
"kratomTracker/notificationmanager"
"time"
Expand Down Expand Up @@ -140,7 +141,17 @@ func (repo *SqliteDoseRepository) GetNextDoseTime() (time.Time, error) {
// Get the time 2 hours after the last dose
var lastDoseTime time.Time
var lastDoseTimeStr string
err := repo.Db.QueryRow("SELECT date_taken FROM doses ORDER BY date_taken DESC LIMIT 1").Scan(&lastDoseTimeStr)
queryStr := `
SELECT MAX(date_taken) AS most_recent_date
FROM doses
WHERE DATE(date_taken) = DATE('now', 'localtime')
ORDER BY date_taken DESC
LIMIT 1`
err := repo.Db.QueryRow(queryStr).Scan(&lastDoseTimeStr)
// If there are no doses today, return the current time
if errors.Is(err, sql.ErrNoRows) || lastDoseTimeStr == "" {
return time.Now(), nil
}
if err != nil {
return time.Now(), err
}
Expand Down
Loading

0 comments on commit 47b6e13

Please sign in to comment.