Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vinvoor: a start #25

Merged
merged 22 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 1 addition & 95 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
.config
*.o
*.pyc

# gtags
GTAGS
GRTAGS
GPATH

# emacs
.dir-locals.el

Expand All @@ -21,52 +12,6 @@ GPATH
# MacOS directory files
.DS_Store

# cache dir
.cache/

# Doc build artifacts
docs/_build/
docs/doxygen_sqlite3.db

# Downloaded font files
docs/_static/DejaVuSans.ttf
docs/_static/NotoSansSC-Regular.otf

# Components Unit Test Apps files
components/**/build/
components/**/build_*_*/
components/**/sdkconfig
components/**/sdkconfig.old

# Example project files
examples/**/build/
examples/**/build_*_*/
examples/**/sdkconfig
examples/**/sdkconfig.old

# Unit test app files
tools/unit-test-app/build
tools/unit-test-app/build_*_*/
tools/unit-test-app/sdkconfig
tools/unit-test-app/sdkconfig.old

# test application build files
tools/test_apps/**/build/
tools/test_apps/**/build_*_*/
tools/test_apps/**/sdkconfig
tools/test_apps/**/sdkconfig.old

TEST_LOGS/
build_summary_*.xml

# gcov coverage reports
*.gcda
*.gcno
coverage.info
coverage_report/

test_multi_heap_host

# VS Code Settings
.vscode/

Expand All @@ -78,44 +23,5 @@ test_multi_heap_host
*.sublime-project
*.sublime-workspace

# Clion IDE CMake build & config
# IDEA files
.idea/
cmake-build-*/

# Results for the checking of the Python coding style and static analysis
.mypy_cache
flake8_output.txt

# ESP-IDF default build directory name
build

# lock files for examples and components
dependencies.lock

# managed_components for examples
managed_components

# pytest log
pytest_embedded_log/
list_job*.txt
size_info*.txt
XUNIT_RESULT*.xml

# clang config (for LSP)
.clangd

