feat: Add functionality to remove a user's game opinion via a new API endpoint and UI button.
This commit is contained in:
@@ -123,6 +123,37 @@ async fn add_opinion(
|
||||
result
|
||||
}
|
||||
|
||||
#[patch("/opinion", data = "<req>")]
|
||||
async fn remove_opinion(
|
||||
token: auth::Token,
|
||||
user_list: &rocket::State<Mutex<Vec<User>>>,
|
||||
game_list: &rocket::State<Mutex<Vec<Game>>>,
|
||||
req: proto_utils::Proto<items::RemoveOpinionRequest>,
|
||||
) -> Option<items::Person> {
|
||||
let mut users = user_list.lock().await;
|
||||
let games = game_list.lock().await;
|
||||
let mut result = None;
|
||||
|
||||
if let Some(user) = users.iter_mut().find(|u| u.person.name == token.username) {
|
||||
let req = req.into_inner();
|
||||
|
||||
if let Some(existing) = user
|
||||
.person
|
||||
.opinion
|
||||
.iter()
|
||||
.position(|o| o.title == req.game_title)
|
||||
{
|
||||
user.person.opinion.remove(existing);
|
||||
}
|
||||
result = Some(user.person.clone());
|
||||
}
|
||||
|
||||
if result.is_some() {
|
||||
save_state(&games, &users);
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
mod cached_option;
|
||||
use cached_option::CachedOption;
|
||||
|
||||
@@ -280,6 +311,7 @@ async fn main() -> Result<(), std::io::Error> {
|
||||
get_game,
|
||||
get_games,
|
||||
add_opinion,
|
||||
remove_opinion,
|
||||
add_game,
|
||||
get_game_thumbnail
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user