aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/http.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/http.go')
-rw-r--r--src/http.go48
1 files changed, 37 insertions, 11 deletions
diff --git a/src/http.go b/src/http.go
index ac6f6da..fce82ba 100644
--- a/src/http.go
+++ b/src/http.go
@@ -38,6 +38,7 @@ func Run(port int) {
mux.Handle("GET /storage/", fs)
if Debugp {
mux.Handle("GET /style.css", fs)
+ mux.Handle("GET /style-2.css", fs)
} else {
mux.Handle("GET /style.min.css", fs)
}
@@ -137,12 +138,6 @@ func countryHandler(next http.Handler) http.Handler {
func mintageHandler(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
td := r.Context().Value("td").(*templateData)
- td.Code = r.FormValue("code")
- if !slices.ContainsFunc(td.Countries, func(c country) bool {
- return c.Code == td.Code
- }) {
- td.Code = td.Countries[0].Code
- }
td.Type = r.FormValue("type")
switch td.Type {
@@ -151,11 +146,42 @@ func mintageHandler(next http.Handler) http.Handler {
td.Type = "circ"
}
- var err error
- td.Mintages, err = dbx.GetMintages(td.Code, dbx.NewMintageType(td.Type))
- if err != nil {
- throwError(http.StatusInternalServerError, err, w, r)
- return
+ td.FilterBy = r.FormValue("filter-by")
+ switch td.FilterBy {
+ case "country", "year":
+ default:
+ td.FilterBy = "country"
+ }
+
+ mt := dbx.NewMintageType(td.Type)
+
+ switch td.FilterBy {
+ case "country":
+ td.Code = r.FormValue("country")
+ if !slices.ContainsFunc(td.Countries, func(c country) bool {
+ return c.Code == td.Code
+ }) {
+ td.Code = td.Countries[0].Code
+ }
+
+ m, err := dbx.GetMintagesByCountry(td.Code, mt)
+ if err != nil {
+ throwError(http.StatusInternalServerError, err, w, r)
+ return
+ }
+ td.CountryMintages = makeCountryMintageTable(m, td.Printer)
+ case "year":
+ var err error
+ td.Year, err = strconv.Atoi(r.FormValue("year"))
+ if err != nil || td.Year < 1999 {
+ td.Year = 1999
+ }
+ m, err := dbx.GetMintagesByYear(td.Year, mt)
+ if err != nil {
+ throwError(http.StatusInternalServerError, err, w, r)
+ return
+ }
+ td.YearMintages = makeYearMintageTable(m, td.Printer)
}
next.ServeHTTP(w, r)