From 42cbf4d76b89536850c6d549b935ea4cac1582b9 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Tue, 14 Jun 2022 12:54:32 +0200 Subject: [PATCH] feat(server): moved api routes under /v1 namespace --- CHANGELOG.md | 4 ++++ src/client/git.v | 10 +++++----- src/client/logs.v | 10 +++++----- src/server/git.v | 30 +++++++++++++++--------------- src/server/logs.v | 24 ++++++++++++------------ 5 files changed, 41 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99a795a..9adee07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) +### Changed + +* Moved all API routes under `/v1` namespace + ## [0.3.0](https://git.rustybever.be/vieter/vieter/src/tag/0.3.0) Nothing besides bumping the versions. diff --git a/src/client/git.v b/src/client/git.v index 4496c08..7b5e52e 100644 --- a/src/client/git.v +++ b/src/client/git.v @@ -7,7 +7,7 @@ import response { Response } // get_git_repos returns a list of GitRepo's, given a filter object. pub fn (c &Client) get_git_repos(filter GitRepoFilter) ?[]GitRepo { 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 } @@ -35,7 +35,7 @@ pub fn (c &Client) get_all_git_repos() ?[]GitRepo { // get_git_repo returns the repo for a specific ID. pub fn (c &Client) get_git_repo(id int) ?GitRepo { - data := c.send_request(Method.get, '/api/repos/$id', {})? + data := c.send_request(Method.get, '/api/v1/repos/$id', {})? 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(',') } - data := c.send_request(Method.post, '/api/repos', params)? + data := c.send_request(Method.post, '/api/v1/repos', params)? return data } // remove_git_repo removes the repo with the given ID from the server. pub fn (c &Client) remove_git_repo(id int) ?Response { - data := c.send_request(Method.delete, '/api/repos/$id', {})? + data := c.send_request(Method.delete, '/api/v1/repos/$id', {})? return data } @@ -67,7 +67,7 @@ pub fn (c &Client) remove_git_repo(id int) ?Response { // patch_git_repo sends a PATCH request to the given repo with the params as // payload. pub fn (c &Client) patch_git_repo(id int, params map[string]string) ?Response { - data := c.send_request(Method.patch, '/api/repos/$id', params)? + data := c.send_request(Method.patch, '/api/v1/repos/$id', params)? return data } diff --git a/src/client/logs.v b/src/client/logs.v index 739de23..2d78fc1 100644 --- a/src/client/logs.v +++ b/src/client/logs.v @@ -8,7 +8,7 @@ import time // get_build_logs returns all build logs. pub fn (c &Client) get_build_logs(filter BuildLogFilter) ?Response<[]BuildLog> { 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 } @@ -19,21 +19,21 @@ pub fn (c &Client) get_build_logs_for_repo(repo_id int) ?Response<[]BuildLog> { '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 } // get_build_log returns a specific build log. pub fn (c &Client) get_build_log(id int) ?Response { - data := c.send_request(Method.get, '/api/logs/$id', {})? + data := c.send_request(Method.get, '/api/v1/logs/$id', {})? return data } // get_build_log_content returns the contents of the build log file. 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 } @@ -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() } - data := c.send_request_with_body(Method.post, '/api/logs', params, content)? + data := c.send_request_with_body(Method.post, '/api/v1/logs', params, content)? return data } diff --git a/src/server/git.v b/src/server/git.v index c1bc6f3..f3fe010 100644 --- a/src/server/git.v +++ b/src/server/git.v @@ -6,9 +6,9 @@ import response { new_data_response, new_response } import db import models { GitRepo, GitRepoArch, GitRepoFilter } -// get_repos returns the current list of repos. -['/api/repos'; get] -fn (mut app App) get_repos() web.Result { +// v1_get_repos returns the current list of repos. +['/api/v1/repos'; get] +fn (mut app App) v1_get_repos() web.Result { if !app.is_authorized() { 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)) } -// get_single_repo returns the information for a single repo. -['/api/repos/:id'; get] -fn (mut app App) get_single_repo(id int) web.Result { +// v1_get_single_repo returns the information for a single repo. +['/api/v1/repos/:id'; get] +fn (mut app App) v1_get_single_repo(id int) web.Result { if !app.is_authorized() { 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)) } -// post_repo creates a new repo from the provided query string. -['/api/repos'; post] -fn (mut app App) post_repo() web.Result { +// v1_post_repo creates a new repo from the provided query string. +['/api/v1/repos'; post] +fn (mut app App) v1_post_repo() web.Result { if !app.is_authorized() { 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.')) } -// delete_repo removes a given repo from the server's list. -['/api/repos/:id'; delete] -fn (mut app App) delete_repo(id int) web.Result { +// v1_delete_repo removes a given repo from the server's list. +['/api/v1/repos/:id'; delete] +fn (mut app App) v1_delete_repo(id int) web.Result { if !app.is_authorized() { 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.')) } -// patch_repo updates a repo's data with the given query params. -['/api/repos/:id'; patch] -fn (mut app App) patch_repo(id int) web.Result { +// v1_patch_repo updates a repo's data with the given query params. +['/api/v1/repos/:id'; patch] +fn (mut app App) v1_patch_repo(id int) web.Result { if !app.is_authorized() { return app.json(http.Status.unauthorized, new_response('Unauthorized.')) } diff --git a/src/server/logs.v b/src/server/logs.v index 314e322..748c3a6 100644 --- a/src/server/logs.v +++ b/src/server/logs.v @@ -10,10 +10,10 @@ import os import util 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. -['/api/logs'; get] -fn (mut app App) get_logs() web.Result { +['/api/v1/logs'; get] +fn (mut app App) v1_get_logs() web.Result { if !app.is_authorized() { 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)) } -// get_single_log returns the build log with the given id. -['/api/logs/:id'; get] -fn (mut app App) get_single_log(id int) web.Result { +// v1_get_single_log returns the build log with the given id. +['/api/v1/logs/:id'; get] +fn (mut app App) v1_get_single_log(id int) web.Result { if !app.is_authorized() { 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)) } -// get_log_content returns the actual build log file for the given id. -['/api/logs/:id/content'; get] -fn (mut app App) get_log_content(id int) web.Result { +// v1_get_log_content returns the actual build log file for the given id. +['/api/v1/logs/:id/content'; get] +fn (mut app App) v1_get_log_content(id int) web.Result { if !app.is_authorized() { return app.json(http.Status.unauthorized, new_response('Unauthorized.')) } @@ -62,9 +62,9 @@ fn parse_query_time(query string) ?time.Time { return t } -// post_log adds a new log to the database. -['/api/logs'; post] -fn (mut app App) post_log() web.Result { +// v1_post_log adds a new log to the database. +['/api/v1/logs'; post] +fn (mut app App) v1_post_log() web.Result { if !app.is_authorized() { return app.json(http.Status.unauthorized, new_response('Unauthorized.')) }