75 lines
2.2 KiB
Go
75 lines
2.2 KiB
Go
package database
|
|
|
|
import (
|
|
"database/sql"
|
|
_ "embed"
|
|
"strings"
|
|
)
|
|
|
|
type Application struct {
|
|
ID int64 `db:"id"`
|
|
Username string `db:"username"`
|
|
Age int64 `db:"age"`
|
|
PlayerType string `db:"player_type"`
|
|
EverBanned bool `db:"ever_banned"`
|
|
EverBannedExplanation string `db:"ever_banned_explanation"`
|
|
Reference string `db:"reference"`
|
|
ReadRules string `db:"read_rules"`
|
|
Accepted sql.NullBool `db:"accepted"`
|
|
Date string `db:"date"`
|
|
}
|
|
|
|
func (a *Application) Status() string {
|
|
switch {
|
|
case !a.Accepted.Valid:
|
|
return "Unanswered"
|
|
case a.Accepted.Bool:
|
|
return "Accepted"
|
|
case !a.Accepted.Bool:
|
|
return "Denied"
|
|
default:
|
|
return "Unknown"
|
|
}
|
|
}
|
|
|
|
func (a *Application) String() string {
|
|
return a.Username
|
|
}
|
|
|
|
//go:embed queries/application_by_id.sql
|
|
var applicationByIDSQL string
|
|
|
|
func (d *Database) ApplicationByID(id int64) (*Application, error) {
|
|
var app Application
|
|
return &app, d.db.Get(&app, applicationByIDSQL, id)
|
|
}
|
|
|
|
//go:embed queries/applications_by_player_username.sql
|
|
var applicationsByPlayerUsernameSQL string
|
|
|
|
func (d *Database) ApplicationsByPlayerUsername(username string) (apps []*Application, err error) {
|
|
return apps, d.db.Select(&apps, applicationsByPlayerUsernameSQL, strings.ToLower(username))
|
|
}
|
|
|
|
//go:embed queries/applications_by_username.sql
|
|
var applicationsByUsernameSQL string
|
|
|
|
func (d *Database) ApplicationsByUsername(username string) (apps []*Application, err error) {
|
|
return apps, d.db.Select(&apps, applicationsByUsernameSQL, strings.ToLower(username))
|
|
}
|
|
|
|
//go:embed queries/applications_by_username_count.sql
|
|
var applicationsByUsernameCountSQL string
|
|
|
|
func (d *Database) ApplicationsByUsernameCount(username string) (count int64, err error) {
|
|
return count, d.db.Get(&count, applicationsByUsernameCountSQL, strings.ToLower(username))
|
|
}
|
|
|
|
//go:embed queries/application_update_accepted.sql
|
|
var applicationUpdateAcceptedSQL string
|
|
|
|
func (d *Database) ApplicationUpdateAccepted(accepted *bool, appID int64) error {
|
|
_, err := d.db.Exec(applicationUpdateAcceptedSQL, accepted, appID)
|
|
return err
|
|
}
|