Skip to content

Commit

Permalink
Merge pull request RealistikOsu#6 from RealistikOsu/REAL-15-update-ap…
Browse files Browse the repository at this point in the history
…i-queries

Update api queries due to `country` row changes
  • Loading branch information
lenforiee authored Jun 20, 2022
2 parents b3e38dc + ab54848 commit 11ddf56
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 78 deletions.
7 changes: 4 additions & 3 deletions app/hmrapi/friends_sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package hmrapi
import (
"database/sql"
"strconv"

"github.com/RealistikOsu/RealistikAPI/common"
)

Expand Down Expand Up @@ -63,7 +64,7 @@ SELECT
users.id, users.username, users.register_datetime, users.privileges, users.latest_activity,
users_stats.username_aka,
users_stats.country
users.country
FROM users_relationships
LEFT JOIN users
ON users_relationships.user1 = users.id
Expand Down Expand Up @@ -120,7 +121,7 @@ SELECT
users.id, users.username, users.register_datetime, users.privileges, users.latest_activity,
users_stats.username_aka,
users_stats.country
users.country
FROM users_relationships
LEFT JOIN users
ON users_relationships.user1 = users.id
Expand All @@ -138,7 +139,7 @@ WHERE users_relationships.user2=? AND NOT EXISTS (SELECT * FROM users_relationsh
var count int = 0
defer results.Close()
for results.Next() {
count+=1
count += 1
}

if err := results.Err(); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions app/hmrapi/topdonors.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type topDonorsResponse struct {
const lbUserQuery = `
SELECT
users.id, users.username, users_stats.username_aka, users.register_datetime, users.privileges, users.latest_activity,
users_stats.country, users.donor_expire
users.country, users.donor_expire
FROM users
INNER JOIN users_stats ON users_stats.id = users.id
WHERE users.privileges >= 4 AND users.privileges != 1048576
Expand Down Expand Up @@ -65,7 +65,7 @@ func TopDonorsGET(md common.MethodData) common.CodeMessager {
}
}

if len(tempUsers)>8 {
if len(tempUsers) > 8 {
sortedUsers := make([]userData, 8)
copy(sortedUsers, tempUsers)
resp.Users = sortedUsers
Expand Down
2 changes: 1 addition & 1 deletion app/mitsuha/followers.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const MyFriendsQuery = `
users.id, users.username, users.register_datetime,
users.privileges, users.latest_activity,
users_stats.username_aka,
users_stats.country
users.country
FROM
users_relationships
LEFT JOIN
Expand Down
4 changes: 2 additions & 2 deletions app/peppy/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (

"strings"

"github.com/RealistikOsu/RealistikAPI/common"
"github.com/jmoiron/sqlx"
"github.com/thehowl/go-osuapi"
"github.com/valyala/fasthttp"
"gopkg.in/redis.v5"
"zxq.co/ripple/ocl"
"github.com/RealistikOsu/RealistikAPI/common"
)

// R is a redis client.
Expand All @@ -36,7 +36,7 @@ func GetUser(c *fasthttp.RequestCtx, db *sqlx.DB) {
users.id, users.username,
users_stats.playcount_%s, users_stats.ranked_score_%s, users_stats.total_score_%s,
users_stats.pp_%s, users_stats.avg_accuracy_%s,
users_stats.country
users.country
FROM users
LEFT JOIN users_stats ON users_stats.id = users.id
%s
Expand Down
2 changes: 1 addition & 1 deletion app/v1/badge.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func BadgeMembersGET(md common.MethodData) common.CodeMessager {

err := md.DB.Select(&members.Members, `SELECT users.id, users.username, register_datetime, users.privileges,
latest_activity, users_stats.username_aka,
users_stats.country
users.country
FROM user_badges ub
INNER JOIN users ON users.id = ub.user
INNER JOIN users_stats ON users_stats.id = ub.user
Expand Down
10 changes: 5 additions & 5 deletions app/v1/clan.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type megaStats struct {
const RXClanQuery = `SELECT users.id, users.username, users.register_datetime, users.privileges,
latest_activity, rx_stats.username_aka,
rx_stats.country, rx_stats.user_color,
users.country, rx_stats.user_color,
rx_stats.ranked_score_std, rx_stats.total_score_std, rx_stats.pp_std, rx_stats.playcount_std, rx_stats.replays_watched_std, rx_stats.total_hits_std,
rx_stats.ranked_score_taiko, rx_stats.total_score_taiko, rx_stats.pp_taiko, rx_stats.playcount_taiko, rx_stats.replays_watched_taiko,rx_stats.total_hits_taiko,
rx_stats.ranked_score_ctb, rx_stats.total_score_ctb, rx_stats.pp_ctb, rx_stats.playcount_ctb, rx_stats.replays_watched_ctb, rx_stats.total_hits_ctb,
Expand All @@ -100,7 +100,7 @@ WHERE clan = ? AND privileges & 1 = 1
const VNClanQuery = `SELECT users.id, users.username, users.register_datetime, users.privileges,
latest_activity, users_stats.username_aka,
users_stats.country, users_stats.user_color,
users.country, users_stats.user_color,
users_stats.ranked_score_std, users_stats.total_score_std, users_stats.pp_std, users_stats.playcount_std, users_stats.replays_watched_std, users_stats.total_hits_std,
users_stats.ranked_score_taiko, users_stats.total_score_taiko, users_stats.pp_taiko, users_stats.playcount_taiko, users_stats.replays_watched_taiko,users_stats.total_hits_taiko,
users_stats.ranked_score_ctb, users_stats.total_score_ctb, users_stats.pp_ctb, users_stats.playcount_ctb, users_stats.replays_watched_ctb, users_stats.total_hits_ctb,
Expand All @@ -116,7 +116,7 @@ WHERE clan = ? AND privileges & 1 = 1
const APClanQuery = `SELECT users.id, users.username, users.register_datetime, users.privileges,
latest_activity, ap_stats.username_aka,
ap_stats.country, ap_stats.user_color,
users.country, ap_stats.user_color,
ap_stats.ranked_score_std, ap_stats.total_score_std, ap_stats.pp_std, ap_stats.playcount_std, ap_stats.replays_watched_std, ap_stats.total_hits_std,
ap_stats.ranked_score_taiko, ap_stats.total_score_taiko, ap_stats.pp_taiko, ap_stats.playcount_taiko, ap_stats.replays_watched_taiko,ap_stats.total_hits_taiko,
ap_stats.ranked_score_ctb, ap_stats.total_score_ctb, ap_stats.pp_ctb, ap_stats.playcount_ctb, ap_stats.replays_watched_ctb, ap_stats.total_hits_ctb,
Expand Down Expand Up @@ -483,7 +483,7 @@ func ClanMembersGET(md common.MethodData) common.CodeMessager {
err := md.DB.Select(&members.Members, `SELECT users.id, users.username, users.register_datetime, users.privileges,
latest_activity, users_stats.username_aka,
users_stats.country, users_stats.user_color,
users.country, users_stats.user_color,
users_stats.ranked_score_std, users_stats.total_score_std, users_stats.pp_std, users_stats.playcount_std, users_stats.replays_watched_std, users_stats.total_hits_std,
users_stats.ranked_score_taiko, users_stats.total_score_taiko, users_stats.pp_taiko, users_stats.playcount_taiko, users_stats.replays_watched_taiko, users_stats.total_hits_taiko
Expand All @@ -507,7 +507,7 @@ func ClanMembersGET(md common.MethodData) common.CodeMessager {
err := md.DB.Select(&members.Members, `SELECT users.id, users.username, users.register_datetime, users.privileges,
latest_activity, users_stats.username_aka,
users_stats.country, users_stats.user_color,
users.country, users_stats.user_color,
users_stats.ranked_score_std, users_stats.total_score_std, users_stats.pp_std, users_stats.playcount_std, users_stats.replays_watched_std,
users_stats.ranked_score_taiko, users_stats.total_score_taiko, users_stats.pp_taiko, users_stats.playcount_taiko, users_stats.replays_watched_taiko
Expand Down
2 changes: 1 addition & 1 deletion app/v1/friend.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ SELECT
users.id, users.username, users.register_datetime, users.privileges, users.latest_activity,
users_stats.username_aka,
users_stats.country
users.country
FROM users_relationships
LEFT JOIN users
ON users_relationships.user2 = users.id
Expand Down
12 changes: 6 additions & 6 deletions app/v1/leaderboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const rxUserQuery = `
SELECT
users.id, users.username, users.register_datetime, users.privileges, users.latest_activity,
rx_stats.username_aka, users_stats.country,
users_stats.username_aka, users.country,
users_stats.play_style, users_stats.favourite_mode,
rx_stats.ranked_score_%[1]s, rx_stats.total_score_%[1]s, rx_stats.playcount_%[1]s,
Expand All @@ -43,7 +43,7 @@ const apUserQuery = `
SELECT
users.id, users.username, users.register_datetime, users.privileges, users.latest_activity,
ap_stats.username_aka, users_stats.country,
users_stats.username_aka, users.country,
users_stats.play_style, users_stats.favourite_mode,
ap_stats.ranked_score_%[1]s, ap_stats.total_score_%[1]s, ap_stats.playcount_%[1]s,
Expand All @@ -57,7 +57,7 @@ const lbUserQuery = `
SELECT
users.id, users.username, users.register_datetime, users.privileges, users.latest_activity,
users_stats.username_aka, users_stats.country,
users_stats.username_aka, users.country,
users_stats.play_style, users_stats.favourite_mode,
users_stats.ranked_score_%[1]s, users_stats.total_score_%[1]s, users_stats.playcount_%[1]s,
Expand All @@ -73,19 +73,19 @@ func getScoreLb(m string, rx int, p int, l int, country string, sorted string, m
case 1:
order = " ORDER BY rx_stats.ranked_score_%[1]s DESC, rx_stats.pp_%[1]s DESC"
if country != "" {
whereClause = fmt.Sprintf(" AND users_stats.country = '%s'", strings.ToUpper(country))
whereClause = fmt.Sprintf(" AND users.country = '%s'", strings.ToUpper(country))
}
query = fmt.Sprintf(rxUserQuery+"WHERE (users.privileges & 3) >= 3"+whereClause+order+" LIMIT %d, %d", m, p*l, l)
case 2:
order = " ORDER BY ap_stats.ranked_score_%[1]s DESC, ap_stats.pp_%[1]s DESC"
if country != "" {
whereClause = fmt.Sprintf(" AND users_stats.country = '%s'", strings.ToUpper(country))
whereClause = fmt.Sprintf(" AND users.country = '%s'", strings.ToUpper(country))
}
query = fmt.Sprintf(apUserQuery+"WHERE (users.privileges & 3) >= 3"+whereClause+order+" LIMIT %d, %d", m, p*l, l)
default:
order = " ORDER BY users_stats.ranked_score_%[1]s DESC, users_stats.pp_%[1]s DESC"
if country != "" {
whereClause = fmt.Sprintf(" AND users_stats.country = '%s'", strings.ToUpper(country))
whereClause = fmt.Sprintf(" AND users.country = '%s'", strings.ToUpper(country))
}
query = fmt.Sprintf(lbUserQuery+"WHERE (users.privileges & 3) >= 3"+whereClause+order+" LIMIT %d, %d", m, p*l, l)
}
Expand Down
4 changes: 2 additions & 2 deletions app/v1/manage_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"strings"
"time"

redis "gopkg.in/redis.v5"
"github.com/RealistikOsu/RealistikAPI/common"
redis "gopkg.in/redis.v5"
)

type setAllowedData struct {
Expand Down Expand Up @@ -48,7 +48,7 @@ func UserManageSetAllowedPOST(md common.MethodData) common.CodeMessager {
query := `
SELECT users.id, users.username, register_datetime, privileges,
latest_activity, users_stats.username_aka,
users_stats.country
users.country
FROM users
LEFT JOIN users_stats
ON users.id=users_stats.id
Expand Down
29 changes: 14 additions & 15 deletions app/v1/score.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"strconv"
"strings"

"gopkg.in/thehowl/go-osuapi.v1"
"github.com/RealistikOsu/RealistikAPI/common"
"gopkg.in/thehowl/go-osuapi.v1"
"zxq.co/x/getrank"
)

Expand Down Expand Up @@ -78,8 +78,8 @@ func ScoresGET(md common.MethodData) common.CodeMessager {
if where.Clause == "" && md.Query("id") == "" {
return ErrMissingField("must specify at least one queried item")
}
rx_ap := common.Int(md.Query("rx"))

rx_ap := common.Int(md.Query("rx"))

//prob should be somewhere else but eh
switch rx_ap {
Expand Down Expand Up @@ -119,12 +119,11 @@ func ScoresGET(md common.MethodData) common.CodeMessager {
genModeClause(md)+` `+sort+common.Paginate(md.Query("p"), md.Query("l"), 100), "FIF")
}


where.Params = where.Params[:len(where.Params)-1]
// this isnt python dash
// Query := ""
var Query string
if rx_ap == 1 {
// Query := ""
var Query string
if rx_ap == 1 {
Query = `
SELECT
scores_relax.id, scores_relax.beatmap_md5, scores_relax.score,
Expand All @@ -135,12 +134,12 @@ func ScoresGET(md common.MethodData) common.CodeMessager {
scores_relax.completed,
users.id, users.username, users.register_datetime, users.privileges,
users.latest_activity, users_stats.username_aka, users_stats.country
users.latest_activity, users_stats.username_aka, users.country
FROM scores_relax
INNER JOIN users ON users.id = scores_relax.userid
INNER JOIN users_stats ON users_stats.id = scores_relax.userid
`
} else if rx_ap == 2 {
} else if rx_ap == 2 {
Query = `
SELECT
scores_ap.id, scores_ap.beatmap_md5, scores_ap.score,
Expand All @@ -151,13 +150,13 @@ func ScoresGET(md common.MethodData) common.CodeMessager {
scores_ap.completed,
users.id, users.username, users.register_datetime, users.privileges,
users.latest_activity, users_stats.username_aka, users_stats.country
users.latest_activity, users_stats.username_aka, users.country
FROM scores_ap
INNER JOIN users ON users.id = scores_ap.userid
INNER JOIN users_stats ON users_stats.id = scores_ap.userid
`
} else {
Query =`
Query = `
SELECT
scores.id, scores.beatmap_md5, scores.score,
scores.max_combo, scores.full_combo, scores.mods,
Expand All @@ -167,13 +166,13 @@ SELECT
scores.completed,
users.id, users.username, users.register_datetime, users.privileges,
users.latest_activity, users_stats.username_aka, users_stats.country
users.latest_activity, users_stats.username_aka, users.country
FROM scores
INNER JOIN users ON users.id = scores.userid
INNER JOIN users_stats ON users_stats.id = scores.userid
`
}
fmt.Println(Query)
}
fmt.Println(Query)
rows, err := md.DB.Query(Query+where.Clause, where.Params...)
if err != nil {
md.Err(err)
Expand Down Expand Up @@ -342,7 +341,7 @@ func genModeClauseColumn(md common.MethodData, column string) string {
if md.Query("mode") != "" {
m, err := strconv.Atoi(md.Query("mode"))
if err == nil && m >= 0 && m <= 3 {
modeClause = fmt.Sprintf("AND " + column + " = '%d'", m)
modeClause = fmt.Sprintf("AND "+column+" = '%d'", m)
}
}
return modeClause
Expand Down
Loading

0 comments on commit 11ddf56

Please sign in to comment.