This repository has been archived by the owner on Oct 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
167 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package controller | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
|
||
"github.com/gorilla/mux" | ||
"github.com/robyzzz/csl-backend/config" | ||
"github.com/robyzzz/csl-backend/model" | ||
"github.com/robyzzz/csl-backend/utils" | ||
) | ||
|
||
// GET /api/users/ - returns all users data | ||
func UserIndex(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Type", "application/json") | ||
|
||
users, err := model.UserIndex() | ||
if err != nil { | ||
utils.APIErrorRespond(w, utils.NewAPIError(http.StatusNotFound, err.Error())) | ||
return | ||
} | ||
|
||
json.NewEncoder(w).Encode(users) | ||
} | ||
|
||
// GET /api/user/{steamid} - returns player's data by steamid | ||
func GetUser(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Type", "application/json") | ||
|
||
user, err := model.GetUser(mux.Vars(r)["steamid"]) | ||
if err != nil { | ||
utils.APIErrorRespond(w, utils.NewAPIError(http.StatusNotFound, err.Error())) | ||
return | ||
} | ||
|
||
json.NewEncoder(w).Encode(user) | ||
} | ||
|
||
// GET /profile - returns user stats if authenticated | ||
func Profile(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Type", "application/json") | ||
|
||
user, err := model.GetUser(config.GetSessionID(r)) | ||
if err != nil { | ||
utils.APIErrorRespond(w, utils.NewAPIError(http.StatusNotFound, err.Error())) | ||
return | ||
} | ||
|
||
json.NewEncoder(w).Encode(user) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package model | ||
|
||
// User represents all data(player_stats + steam_user) | ||
// TODO: | ||
type User struct { | ||
ID uint64 `json:"id"` | ||
SteamID string `json:"steamid"` | ||
Kills int `json:"kills"` | ||
Deaths int `json:"deaths"` | ||
Assists int `json:"assists"` | ||
Shots int `json:"shots"` | ||
Hits int `json:"hits"` | ||
Damage int `json:"damage"` | ||
First_Blood int `json:"first_blood"` | ||
Aces int `json:"aces"` | ||
Headshots int `json:"headshots"` | ||
No_Scope int `json:"no_scope"` | ||
Count int `json:"count"` | ||
Playtime int `json:"playtime"` | ||
Match_Win int `json:"match_win"` | ||
Match_Lose int `json:"match_lose"` | ||
Match_Draw int `json:"match_draw"` | ||
Rounds_Won int `json:"rounds_won"` | ||
Rounds_Lost int `json:"rounds_lost"` | ||
Mvp int `json:"mvp"` | ||
} | ||
|
||
// Returns all players stats from db | ||
func UserIndex() ([]User, error) { | ||
// TODO: get player_stats joined with steam_user stuff | ||
return []User{}, nil | ||
} | ||
|
||
// Returns player's data from db by steamid | ||
func GetUser(steamid string) (User, error) { | ||
// TODO: get player_stats joined with steam_user stuff | ||
return User{}, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.