Implement /api/mission/clear
This commit is contained in:
@ -2,17 +2,50 @@ use json;
|
||||
use json::object;
|
||||
use crate::router::global;
|
||||
use actix_web::{HttpResponse, HttpRequest};
|
||||
//use crate::router::userdata;
|
||||
use crate::router::userdata;
|
||||
use crate::encryption;
|
||||
|
||||
pub fn mission(_req: HttpRequest) -> HttpResponse {
|
||||
//let key = global::get_login(req.headers());
|
||||
//let user = userdata::get_acc(&key);
|
||||
pub fn mission(req: HttpRequest) -> HttpResponse {
|
||||
let key = global::get_login(req.headers(), "");
|
||||
let missions = userdata::get_acc_missions(&key);
|
||||
|
||||
let resp = object!{
|
||||
"code": 0,
|
||||
"server_time": global::timestamp(),
|
||||
"data": {
|
||||
"mission_list": []
|
||||
"mission_list": missions
|
||||
}
|
||||
};
|
||||
global::send(resp)
|
||||
}
|
||||
|
||||
pub fn clear(req: HttpRequest, body: String) -> HttpResponse {
|
||||
let key = global::get_login(req.headers(), &body);
|
||||
let mut missions = userdata::get_acc_missions(&key);
|
||||
let body = json::parse(&encryption::decrypt_packet(&body).unwrap()).unwrap();
|
||||
|
||||
for (_i, id) in body["master_mission_ids"].members().enumerate() {
|
||||
for (i, mission) in missions.members().enumerate() {
|
||||
if mission["master_mission_id"].to_string() == id.to_string() {
|
||||
//I think this is all?
|
||||
missions[i]["progress"] = (1).into();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
userdata::save_acc_missions(&key, missions);
|
||||
|
||||
let resp = object!{
|
||||
"code": 0,
|
||||
"server_time": global::timestamp(),
|
||||
"data": {
|
||||
"clear_mission_ids": body["master_mission_ids"].clone()
|
||||
}
|
||||
};
|
||||
global::send(resp)
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
global::send(resp)
|
||||
|
Reference in New Issue
Block a user