feat: logs api now also returns id

main
Jef Roosens 2022-09-11 20:34:02 +02:00
parent 7b59277931
commit 210508f1ee
Signed by untrusted user: Jef Roosens
GPG Key ID: B75D4F293C7052DB
6 changed files with 19 additions and 13 deletions

View File

@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
repository will be cloned with the default branch
* Build containers now explicitely set the PATH variable
* Refactor of web framework
* API endpoints now return id of newly created entries
### Removed

View File

@ -39,7 +39,7 @@ pub fn (c &Client) get_build_log_content(id int) ?string {
}
// add_build_log adds a new build log to the server.
pub fn (c &Client) add_build_log(target_id int, start_time time.Time, end_time time.Time, arch string, exit_code int, content string) ?Response<string> {
pub fn (c &Client) add_build_log(target_id int, start_time time.Time, end_time time.Time, arch string, exit_code int, content string) ?Response<int> {
params := {
'target': target_id.str()
'startTime': start_time.unix_time().str()
@ -48,7 +48,7 @@ pub fn (c &Client) add_build_log(target_id int, start_time time.Time, end_time t
'exitCode': exit_code.str()
}
data := c.send_request_with_body<string>(Method.post, '/api/v1/logs', params, content)?
data := c.send_request_with_body<int>(Method.post, '/api/v1/logs', params, content)?
return data
}

View File

@ -206,7 +206,7 @@ fn add(conf Config, t &NewTarget) ? {
c := client.new(conf.address, conf.api_key)
res := c.add_target(t)?
println("Target added with id $res.data")
println('Target added with id $res.data')
}
// remove removes a repository from the server's list.

View File

@ -79,10 +79,14 @@ pub fn (db &VieterDb) get_build_log(id int) ?BuildLog {
}
// add_build_log inserts the given BuildLog into the database.
pub fn (db &VieterDb) add_build_log(log BuildLog) {
pub fn (db &VieterDb) add_build_log(log BuildLog) int {
sql db.conn {
insert log into BuildLog
}
inserted_id := db.conn.last_id() as int
return inserted_id
}
// delete_build_log delete the BuildLog with the given ID from the database.

View File

@ -19,7 +19,7 @@ fn (mut app App) v1_get_logs() web.Result {
}
logs := app.db.get_build_logs(filter)
return app.json(http.Status.ok, new_data_response(logs))
return app.json(.ok, new_data_response(logs))
}
// v1_get_single_log returns the build log with the given id.
@ -27,7 +27,7 @@ fn (mut app App) v1_get_logs() web.Result {
fn (mut app App) v1_get_single_log(id int) web.Result {
log := app.db.get_build_log(id) or { return app.not_found() }
return app.json(http.Status.ok, new_data_response(log))
return app.json(.ok, new_data_response(log))
}
// v1_get_log_content returns the actual build log file for the given id.
@ -95,7 +95,8 @@ fn (mut app App) v1_post_log() web.Result {
exit_code: exit_code
}
app.db.add_build_log(log)
// id of newly created log
log_id := app.db.add_build_log(log)
repo_logs_dir := os.join_path(app.conf.data_dir, logs_dir_name, target_id.str(), arch)
@ -122,5 +123,5 @@ fn (mut app App) v1_post_log() web.Result {
return app.status(http.Status.length_required)
}
return app.json(http.Status.ok, new_response('Logs added successfully.'))
return app.json(.ok, new_data_response(log_id))
}

View File

@ -2,7 +2,7 @@ module server
import web
import net.http
import web.response { new_data_response, new_response, new_full_response }
import web.response { new_data_response, new_response }
import db
import models { Target, TargetArch, TargetFilter }
@ -14,7 +14,7 @@ fn (mut app App) v1_get_targets() web.Result {
}
repos := app.db.get_targets(filter)
return app.json(http.Status.ok, new_data_response(repos))
return app.json(.ok, new_data_response(repos))
}
// v1_get_single_target returns the information for a single target.
@ -22,7 +22,7 @@ fn (mut app App) v1_get_targets() web.Result {
fn (mut app App) v1_get_single_target(id int) web.Result {
repo := app.db.get_target(id) or { return app.not_found() }
return app.json(http.Status.ok, new_data_response(repo))
return app.json(.ok, new_data_response(repo))
}
// v1_post_target creates a new target from the provided query string.
@ -55,7 +55,7 @@ fn (mut app App) v1_post_target() web.Result {
fn (mut app App) v1_delete_target(id int) web.Result {
app.db.delete_target(id)
return app.json(http.Status.ok, new_response('Repo removed successfully.'))
return app.status(.ok)
}
// v1_patch_target updates a target's data with the given query params.
@ -69,5 +69,5 @@ fn (mut app App) v1_patch_target(id int) web.Result {
app.db.update_target_archs(id, arch_objs)
}
return app.json(http.Status.ok, new_response('Repo updated successfully.'))
return app.status(.ok)
}