# Vale
.vale/styles/*

# pio
.pio

# sqlite
*.db

.env

# vinscant
key.txt
mfrc522.py
webrepl_cli.py
40 changes: 32 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,41 @@ Scans a badge at the scanner (vinscant) which registers its serial number at the

Features:

- Supports a daily check-in, keeping track of which days you have visited the kelder.
- Supports a daily check-in, keeping track of which days you have visited the kelder.

Goals:

- Support check-in and check-out, keeping track of how many hours(, minutes(, seconds)) you have been in the kelder
- Cool stats :D
- Support check-in and check-out, keeping track of how many hours(, minutes(, seconds)) you have been in the kelder
- Cool stats :D

Secret goals:

- Streaks
- Data
- More Data
- Skins
- Battlepass
- Streaks
- Data
- More Data
- Skins
- Battlepass

## Structure

- `Vinscant` -> Scanner
- `Vingo` -> Backend
- `Vinvoor` -> Frontend

## How to run (for development)

### Easy & Quick

- Install Docker and Docker Compose
- Run the script `./dev.sh` with optional flags:
- `-b`: Show the output of the backend.
- `-f`: Show the output of the frontend.
- `-c`: Rebuilds the docker containers.
- If both `-b` and `-f` or no flags are provided, the output of both the backend and frontend are shown.

The backend is accessible at `localhost:3000`, and the frontend at `localhost:5173`.
Both the backend and the frontend support hot module reloading (HMR).

### Manual

- Each part has it's own `README.md` with instructions on how to run it.
55 changes: 55 additions & 0 deletions dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash

# Current user
export CURRENT_UID=$(id -u):$(id -g)

# Parse input

backend=false
frontend=false
clean=false

while getopts 'bfc' flag; do
case "${flag}" in
b) backend=true ;;
f) frontend=true ;;
c) clean=true ;;
*) echo "Unexpected option ${flag}" ;;
esac
done

# Build the docker containers if clean flag is set

if [ "$clean" = true ]; then
rm vingo/.env || true
rm vinvoor/.env || true
docker-compose -f docker-compose.yml build
fi


# Check for the required files

if [ ! -f vingo/.env ]; then
cp vingo/dev.env vingo/.env
fi
if [ ! -f vinvoor/.env ]; then
cp vinvoor/dev.env vinvoor/.env
fi

# Start the docker containers
docker-compose -f docker-compose.yml up -d

echo "-------------------------------------"
echo "Following logs..."
echo "Press CTRL + C to stop all containers"
echo "-------------------------------------"

if [ "$backend" = true ] && [ "$frontend" = false ]; then
docker-compose -f docker-compose.yml logs -f zess-backend
elif [ "$backend" = false ] && [ "$frontend" = true ]; then
docker-compose -f docker-compose.yml logs -f zess-frontend
else
docker-compose -f docker-compose.yml logs -f zess-backend zess-frontend
fi

docker-compose -f docker-compose.yml down
43 changes: 43 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
services:
zess-db:
image: postgres:alpine3.20
environment:
- POSTGRES_PASSWORD=zess
- POSTGRES_USER=postgres
- POSTGRES_DB=zess
volumes:
- db-data:/var/lib/postgresql/data
ports:
- 5432:5432
extra_hosts:
- "host.docker.internal:host-gateway"

zess-backend:
build:
context: vingo
dockerfile: Dockerfile.dev
ports:
- 4000:4000
volumes:
- ./vingo:/backend
- backend-packages:/go/pkg/mod
extra_hosts:
- "host.docker.internal:host-gateway"
depends_on:
- zess-db

zess-frontend:
build:
context: vinvoor
dockerfile: Dockerfile.dev
user: ${CURRENT_UID}
ports:
- 5173:5173
volumes:
- ./vinvoor:/frontend
extra_hosts:
- "host.docker.internal:host-gateway"

volumes:
backend-packages:
db-data:
51 changes: 51 additions & 0 deletions vingo/.air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"

[build]
args_bin = []
bin = "./tmp/main"
cmd = "go build -o ./tmp/main ."
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
post_cmd = []
pre_cmd = []
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false

[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"

[log]
main_only = false
time = false

[misc]
clean_on_exit = false

[proxy]
app_port = 0
enabled = false
proxy_port = 0

[screen]
clear_on_rebuild = false
keep_scroll = true
2 changes: 2 additions & 0 deletions vingo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
tmp/
10 changes: 10 additions & 0 deletions vingo/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM golang:1.22.1-alpine3.19

WORKDIR /backend

RUN go install github.com/air-verse/air@latest
COPY .air.toml .

COPY go.mod go.sum ./

CMD go mod tidy && air -c .air.toml
2 changes: 2 additions & 0 deletions vingo/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Vingo

The webserver that keeps track of the scans :D

Register a scan by posting `card_serial;scan_key` to the `/scans` endpoint.
Expand All @@ -7,6 +8,7 @@ Register a scan by posting `card_serial;scan_key` to the `/scans` endpoint.
To register a card, click the "Start registering a new card" button in the cards view, after which the server will register the next scanned card for the user that initiated the request. Only 1 user can register a card at a time.

## How to run (for development)

- install go
- install docker
- `docker run --name zess-postgres -e POSTGRES_PASSWORD=zess -d -p 5432:5432 postgres`
Expand Down
4 changes: 2 additions & 2 deletions vingo/database/cards.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package database
import "time"

type Card struct {
Serial string
CreatedAt time.Time
Serial string `json:"serial"`
CreatedAt time.Time `json:"createdAt"`
}

var (
Expand Down
12 changes: 6 additions & 6 deletions vingo/database/scans.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package database
import "time"

type Scan struct {
ScanTime time.Time
Card string
ScanTime time.Time `json:"scanTime"`
Card string `json:"card"`
}

type Present struct {
Expand All @@ -14,9 +14,9 @@ type Present struct {
}

type LeaderboardItem struct {
Position int
Username string
TotalDays int
Position int `json:"position"`
Username string `json:"username"`
TotalDays int `json:"totalDays"`
}

var (
Expand Down Expand Up @@ -57,7 +57,7 @@ func GetPresenceHistory(user_id int) ([]Present, error) {
WITH date_series AS (
SELECT generate_series(CURRENT_DATE AT TIME ZONE 'Europe/Brussels' - INTERVAL '6 days', CURRENT_DATE AT TIME ZONE 'Europe/Brussels', '1 day')::date AS date
)
SELECT
SELECT
ds.date,
CASE WHEN scans.scan_date IS NOT NULL THEN TRUE ELSE FALSE END AS present,
CASE WHEN days.date IS NOT NULL THEN TRUE ELSE FALSE END AS streak_day
Expand Down
6 changes: 3 additions & 3 deletions vingo/database/settings.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package database

type Settings struct {
ScanInOut bool
Leaderboard bool
Public bool
ScanInOut bool `json:"scanInOut"`
Leaderboard bool `json:"leaderboard"`
Public bool `json:"public"`
}

var (
Expand Down
Loading