From b7af0511038db4297450f46da952a4cfeab72da9 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Wed, 28 Dec 2022 21:24:30 +0100 Subject: [PATCH] feat(client): support removing repos, arch-repos & packages --- src/client/logs.v | 9 ++++----- src/client/repos.v | 16 ++++++++++++++++ src/client/targets.v | 11 +++++------ 3 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 src/client/repos.v diff --git a/src/client/logs.v b/src/client/logs.v index 2ddb2e2..6553837 100644 --- a/src/client/logs.v +++ b/src/client/logs.v @@ -1,28 +1,27 @@ module client import models { BuildLog, BuildLogFilter } -import net.http { Method } import web.response { Response } import time // get_build_logs returns all build logs. pub fn (c &Client) get_build_logs(filter BuildLogFilter) ![]BuildLog { params := models.params_from(filter) - data := c.send_request<[]BuildLog>(Method.get, '/api/v1/logs', params)! + data := c.send_request<[]BuildLog>(.get, '/api/v1/logs', params)! return data.data } // get_build_log returns a specific build log. pub fn (c &Client) get_build_log(id int) !BuildLog { - data := c.send_request(Method.get, '/api/v1/logs/$id', {})! + data := c.send_request(.get, '/api/v1/logs/$id', {})! return data.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/v1/logs/$id/content', {}, '')! + data := c.send_request_raw_response(.get, '/api/v1/logs/$id/content', {}, '')! return data } @@ -37,7 +36,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(Method.post, '/api/v1/logs', params, content)! + data := c.send_request_with_body(.post, '/api/v1/logs', params, content)! return data } diff --git a/src/client/repos.v b/src/client/repos.v new file mode 100644 index 0000000..9644e9b --- /dev/null +++ b/src/client/repos.v @@ -0,0 +1,16 @@ +module client + +// remove_repo removes an entire repository. +pub fn (c &Client) remove_repo(repo string) ! { + c.send_request(.delete, '/$repo', {})! +} + +// remove_arch_repo removes an entire arch-repo. +pub fn (c &Client) remove_arch_repo(repo string, arch string) ! { + c.send_request(.delete, '/$repo/$arch', {})! +} + +// remove_package removes a single package from the given arch-repo. +pub fn (c &Client) remove_package(repo string, arch string, pkgname string) ! { + c.send_request(.delete, '/$repo/$arch/$pkgname', {})! +} diff --git a/src/client/targets.v b/src/client/targets.v index da6a9e4..565832e 100644 --- a/src/client/targets.v +++ b/src/client/targets.v @@ -1,12 +1,11 @@ module client import models { Target, TargetFilter } -import net.http { Method } // get_targets returns a list of targets, given a filter object. pub fn (c &Client) get_targets(filter TargetFilter) ![]Target { params := models.params_from(filter) - data := c.send_request<[]Target>(Method.get, '/api/v1/targets', params)! + data := c.send_request<[]Target>(.get, '/api/v1/targets', params)! return data.data } @@ -34,7 +33,7 @@ pub fn (c &Client) get_all_targets() ![]Target { // get_target returns the target for a specific id. pub fn (c &Client) get_target(id int) !Target { - data := c.send_request(Method.get, '/api/v1/targets/$id', {})! + data := c.send_request(.get, '/api/v1/targets/$id', {})! return data.data } @@ -51,14 +50,14 @@ pub struct NewTarget { // add_target adds a new target to the server. pub fn (c &Client) add_target(t NewTarget) !int { params := models.params_from(t) - data := c.send_request(Method.post, '/api/v1/targets', params)! + data := c.send_request(.post, '/api/v1/targets', params)! return data.data } // remove_target removes the target with the given id from the server. pub fn (c &Client) remove_target(id int) !string { - data := c.send_request(Method.delete, '/api/v1/targets/$id', {})! + data := c.send_request(.delete, '/api/v1/targets/$id', {})! return data.data } @@ -66,7 +65,7 @@ pub fn (c &Client) remove_target(id int) !string { // patch_target sends a PATCH request to the given target with the params as // payload. pub fn (c &Client) patch_target(id int, params map[string]string) !string { - data := c.send_request(Method.patch, '/api/v1/targets/$id', params)! + data := c.send_request(.patch, '/api/v1/targets/$id', params)! return data.data }