Add changes so far
This commit is contained in:
6 files changed
+207
No files matched your search
@@ -0,0 +1,69 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/Flashfyre/pokerogue-server/db"
|
||||
)
|
||||
|
||||
// /api/account/info - get account info
|
||||
|
||||
type AccountInfoResponse struct{
|
||||
Username string `json:"string"`
|
||||
}
|
||||
|
||||
func HandleAccountInfo(w http.ResponseWriter, r *http.Request) {
|
||||
token, err := base64.StdEncoding.DecodeString(r.Header.Get("Authorization"))
|
||||
if err != nil {
|
||||
http.Error(w, fmt.Sprintf("failed to decode token: %s", err), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
username, err := db.GetAccountInfoFromToken(token)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
response, err := json.Marshal(AccountInfoResponse{Username: username})
|
||||
if err != nil {
|
||||
http.Error(w, fmt.Sprintf("failed to marshal response json: %s", err), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(response)
|
||||
}
|
||||
|
||||
// /api/account/register - register account
|
||||
|
||||
type AccountRegisterRequest GenericAuthRequest
|
||||
type AccountRegisterResponse GenericAuthResponse
|
||||
|
||||
func HandleAccountRegister(w http.ResponseWriter, r *http.Request) {
|
||||
var request AccountRegisterRequest
|
||||
err := json.NewDecoder(r.Body).Decode(&request)
|
||||
if err != nil {
|
||||
http.Error(w, fmt.Sprintf("failed to decode request body: %s", err), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// /api/account/login - log into account
|
||||
|
||||
type AccountLoginRequest GenericAuthRequest
|
||||
type AccountLoginResponse GenericAuthResponse
|
||||
|
||||
func HandleAccountLogin(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
}
|
||||
|
||||
// /api/account/logout - log out of account
|
||||
|
||||
func HandleAccountLogout(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package api
|
||||
|
||||
// error
|
||||
|
||||
type ErrorResponse struct{
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// auth
|
||||
|
||||
type GenericAuthRequest struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type GenericAuthResponse struct {
|
||||
Token string `json:"token"`
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package api
|
||||
|
||||
import "net/http"
|
||||
|
||||
// /api/savedata/get - get save data
|
||||
|
||||
type SavedataGetRequest struct{}
|
||||
type SavedataGetResponse struct{}
|
||||
|
||||
func HandleSavedataGet(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
}
|
||||
|
||||
// /api/savedata/update - update save data
|
||||
|
||||
type SavedataUpdateRequest struct{}
|
||||
type SavedataUpdateResponse struct{}
|
||||
|
||||
func HandleSavedataUpdate(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
}
|
||||
|
||||
// /api/savedata/delete - delete save date
|
||||
|
||||
type SavedataDeleteRequest struct{}
|
||||
type SavedataDeleteResponse struct{}
|
||||
|
||||
func HandleSavedataDelete(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user