Redo endpoints to get all data at once

This commit is contained in:
Ethan O'Brien
2026-05-04 12:35:22 -05:00
parent 902fbaec55
commit f7611937cc
8 changed files with 57 additions and 38 deletions

View File

@@ -1,20 +1,16 @@
use actix_web::{web, HttpRequest, HttpResponse, Responder};
use crate::router::databases::csv::{self, Region};
use actix_web::http::header::ContentType;
use crate::router::databases::csv::{get_all, Region};
pub fn routes(cfg: &mut web::ServiceConfig) {
cfg.service(
web::scope("/masterdata")
.route("/supported", web::get().to(supported))
.service(
web::scope("/{platform}/{LANG}")
.route("/{MST}", web::get().to(mst))
)
.route("/{platform}/{LANG}", web::get().to(mst))
);
}
async fn mst(req: HttpRequest) -> impl Responder {
let mst_name = req.match_info().get("MST").unwrap();
let lang = req.match_info().get("LANG").unwrap_or("JP");
let region = match lang.to_ascii_uppercase().as_str() {
@@ -22,13 +18,12 @@ async fn mst(req: HttpRequest) -> impl Responder {
_ => Region::En, // idk
};
match csv::csv_bytes(region, mst_name) {
Some(body) => HttpResponse::Ok()
.insert_header(("content-type", "text/csv; charset=utf-8"))
.insert_header(("content-length", body.len()))
.body(body),
None => HttpResponse::NotFound().finish(),
}
let body = get_all(region);
let body = jzon::stringify(body);
HttpResponse::Ok()
.insert_header(("content-type", ContentType::json()))
.insert_header(("content-length", body.len()))
.body(body)
}
async fn supported() -> impl Responder {