-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* grade api added * fixes * grades api * priv checks --------- Co-authored-by: cmyui <[email protected]>
- Loading branch information
1 parent
ad82482
commit f7520a3
Showing
4 changed files
with
65 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ main | |
gitold/ | ||
akatsuki-api | ||
akatsuki-api.exe | ||
.env | ||
.env | ||
.vscode/ |
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,59 @@ | ||
package v1 | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
|
||
"github.com/osuAkatsuki/akatsuki-api/common" | ||
) | ||
|
||
type userGrades struct { | ||
XHCount int `json:"xh_count"` | ||
XCount int `json:"x_count"` | ||
SHCount int `json:"sh_count"` | ||
SCount int `json:"s_count"` | ||
ACount int `json:"a_count"` | ||
BCount int `json:"b_count"` | ||
CCount int `json:"c_count"` | ||
DCount int `json:"d_count"` | ||
} | ||
type userGradesResponse struct { | ||
common.ResponseBase | ||
Grades userGrades `json:"grades"` | ||
} | ||
|
||
func UserGradesGET(md common.MethodData) common.CodeMessager { | ||
var response userGradesResponse | ||
mode := common.Int(md.Query("mode")) | ||
userID := common.Int(md.Query("id")) | ||
query := fmt.Sprintf(` | ||
SELECT | ||
xh_count, x_count, sh_count, s_count, | ||
a_count, b_count, c_count, d_count | ||
FROM user_stats | ||
INNER JOIN users ON users.id = user_stats.user_id | ||
WHERE user_id = ? AND user_stats.mode = ? AND %s`, | ||
md.User.OnlyUserPublic(true), | ||
) | ||
|
||
err := md.DB.QueryRow(query, userID, mode).Scan( | ||
&response.Grades.XHCount, | ||
&response.Grades.XCount, | ||
&response.Grades.SHCount, | ||
&response.Grades.SCount, | ||
&response.Grades.ACount, | ||
&response.Grades.BCount, | ||
&response.Grades.CCount, | ||
&response.Grades.DCount, | ||
) | ||
|
||
if err != nil { | ||
if err == sql.ErrNoRows { | ||
return common.SimpleResponse(404, "User stats not found") | ||
} | ||
md.Err(err) | ||
return Err500 | ||
} | ||
response.Code = 200 | ||
return response | ||
} |