Skip to content

Commit

Permalink
fix(api): Axum API, fix delete tag response
Browse files Browse the repository at this point in the history
Response after deleting a tag should be:

```
{
  data: 1
}
```

not:

```
{
  data: "1"
}
```

where 1 (`i64`) is the tag ID.
  • Loading branch information
josecelano committed Jun 19, 2023
1 parent 48b27ea commit 34db879
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/web/api/v1/contexts/tag/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use super::responses::{added_tag, deleted_tag};
use crate::common::AppData;
use crate::databases::database;
use crate::errors::ServiceError;
use crate::models::torrent_tag::TorrentTag;
use crate::models::torrent_tag::{TagId, TorrentTag};
use crate::web::api::v1::extractors::bearer_token::Extract;
use crate::web::api::v1::responses::{self, OkResponseData};

Expand Down Expand Up @@ -72,7 +72,7 @@ pub async fn delete_handler(
State(app_data): State<Arc<AppData>>,
Extract(maybe_bearer_token): Extract,
extract::Json(delete_tag_form): extract::Json<DeleteTagForm>,
) -> Result<Json<OkResponseData<String>>, ServiceError> {
) -> Result<Json<OkResponseData<TagId>>, ServiceError> {
let user_id = app_data.auth.get_user_id_from_bearer_token(&maybe_bearer_token).await?;

match app_data.tag_service.delete_tag(&delete_tag_form.tag_id, &user_id).await {
Expand Down
6 changes: 2 additions & 4 deletions src/web/api/v1/contexts/tag/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ pub fn added_tag(tag_name: &str) -> Json<OkResponseData<String>> {
}

/// Response after successfully deleting a tag.
pub fn deleted_tag(tag_id: TagId) -> Json<OkResponseData<String>> {
Json(OkResponseData {
data: tag_id.to_string(),
})
pub fn deleted_tag(tag_id: TagId) -> Json<OkResponseData<TagId>> {
Json(OkResponseData { data: tag_id })
}
2 changes: 1 addition & 1 deletion tests/e2e/contexts/tag/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ mod with_axum_implementation {
#[tokio::test]
async fn it_should_allow_admins_to_delete_tags() {
let mut env = TestEnv::new();
env.start(api::Implementation::ActixWeb).await;
env.start(api::Implementation::Axum).await;

if env::var(ENV_VAR_E2E_EXCLUDE_AXUM_IMPL).is_ok() {
println!("Skipped");
Expand Down

0 comments on commit 34db879

Please sign in to comment.