feat: initial commit — backend API + student cabinet frontend

- Go backend: auth (JWT), points earn/spend, QR token generation,
  partners, admin grant/stats endpoints with chi router
- Next.js 14 frontend: login, student dashboard, transaction history,
  QR display, partners list
- PostgreSQL migrations (4 tables), Redis cache, Docker Compose
- CORS middleware, role-based route protection, Zustand auth store

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
emil
2026-05-01 10:03:27 +03:00
co-authored by Claude Sonnet 4.6
commit 50b3c4198a
80 changed files with 10579 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
// Package cache provides Redis client initialization.
package cache
import (
"context"
"fmt"
"github.com/redis/go-redis/v9"
)
// NewClient creates and validates a Redis client using the given REDIS_URL.
// Returns an error if the URL cannot be parsed or if the initial PING fails.
func NewClient(ctx context.Context, redisURL string) (*redis.Client, error) {
opts, err := redis.ParseURL(redisURL)
if err != nil {
return nil, fmt.Errorf("cache.NewClient: parse URL: %w", err)
}
client := redis.NewClient(opts)
if err := client.Ping(ctx).Err(); err != nil {
return nil, fmt.Errorf("cache.NewClient: ping: %w", err)
}
return client, nil
}
+22
View File
@@ -0,0 +1,22 @@
// Package db provides PostgreSQL connection pool initialization.
package db
import (
"context"
"fmt"
"github.com/jackc/pgx/v5/pgxpool"
)
// NewPool creates and validates a pgx connection pool using the given DATABASE_URL.
// Returns an error if the pool cannot be created or if the initial ping fails.
func NewPool(ctx context.Context, databaseURL string) (*pgxpool.Pool, error) {
pool, err := pgxpool.New(ctx, databaseURL)
if err != nil {
return nil, fmt.Errorf("db.NewPool: create pool: %w", err)
}
if err := pool.Ping(ctx); err != nil {
return nil, fmt.Errorf("db.NewPool: ping: %w", err)
}
return pool, nil
}
+32
View File
@@ -0,0 +1,32 @@
// Package response provides helpers for writing consistent JSON API responses.
// Every handler must use these helpers — never call json.Encode directly.
package response
import (
"encoding/json"
"net/http"
)
type successBody struct {
Data interface{} `json:"data"`
}
type errorBody struct {
Error string `json:"error"`
}
// JSON writes a successful JSON response with the given HTTP status code and data payload.
// The payload is wrapped in {"data": ...} to match the API envelope convention.
func JSON(w http.ResponseWriter, status int, data interface{}) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
json.NewEncoder(w).Encode(successBody{Data: data}) //nolint:errcheck
}
// Error writes a JSON error response with the given HTTP status code and human-readable message.
// The message is wrapped in {"error": ...}.
func Error(w http.ResponseWriter, status int, message string) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
json.NewEncoder(w).Encode(errorBody{Error: message}) //nolint:errcheck
}