Initial commit
This commit is contained in:
commit
b6014c6ffc
47 files changed
+4329
No files matched your search
@@ -0,0 +1,70 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"vlog/internal/auth"
|
||||
"vlog/internal/handlers"
|
||||
)
|
||||
|
||||
// registerRoutes wires up the whole JSON API. Auth login/callback/logout
|
||||
// and the /api/public/... share endpoints are public; everything else
|
||||
// requires the session cookie.
|
||||
func registerRoutes(mux *http.ServeMux, h *handlers.Handlers) {
|
||||
mux.HandleFunc("GET /api/auth/login", h.Login)
|
||||
mux.HandleFunc("GET /api/auth/callback", h.Callback)
|
||||
mux.HandleFunc("POST /api/auth/logout", h.Logout)
|
||||
|
||||
// Public, unauthenticated share view (QR code / link, no login) — a
|
||||
// deliberately narrow read-only surface, see internal/handlers/public.go.
|
||||
mux.HandleFunc("GET /api/public/cars/{shareToken}", h.PublicCar)
|
||||
mux.HandleFunc("GET /api/public/cars/{shareToken}/photo", h.PublicCarPhoto)
|
||||
mux.HandleFunc("GET /api/public/cars/{shareToken}/service-entries", h.PublicServiceEntries)
|
||||
mux.HandleFunc("GET /api/public/cars/{shareToken}/files/{fileId}", h.PublicFile)
|
||||
|
||||
protected := http.NewServeMux()
|
||||
protected.HandleFunc("GET /api/me", h.Me)
|
||||
|
||||
protected.HandleFunc("GET /api/cars", h.ListCars)
|
||||
protected.HandleFunc("POST /api/cars", h.CreateCar)
|
||||
protected.HandleFunc("GET /api/cars/{carId}", h.GetCar)
|
||||
protected.HandleFunc("PUT /api/cars/{carId}", h.UpdateCar)
|
||||
protected.HandleFunc("DELETE /api/cars/{carId}", h.DeleteCar)
|
||||
protected.HandleFunc("POST /api/cars/{carId}/photo", h.UploadCarPhoto)
|
||||
protected.HandleFunc("GET /api/cars/{carId}/photo", h.GetCarPhoto)
|
||||
protected.HandleFunc("PATCH /api/cars/{carId}/odometer", h.UpdateOdometer)
|
||||
protected.HandleFunc("POST /api/cars/{carId}/share", h.GenerateShareLink)
|
||||
protected.HandleFunc("DELETE /api/cars/{carId}/share", h.RevokeShareLink)
|
||||
protected.HandleFunc("GET /api/cars/{carId}/mileage", h.Mileage)
|
||||
|
||||
protected.HandleFunc("GET /api/cars/{carId}/service-entries", h.ListServiceEntries)
|
||||
protected.HandleFunc("POST /api/cars/{carId}/service-entries", h.CreateServiceEntry)
|
||||
protected.HandleFunc("GET /api/service-entries/{entryId}", h.GetServiceEntry)
|
||||
protected.HandleFunc("PUT /api/service-entries/{entryId}", h.UpdateServiceEntry)
|
||||
protected.HandleFunc("DELETE /api/service-entries/{entryId}", h.DeleteServiceEntry)
|
||||
protected.HandleFunc("POST /api/service-entries/{entryId}/files", h.UploadServiceEntryFile)
|
||||
protected.HandleFunc("GET /api/files/{fileId}", h.GetFile)
|
||||
protected.HandleFunc("DELETE /api/files/{fileId}", h.DeleteFile)
|
||||
|
||||
protected.HandleFunc("GET /api/cars/{carId}/reminders", h.ListReminders)
|
||||
protected.HandleFunc("POST /api/cars/{carId}/reminders", h.CreateReminder)
|
||||
protected.HandleFunc("PUT /api/reminders/{reminderId}", h.UpdateReminder)
|
||||
protected.HandleFunc("DELETE /api/reminders/{reminderId}", h.DeleteReminder)
|
||||
|
||||
protected.HandleFunc("GET /api/cars/{carId}/knowledge", h.ListKnowledge)
|
||||
protected.HandleFunc("POST /api/cars/{carId}/knowledge", h.CreateKnowledge)
|
||||
protected.HandleFunc("PUT /api/knowledge/{knowledgeId}", h.UpdateKnowledge)
|
||||
protected.HandleFunc("DELETE /api/knowledge/{knowledgeId}", h.DeleteKnowledge)
|
||||
|
||||
protected.HandleFunc("GET /api/cars/{carId}/fuel-entries", h.ListFuelEntries)
|
||||
protected.HandleFunc("POST /api/cars/{carId}/fuel-entries", h.CreateFuelEntry)
|
||||
protected.HandleFunc("PUT /api/fuel-entries/{entryId}", h.UpdateFuelEntry)
|
||||
protected.HandleFunc("DELETE /api/fuel-entries/{entryId}", h.DeleteFuelEntry)
|
||||
|
||||
protected.HandleFunc("GET /api/dashboard", h.Dashboard)
|
||||
|
||||
// Mounted as a subtree on the outer mux; Go's ServeMux does not strip
|
||||
// the prefix, so the protected mux's patterns include the full "/api/..."
|
||||
// path and match the original request untouched.
|
||||
mux.Handle("/api/", auth.RequireAuth(h.JWTSecret)(protected))
|
||||
}
|
||||
Reference in new issue
Block a user