make bug report database name configurable

Replace the hardcoded "emly_bugreports_dev" database name in SQL queries with the database name from the application configuration.
This commit is contained in:
Flavio Fois
2026-03-26 20:28:51 +01:00
parent 09a760e025
commit e6d663f4f2
5 changed files with 50 additions and 50 deletions

View File

@@ -11,15 +11,15 @@ import (
"github.com/jmoiron/sqlx"
)
func registerBugReports(r chi.Router, db *sqlx.DB) {
func registerBugReports(r chi.Router, db *sqlx.DB, dbName string) {
r.Route("/bug-reports", func(r chi.Router) {
// API key only: submit a report and check count
r.Group(func(r chi.Router) {
r.Use(apimw.APIKeyAuth(db))
r.Use(httprate.LimitByIP(30, time.Minute))
r.Get("/count", handlers.GetReportsCount(db))
r.Post("/", handlers.CreateBugReport(db))
r.Get("/count", handlers.GetReportsCount(db, dbName))
r.Post("/", handlers.CreateBugReport(db, dbName))
})
// API key + admin key: full read/write access
@@ -28,14 +28,14 @@ func registerBugReports(r chi.Router, db *sqlx.DB) {
r.Use(apimw.AdminKeyAuth(db))
r.Use(httprate.LimitByIP(30, time.Minute))
r.Get("/", handlers.GetAllBugReports(db))
r.Get("/{id}", handlers.GetBugReportByID(db))
r.Get("/{id}/status", handlers.GetReportStatusByID(db))
r.Get("/{id}/files", handlers.GetReportFilesByReportID(db))
r.Get("/{id}/files/{file_id}", handlers.GetReportFileByFileID(db))
r.Get("/{id}/download", handlers.GetBugReportZipById(db))
r.Patch("/{id}/status", handlers.PatchBugReportStatus(db))
r.Delete("/{id}", handlers.DeleteBugReportByID(db))
r.Get("/", handlers.GetAllBugReports(db, dbName))
r.Get("/{id}", handlers.GetBugReportByID(db, dbName))
r.Get("/{id}/status", handlers.GetReportStatusByID(db, dbName))
r.Get("/{id}/files", handlers.GetReportFilesByReportID(db, dbName))
r.Get("/{id}/files/{file_id}", handlers.GetReportFileByFileID(db, dbName))
r.Get("/{id}/download", handlers.GetBugReportZipById(db, dbName))
r.Patch("/{id}/status", handlers.PatchBugReportStatus(db, dbName))
r.Delete("/{id}", handlers.DeleteBugReportByID(db, dbName))
})
})
}

View File

@@ -33,7 +33,7 @@ func NewRouter(db *sqlx.DB) http.Handler {
r.Route("/api", func(r chi.Router) {
registerAdmin(r, db)
registerBugReports(r, db)
registerBugReports(r, db, config.Load().Database)
})
return r

View File

@@ -11,15 +11,15 @@ import (
"github.com/jmoiron/sqlx"
)
func registerBugReports(r chi.Router, db *sqlx.DB) {
func registerBugReports(r chi.Router, db *sqlx.DB, dbName string) {
r.Route("/bug-report", func(r chi.Router) {
// API key only: submit a report and check count
r.Group(func(r chi.Router) {
r.Use(apimw.APIKeyAuth(db))
r.Use(httprate.LimitByIP(30, time.Minute))
r.Get("/count", handlers.GetReportsCount(db))
r.Post("/", handlers.CreateBugReport(db))
r.Get("/count", handlers.GetReportsCount(db, dbName))
r.Post("/", handlers.CreateBugReport(db, dbName))
})
// API key + admin key: full read/write access
@@ -28,14 +28,14 @@ func registerBugReports(r chi.Router, db *sqlx.DB) {
r.Use(apimw.AdminKeyAuth(db))
r.Use(httprate.LimitByIP(30, time.Minute))
r.Get("/", handlers.GetAllBugReports(db))
r.Get("/{id}", handlers.GetBugReportByID(db))
r.Get("/{id}/status", handlers.GetReportStatusByID(db))
r.Get("/{id}/files", handlers.GetReportFilesByReportID(db))
r.Get("/{id}/files/{file_id}", handlers.GetReportFileByFileID(db))
r.Get("/{id}/download", handlers.GetBugReportZipById(db))
r.Patch("/{id}/status", handlers.PatchBugReportStatus(db))
r.Delete("/{id}", handlers.DeleteBugReportByID(db))
r.Get("/", handlers.GetAllBugReports(db, dbName))
r.Get("/{id}", handlers.GetBugReportByID(db, dbName))
r.Get("/{id}/status", handlers.GetReportStatusByID(db, dbName))
r.Get("/{id}/files", handlers.GetReportFilesByReportID(db, dbName))
r.Get("/{id}/files/{file_id}", handlers.GetReportFileByFileID(db, dbName))
r.Get("/{id}/download", handlers.GetBugReportZipById(db, dbName))
r.Patch("/{id}/status", handlers.PatchBugReportStatus(db, dbName))
r.Delete("/{id}", handlers.DeleteBugReportByID(db, dbName))
})
})
}

View File

@@ -33,7 +33,7 @@ func NewRouter(db *sqlx.DB) http.Handler {
r.Route("/api", func(r chi.Router) {
registerAdmin(r, db)
registerBugReports(r, db)
registerBugReports(r, db, config.Load().Database)
})
return r