From 174b962f193af0fb3ef09c5222687bc4dc1df61e Mon Sep 17 00:00:00 2001 From: Up Date: Wed, 15 May 2024 00:00:38 +0200 Subject: [PATCH] update verify endpoint --- api/common.go | 2 +- api/endpoints.go | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/api/common.go b/api/common.go index ec87644..bdd5aab 100644 --- a/api/common.go +++ b/api/common.go @@ -56,7 +56,7 @@ func Init(mux *http.ServeMux) error { // new session 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/session", handleGetSessionData) diff --git a/api/endpoints.go b/api/endpoints.go index 62a958d..205e012 100644 --- a/api/endpoints.go +++ b/api/endpoints.go @@ -627,7 +627,7 @@ func handleUpdateAll(w http.ResponseWriter, r *http.Request) { return } } 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) return } @@ -646,24 +646,23 @@ func handleUpdateAll(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) } -type SessionVerifyResponse struct { - Valid bool `json:"valid"` - SessionData *defs.SessionSaveData `json:"sessionData"` +type SystemVerifyResponse struct { + Valid bool `json:"valid"` + SystemData *defs.SystemSaveData `json:"systemData"` } -type SessionVerifyRequest struct { +type SystemVerifyRequest struct { 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) if err != nil { httpError(w, r, err, http.StatusBadRequest) return } - var input SessionVerifyRequest + var input SystemVerifyRequest err = json.NewDecoder(r.Body).Decode(&input) if err != nil { 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 } - response := SessionVerifyResponse{ + response := SystemVerifyResponse{ Valid: active, } @@ -689,14 +688,14 @@ func handleSessionVerify(w http.ResponseWriter, r *http.Request) { return } - var storedSaveData defs.SessionSaveData - storedSaveData, err = db.ReadSessionSaveData(uuid, input.Slot) + var storedSaveData defs.SystemSaveData + storedSaveData, err = db.ReadSystemSaveData(uuid) if err != nil { httpError(w, r, fmt.Errorf("failed to read session save data: %s", err), http.StatusInternalServerError) return } - response.SessionData = &storedSaveData + response.SystemData = &storedSaveData } jsonResponse(w, r, response) @@ -733,6 +732,7 @@ func handleGetSystemData(w http.ResponseWriter, r *http.Request) { return } + //TODO apply vouchers jsonResponse(w, r, save) }