aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/api_stations.go
blob: 411ed96cec2f4a0cb67785e677a18e5bde0e183c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package admin

import (
	"net/http"
)

func (s *AdminServer) handleStations(w http.ResponseWriter, r *http.Request) {
	if r.Method != http.MethodGet {
		http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
		return
	}

	items, err := s.itemStore.LoadAll()
	if err != nil {
		http.Error(w, "failed to load items", http.StatusInternalServerError)
		return
	}

	seen := map[string]bool{}
	var stations []string
	for _, def := range items {
		if def.Craft != nil {
			for _, c := range def.Craft {
				for _, s := range c.Station {
					if s != "" {
						if !seen[s] {
							seen[s] = true
							stations = append(stations, s)
						}
					}
				}
			}
		}
	}

	writeJSON(w, stations)
}