Add struct for change_target_music function

This commit is contained in:
Ethan O'Brien 2024-07-17 21:51:36 -05:00
parent 61789f0165
commit b6a49a7080
2 changed files with 18 additions and 4 deletions

View file

@ -26,3 +26,5 @@ mime = "0.3.17"
sha2 = "0.10.8"
include-flate-codegen = "0.3.0"
libflate = "2.1.0"
serde_json = "1.0.120"
serde = { version = "1.0.204", features = ["derive"] }

View file

@ -102,14 +102,16 @@ pub fn star_event(req: HttpRequest, body: String) -> Option<JsonValue> {
pub fn change_target_music(req: HttpRequest, body: String) -> Option<JsonValue> {
let key = global::get_login(req.headers(), &body);
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
let mut event = get_event_data(&key, body["master_event_id"].as_i64().unwrap());
let body = &encryption::decrypt_packet(&body).unwrap();
let body: StarEventChangeTargetMusic = serde_json::from_str(body).unwrap();
let mut event = get_event_data(&key, body.master_event_id as i64);
event["star_event"]["music_change_count"] = (event["star_event"]["music_change_count"].as_i32().unwrap() + 1).into();
switch_music(&mut event, body["position"].as_i32().unwrap());
switch_music(&mut event, body.position as i32);
save_event_data(&key, body["master_event_id"].as_i64().unwrap(), event.clone());
save_event_data(&key, body.master_event_id as i64, event.clone());
Some(event["star_event"].clone())
}
@ -137,3 +139,13 @@ pub fn ranking(_req: HttpRequest, _body: String) -> Option<JsonValue> {
ranking_detail_list: []
})
}
// Start request structs
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
struct StarEventChangeTargetMusic {
master_event_id: usize,
position: usize
}