Formatting again using vfmt

This commit is contained in:
Manuel 2023-01-11 19:08:24 +01:00
parent 318b1d3dc8
commit 859ac51f1a
Signed by: Manuel
GPG key ID: 4085037435E1F07A
5 changed files with 39 additions and 30 deletions

View file

@ -9,26 +9,32 @@ pub mut:
}
fn (mut app App) create_tables() int {
return app.db.exec_none(
'CREATE TABLE IF NOT EXISTS ScoreRes (
return app.db.exec_none('CREATE TABLE IF NOT EXISTS ScoreRes (
id INTEGER PRIMARY KEY,
player TEXT NOT NULL,
score INTEGER NOT NULL,
time SQLITE_INT64_TYPE NOT NULL
)'
)
)')
}
fn (mut app App) insert_score(score ScoreRes) ScoreRes {
sql app.db { insert score into ScoreRes }
sql app.db {
insert score into ScoreRes
}
last_row_id := app.db.last_insert_rowid()
return sql app.db { select from ScoreRes where id == last_row_id }
return sql app.db {
select from ScoreRes where id == last_row_id
}
}
fn (mut app App) get_scores() []ScoreRes {
return sql app.db { select from ScoreRes order by score desc }
return sql app.db {
select from ScoreRes order by score desc
}
}
fn (mut app App) delete_score(score_id int) {
sql app.db { delete from ScoreRes where id == score_id }
sql app.db {
delete from ScoreRes where id == score_id
}
}

View file

@ -41,7 +41,7 @@ fn main() {
}
mut host := '::'
if app_config.host != "" {
if app_config.host != '' {
host = app_config.host
}

View file

@ -31,8 +31,7 @@ pub fn (mut app App) score_list() vweb.Result {
return app.json(scores)
}
[post]
['/api/v1/score/submit']
['/api/v1/score/submit'; post]
pub fn (mut app App) score_submit() vweb.Result {
if !app.auth() {
app.set_status(401, '')
@ -44,7 +43,11 @@ pub fn (mut app App) score_submit() vweb.Result {
return app.json(Status{400, 'Bad JSON object'})
}
score := app.insert_score(ScoreRes{player:body.player, score:body.score, time:time.now().unix_time()})
score := app.insert_score(ScoreRes{
player: body.player
score: body.score
time: time.now().unix_time()
})
return app.json(score)
}