-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement setting labels for advisories
- Loading branch information
Showing
9 changed files
with
317 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use crate::advisory::service::AdvisoryService; | ||
use actix_web::{patch, put, web, HttpResponse, Responder}; | ||
use trustify_common::id::Id; | ||
use trustify_entity::labels::Labels; | ||
|
||
/// Replace the labels of an advisory | ||
#[utoipa::path( | ||
tag = "advisory", | ||
context_path = "/api", | ||
request_body = inline(Labels), | ||
params( | ||
("id" = string, Path, description = "Digest/hash of the document, prefixed by hash type, such as 'sha256:<hash>' or 'urn:uuid:<uuid>'"), | ||
), | ||
responses( | ||
(status = 204, description = "Replaced the labels of the advisory"), | ||
(status = 404, description = "The advisory could not be found"), | ||
), | ||
)] | ||
#[put("/v1/advisory/{id}/label")] | ||
pub async fn set( | ||
advisory: web::Data<AdvisoryService>, | ||
id: web::Path<Id>, | ||
web::Json(labels): web::Json<Labels>, | ||
) -> actix_web::Result<impl Responder> { | ||
Ok( | ||
match advisory.set_labels(id.into_inner(), labels, ()).await? { | ||
Some(()) => HttpResponse::NoContent(), | ||
None => HttpResponse::NotFound(), | ||
}, | ||
) | ||
} | ||
|
||
/// Modify existing labels of an advisory | ||
#[utoipa::path( | ||
tag = "advisory", | ||
context_path = "/api", | ||
request_body = inline(Labels), | ||
params( | ||
("id" = string, Path, description = "Digest/hash of the document, prefixed by hash type, such as 'sha256:<hash>' or 'urn:uuid:<uuid>'"), | ||
), | ||
responses( | ||
(status = 204, description = "Modified the labels of the advisory"), | ||
(status = 404, description = "The advisory could not be found"), | ||
), | ||
)] | ||
#[patch("/v1/advisory/{id}/label")] | ||
pub async fn update( | ||
advisory: web::Data<AdvisoryService>, | ||
id: web::Path<Id>, | ||
web::Json(update): web::Json<Labels>, | ||
) -> actix_web::Result<impl Responder> { | ||
Ok( | ||
match advisory | ||
.update_labels(id.into_inner(), |labels| labels.apply(update)) | ||
.await? | ||
{ | ||
Some(()) => HttpResponse::NoContent(), | ||
None => HttpResponse::NotFound(), | ||
}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.