46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package sdkserver
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"gac-hkrpg-go/internal/common"
|
|
)
|
|
|
|
func apiAARoundSelection(w http.ResponseWriter, r *http.Request) {
|
|
switch r.Method {
|
|
case http.MethodGet:
|
|
selection, err := common.ReadAARoundSelection()
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
writeJSON(w, map[string]any{"status": 200, "selection": selection})
|
|
case http.MethodPost:
|
|
var request struct {
|
|
Action string `json:"action"`
|
|
PeakGroupID uint32 `json:"peak_group_id"`
|
|
}
|
|
if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
|
|
http.Error(w, "invalid JSON", http.StatusBadRequest)
|
|
return
|
|
}
|
|
if request.Action == "clear" {
|
|
if err := common.ClearAARoundSelection(); err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
writeJSON(w, map[string]any{"status": 200, "selection": nil})
|
|
return
|
|
}
|
|
selection, err := common.SetAARoundSelection(request.PeakGroupID)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
return
|
|
}
|
|
writeJSON(w, map[string]any{"status": 200, "selection": selection})
|
|
default:
|
|
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
|
}
|
|
}
|