forked from vieter-v/vieter
feat(server): moved api routes under /v1 namespace
parent
3a5ac5d32b
commit
6b79f7b5ed
|
@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [Unreleased](https://git.rustybever.be/vieter/vieter/src/branch/dev)
|
## [Unreleased](https://git.rustybever.be/vieter/vieter/src/branch/dev)
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
* Moved all API routes under `/v1` namespace
|
||||||
|
|
||||||
## [0.3.0](https://git.rustybever.be/vieter/vieter/src/tag/0.3.0)
|
## [0.3.0](https://git.rustybever.be/vieter/vieter/src/tag/0.3.0)
|
||||||
|
|
||||||
Nothing besides bumping the versions.
|
Nothing besides bumping the versions.
|
||||||
|
|
|
@ -7,7 +7,7 @@ import response { Response }
|
||||||
// get_git_repos returns a list of GitRepo's, given a filter object.
|
// get_git_repos returns a list of GitRepo's, given a filter object.
|
||||||
pub fn (c &Client) get_git_repos(filter GitRepoFilter) ?[]GitRepo {
|
pub fn (c &Client) get_git_repos(filter GitRepoFilter) ?[]GitRepo {
|
||||||
params := models.params_from(filter)
|
params := models.params_from(filter)
|
||||||
data := c.send_request<[]GitRepo>(Method.get, '/api/repos', params)?
|
data := c.send_request<[]GitRepo>(Method.get, '/api/v1/repos', params)?
|
||||||
|
|
||||||
return data.data
|
return data.data
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ pub fn (c &Client) get_all_git_repos() ?[]GitRepo {
|
||||||
|
|
||||||
// get_git_repo returns the repo for a specific ID.
|
// get_git_repo returns the repo for a specific ID.
|
||||||
pub fn (c &Client) get_git_repo(id int) ?GitRepo {
|
pub fn (c &Client) get_git_repo(id int) ?GitRepo {
|
||||||
data := c.send_request<GitRepo>(Method.get, '/api/repos/$id', {})?
|
data := c.send_request<GitRepo>(Method.get, '/api/v1/repos/$id', {})?
|
||||||
|
|
||||||
return data.data
|
return data.data
|
||||||
}
|
}
|
||||||
|
@ -52,14 +52,14 @@ pub fn (c &Client) add_git_repo(url string, branch string, repo string, arch []s
|
||||||
params['arch'] = arch.join(',')
|
params['arch'] = arch.join(',')
|
||||||
}
|
}
|
||||||
|
|
||||||
data := c.send_request<string>(Method.post, '/api/repos', params)?
|
data := c.send_request<string>(Method.post, '/api/v1/repos', params)?
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove_git_repo removes the repo with the given ID from the server.
|
// remove_git_repo removes the repo with the given ID from the server.
|
||||||
pub fn (c &Client) remove_git_repo(id int) ?Response<string> {
|
pub fn (c &Client) remove_git_repo(id int) ?Response<string> {
|
||||||
data := c.send_request<string>(Method.delete, '/api/repos/$id', {})?
|
data := c.send_request<string>(Method.delete, '/api/v1/repos/$id', {})?
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ pub fn (c &Client) remove_git_repo(id int) ?Response<string> {
|
||||||
// patch_git_repo sends a PATCH request to the given repo with the params as
|
// patch_git_repo sends a PATCH request to the given repo with the params as
|
||||||
// payload.
|
// payload.
|
||||||
pub fn (c &Client) patch_git_repo(id int, params map[string]string) ?Response<string> {
|
pub fn (c &Client) patch_git_repo(id int, params map[string]string) ?Response<string> {
|
||||||
data := c.send_request<string>(Method.patch, '/api/repos/$id', params)?
|
data := c.send_request<string>(Method.patch, '/api/v1/repos/$id', params)?
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import time
|
||||||
// get_build_logs returns all build logs.
|
// get_build_logs returns all build logs.
|
||||||
pub fn (c &Client) get_build_logs(filter BuildLogFilter) ?Response<[]BuildLog> {
|
pub fn (c &Client) get_build_logs(filter BuildLogFilter) ?Response<[]BuildLog> {
|
||||||
params := models.params_from(filter)
|
params := models.params_from(filter)
|
||||||
data := c.send_request<[]BuildLog>(Method.get, '/api/logs', params)?
|
data := c.send_request<[]BuildLog>(Method.get, '/api/v1/logs', params)?
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
@ -19,21 +19,21 @@ pub fn (c &Client) get_build_logs_for_repo(repo_id int) ?Response<[]BuildLog> {
|
||||||
'repo': repo_id.str()
|
'repo': repo_id.str()
|
||||||
}
|
}
|
||||||
|
|
||||||
data := c.send_request<[]BuildLog>(Method.get, '/api/logs', params)?
|
data := c.send_request<[]BuildLog>(Method.get, '/api/v1/logs', params)?
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
// get_build_log returns a specific build log.
|
// get_build_log returns a specific build log.
|
||||||
pub fn (c &Client) get_build_log(id int) ?Response<BuildLog> {
|
pub fn (c &Client) get_build_log(id int) ?Response<BuildLog> {
|
||||||
data := c.send_request<BuildLog>(Method.get, '/api/logs/$id', {})?
|
data := c.send_request<BuildLog>(Method.get, '/api/v1/logs/$id', {})?
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
// get_build_log_content returns the contents of the build log file.
|
// get_build_log_content returns the contents of the build log file.
|
||||||
pub fn (c &Client) get_build_log_content(id int) ?string {
|
pub fn (c &Client) get_build_log_content(id int) ?string {
|
||||||
data := c.send_request_raw_response(Method.get, '/api/logs/$id/content', {}, '')?
|
data := c.send_request_raw_response(Method.get, '/api/v1/logs/$id/content', {}, '')?
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ pub fn (c &Client) add_build_log(repo_id int, start_time time.Time, end_time tim
|
||||||
'exitCode': exit_code.str()
|
'exitCode': exit_code.str()
|
||||||
}
|
}
|
||||||
|
|
||||||
data := c.send_request_with_body<string>(Method.post, '/api/logs', params, content)?
|
data := c.send_request_with_body<string>(Method.post, '/api/v1/logs', params, content)?
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,9 @@ import response { new_data_response, new_response }
|
||||||
import db
|
import db
|
||||||
import models { GitRepo, GitRepoArch, GitRepoFilter }
|
import models { GitRepo, GitRepoArch, GitRepoFilter }
|
||||||
|
|
||||||
// get_repos returns the current list of repos.
|
// v1_get_repos returns the current list of repos.
|
||||||
['/api/repos'; get]
|
['/api/v1/repos'; get]
|
||||||
fn (mut app App) get_repos() web.Result {
|
fn (mut app App) v1_get_repos() web.Result {
|
||||||
if !app.is_authorized() {
|
if !app.is_authorized() {
|
||||||
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
||||||
}
|
}
|
||||||
|
@ -21,9 +21,9 @@ fn (mut app App) get_repos() web.Result {
|
||||||
return app.json(http.Status.ok, new_data_response(repos))
|
return app.json(http.Status.ok, new_data_response(repos))
|
||||||
}
|
}
|
||||||
|
|
||||||
// get_single_repo returns the information for a single repo.
|
// v1_get_single_repo returns the information for a single repo.
|
||||||
['/api/repos/:id'; get]
|
['/api/v1/repos/:id'; get]
|
||||||
fn (mut app App) get_single_repo(id int) web.Result {
|
fn (mut app App) v1_get_single_repo(id int) web.Result {
|
||||||
if !app.is_authorized() {
|
if !app.is_authorized() {
|
||||||
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
||||||
}
|
}
|
||||||
|
@ -33,9 +33,9 @@ fn (mut app App) get_single_repo(id int) web.Result {
|
||||||
return app.json(http.Status.ok, new_data_response(repo))
|
return app.json(http.Status.ok, new_data_response(repo))
|
||||||
}
|
}
|
||||||
|
|
||||||
// post_repo creates a new repo from the provided query string.
|
// v1_post_repo creates a new repo from the provided query string.
|
||||||
['/api/repos'; post]
|
['/api/v1/repos'; post]
|
||||||
fn (mut app App) post_repo() web.Result {
|
fn (mut app App) v1_post_repo() web.Result {
|
||||||
if !app.is_authorized() {
|
if !app.is_authorized() {
|
||||||
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
||||||
}
|
}
|
||||||
|
@ -57,9 +57,9 @@ fn (mut app App) post_repo() web.Result {
|
||||||
return app.json(http.Status.ok, new_response('Repo added successfully.'))
|
return app.json(http.Status.ok, new_response('Repo added successfully.'))
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete_repo removes a given repo from the server's list.
|
// v1_delete_repo removes a given repo from the server's list.
|
||||||
['/api/repos/:id'; delete]
|
['/api/v1/repos/:id'; delete]
|
||||||
fn (mut app App) delete_repo(id int) web.Result {
|
fn (mut app App) v1_delete_repo(id int) web.Result {
|
||||||
if !app.is_authorized() {
|
if !app.is_authorized() {
|
||||||
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
||||||
}
|
}
|
||||||
|
@ -69,9 +69,9 @@ fn (mut app App) delete_repo(id int) web.Result {
|
||||||
return app.json(http.Status.ok, new_response('Repo removed successfully.'))
|
return app.json(http.Status.ok, new_response('Repo removed successfully.'))
|
||||||
}
|
}
|
||||||
|
|
||||||
// patch_repo updates a repo's data with the given query params.
|
// v1_patch_repo updates a repo's data with the given query params.
|
||||||
['/api/repos/:id'; patch]
|
['/api/v1/repos/:id'; patch]
|
||||||
fn (mut app App) patch_repo(id int) web.Result {
|
fn (mut app App) v1_patch_repo(id int) web.Result {
|
||||||
if !app.is_authorized() {
|
if !app.is_authorized() {
|
||||||
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,10 +10,10 @@ import os
|
||||||
import util
|
import util
|
||||||
import models { BuildLog, BuildLogFilter }
|
import models { BuildLog, BuildLogFilter }
|
||||||
|
|
||||||
// get_logs returns all build logs in the database. A 'repo' query param can
|
// v1_get_logs returns all build logs in the database. A 'repo' query param can
|
||||||
// optionally be added to limit the list of build logs to that repository.
|
// optionally be added to limit the list of build logs to that repository.
|
||||||
['/api/logs'; get]
|
['/api/v1/logs'; get]
|
||||||
fn (mut app App) get_logs() web.Result {
|
fn (mut app App) v1_get_logs() web.Result {
|
||||||
if !app.is_authorized() {
|
if !app.is_authorized() {
|
||||||
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
||||||
}
|
}
|
||||||
|
@ -26,9 +26,9 @@ fn (mut app App) get_logs() web.Result {
|
||||||
return app.json(http.Status.ok, new_data_response(logs))
|
return app.json(http.Status.ok, new_data_response(logs))
|
||||||
}
|
}
|
||||||
|
|
||||||
// get_single_log returns the build log with the given id.
|
// v1_get_single_log returns the build log with the given id.
|
||||||
['/api/logs/:id'; get]
|
['/api/v1/logs/:id'; get]
|
||||||
fn (mut app App) get_single_log(id int) web.Result {
|
fn (mut app App) v1_get_single_log(id int) web.Result {
|
||||||
if !app.is_authorized() {
|
if !app.is_authorized() {
|
||||||
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
||||||
}
|
}
|
||||||
|
@ -38,9 +38,9 @@ fn (mut app App) get_single_log(id int) web.Result {
|
||||||
return app.json(http.Status.ok, new_data_response(log))
|
return app.json(http.Status.ok, new_data_response(log))
|
||||||
}
|
}
|
||||||
|
|
||||||
// get_log_content returns the actual build log file for the given id.
|
// v1_get_log_content returns the actual build log file for the given id.
|
||||||
['/api/logs/:id/content'; get]
|
['/api/v1/logs/:id/content'; get]
|
||||||
fn (mut app App) get_log_content(id int) web.Result {
|
fn (mut app App) v1_get_log_content(id int) web.Result {
|
||||||
if !app.is_authorized() {
|
if !app.is_authorized() {
|
||||||
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
||||||
}
|
}
|
||||||
|
@ -62,9 +62,9 @@ fn parse_query_time(query string) ?time.Time {
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
// post_log adds a new log to the database.
|
// v1_post_log adds a new log to the database.
|
||||||
['/api/logs'; post]
|
['/api/v1/logs'; post]
|
||||||
fn (mut app App) post_log() web.Result {
|
fn (mut app App) v1_post_log() web.Result {
|
||||||
if !app.is_authorized() {
|
if !app.is_authorized() {
|
||||||
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue