FloorVisualizer/internal/handler/auth_handler.go
dindang 94895cbc22 Initial commit: FloorVisualizer backend
- Go API server with PostgreSQL + Redis
- AI floor replacement (OpenRouter Gemini)
- Product database (10 brands, 3539 products)
- Recommendation engine, calculator, articles
- Redis async queue + worker pool
- Hot product caching, brand view tracking
- JWT auth, favorites, projects
- Docker deployment ready

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-16 09:47:11 +08:00

50 lines
1.2 KiB
Go

package handler
import (
"database/sql"
"encoding/json"
"net/http"
"floorvisualizer/internal/service"
)
func handleRegister(authSvc *service.AuthService, db *sql.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
writeErr(w, 405, "Method not allowed")
return
}
var input service.RegisterInput
if err := json.NewDecoder(r.Body).Decode(&input); err != nil {
writeJSON(w, 400, map[string]string{"error": "invalid request body"})
return
}
resp, err := authSvc.Register(db, input)
if err != nil {
writeJSON(w, 400, map[string]string{"error": err.Error()})
return
}
writeJSON(w, 201, resp)
}
}
func handleLogin(authSvc *service.AuthService, db *sql.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
writeErr(w, 405, "Method not allowed")
return
}
var input service.LoginInput
if err := json.NewDecoder(r.Body).Decode(&input); err != nil {
writeJSON(w, 400, map[string]string{"error": "invalid request body"})
return
}
resp, err := authSvc.Login(db, input)
if err != nil {
writeJSON(w, 401, map[string]string{"error": err.Error()})
return
}
writeJSON(w, 200, resp)
}
}