update verify endpoint

master
Up 2024-05-15 00:00:38 +02:00
parent e2efcd550c
commit 174b962f19
No known key found for this signature in database
GPG Key ID: 3B75CD7439FEB388
2 changed files with 13 additions and 13 deletions

View File

@ -56,7 +56,7 @@ func Init(mux *http.ServeMux) error {
// new session // new session
mux.HandleFunc("POST /savedata/updateall", handleUpdateAll) mux.HandleFunc("POST /savedata/updateall", handleUpdateAll)
mux.HandleFunc("POST /savedata/verify", handleSessionVerify) mux.HandleFunc("POST /savedata/system/verify", handleSystemVerify)
mux.HandleFunc("GET /savedata/system", handleGetSystemData) mux.HandleFunc("GET /savedata/system", handleGetSystemData)
mux.HandleFunc("GET /savedata/session", handleGetSessionData) mux.HandleFunc("GET /savedata/session", handleGetSessionData)

View File

@ -627,7 +627,7 @@ func handleUpdateAll(w http.ResponseWriter, r *http.Request) {
return return
} }
} else { } else {
if err := db.UpdateTrainerIds(trainerId, secretId, uuid); err != nil { if err = db.UpdateTrainerIds(trainerId, secretId, uuid); err != nil {
httpError(w, r, err, http.StatusInternalServerError) httpError(w, r, err, http.StatusInternalServerError)
return return
} }
@ -646,24 +646,23 @@ func handleUpdateAll(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
} }
type SessionVerifyResponse struct { type SystemVerifyResponse struct {
Valid bool `json:"valid"` Valid bool `json:"valid"`
SessionData *defs.SessionSaveData `json:"sessionData"` SystemData *defs.SystemSaveData `json:"systemData"`
} }
type SessionVerifyRequest struct { type SystemVerifyRequest struct {
ClientSessionId string `json:"clientSessionId"` ClientSessionId string `json:"clientSessionId"`
Slot int `json:"slot"`
} }
func handleSessionVerify(w http.ResponseWriter, r *http.Request) { func handleSystemVerify(w http.ResponseWriter, r *http.Request) {
uuid, err := uuidFromRequest(r) uuid, err := uuidFromRequest(r)
if err != nil { if err != nil {
httpError(w, r, err, http.StatusBadRequest) httpError(w, r, err, http.StatusBadRequest)
return return
} }
var input SessionVerifyRequest var input SystemVerifyRequest
err = json.NewDecoder(r.Body).Decode(&input) err = json.NewDecoder(r.Body).Decode(&input)
if err != nil { if err != nil {
httpError(w, r, fmt.Errorf("failed to decode request body: %s", err), http.StatusBadRequest) httpError(w, r, fmt.Errorf("failed to decode request body: %s", err), http.StatusBadRequest)
@ -677,7 +676,7 @@ func handleSessionVerify(w http.ResponseWriter, r *http.Request) {
return return
} }
response := SessionVerifyResponse{ response := SystemVerifyResponse{
Valid: active, Valid: active,
} }
@ -689,14 +688,14 @@ func handleSessionVerify(w http.ResponseWriter, r *http.Request) {
return return
} }
var storedSaveData defs.SessionSaveData var storedSaveData defs.SystemSaveData
storedSaveData, err = db.ReadSessionSaveData(uuid, input.Slot) storedSaveData, err = db.ReadSystemSaveData(uuid)
if err != nil { if err != nil {
httpError(w, r, fmt.Errorf("failed to read session save data: %s", err), http.StatusInternalServerError) httpError(w, r, fmt.Errorf("failed to read session save data: %s", err), http.StatusInternalServerError)
return return
} }
response.SessionData = &storedSaveData response.SystemData = &storedSaveData
} }
jsonResponse(w, r, response) jsonResponse(w, r, response)
@ -733,6 +732,7 @@ func handleGetSystemData(w http.ResponseWriter, r *http.Request) {
return return
} }
//TODO apply vouchers
jsonResponse(w, r, save) jsonResponse(w, r, save)
} }