-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow creators to reset a quest instance (#175)
This PR: - adds function to DB interface to remove events that made progress on a quest instance - adds function to DB interface to remove a quest instance from the completed quest instances table - adds a new endpoint to allow the creators to reset a quest instance state to the start
- Loading branch information
Showing
16 changed files
with
333 additions
and
53 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
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,7 @@ | ||
pub mod reset; | ||
|
||
use actix_web::Scope; | ||
|
||
pub fn services(api_scope: Scope) -> Scope { | ||
api_scope.service(reset::reset_quest_instance) | ||
} |
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,40 @@ | ||
use crate::{api::routes::quests::get_user_address_from_request, domain::quests}; | ||
use actix_web::{patch, web, HttpRequest, HttpResponse}; | ||
use quests_db::Database; | ||
use quests_protocol::definitions::Quest; | ||
use serde::{Deserialize, Serialize}; | ||
use utoipa::ToSchema; | ||
|
||
#[derive(Serialize, Deserialize, ToSchema)] | ||
pub struct GetCreatorQuestsResponse { | ||
pub quests: Vec<Quest>, | ||
} | ||
|
||
/// Reset a User's Quest Instance. It can only be executed by the Quest Creator | ||
#[utoipa::path( | ||
params( | ||
("quest_instance" = String, description = "Quest Instance UUID") | ||
), | ||
responses( | ||
(status = 204, description = "Quest Instance was reset"), | ||
(status = 401, description = "Unauthorized"), | ||
(status = 403, description = "Cannot reset a Quest Instance if you are not the Quest Creator"), | ||
(status = 404, description = "Quest Instance not found"), | ||
(status = 500, description = "Internal Server Error") | ||
) | ||
)] | ||
#[patch("/instances/{quest_instance}/reset")] | ||
pub async fn reset_quest_instance( | ||
req: HttpRequest, | ||
data: web::Data<Database>, | ||
quest_instance: web::Path<String>, | ||
) -> HttpResponse { | ||
let db = data.into_inner(); | ||
|
||
let auth_user = get_user_address_from_request(&req).unwrap(); // unwrap here is safe | ||
|
||
match quests::reset_quest_instance(db, &auth_user, &quest_instance).await { | ||
Ok(_) => HttpResponse::NoContent().finish(), | ||
Err(err) => HttpResponse::from_error(err), | ||
} | ||
} |
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.