[BE] Model and minimal controllers for Person & Course
This commit is contained in:
parent
a2ad5fde38
commit
a4f46c75cf
18
backend/src/controller/course/mod.rs
Normal file
18
backend/src/controller/course/mod.rs
Normal file
@ -0,0 +1,18 @@
|
||||
use rocket::serde::json::Json;
|
||||
|
||||
use crate::model::course::Course;
|
||||
|
||||
#[get("/course")]
|
||||
pub async fn get_all() -> Json<Vec<Course>> {
|
||||
// TODO: get from database
|
||||
let c = Course {
|
||||
course_id: 1,
|
||||
course_code: 322,
|
||||
course_name: "4x4".to_string(),
|
||||
course_display_name: "Manejo en 4x4 road danger".to_string(),
|
||||
course_days_amount: 2,
|
||||
course_has_custom_label: false,
|
||||
};
|
||||
|
||||
Json(vec![c.clone(), c])
|
||||
}
|
@ -1 +1,2 @@
|
||||
pub mod course;
|
||||
pub mod person;
|
||||
|
@ -1,9 +1,10 @@
|
||||
use rocket::{http::ContentType, serde::json::Json, Response};
|
||||
use rocket::serde::json::Json;
|
||||
|
||||
use crate::model::person::Person;
|
||||
|
||||
#[get("/person/<dni>")]
|
||||
pub async fn get_by_dni(dni: i32) -> Json<Person> {
|
||||
// TODO: get from database
|
||||
Json(Person {
|
||||
person_id: 1,
|
||||
person_dni: format!("{}", dni),
|
||||
|
@ -37,7 +37,8 @@ impl Fairing for Cors {
|
||||
fn rocket() -> _ {
|
||||
rocket::build()
|
||||
.attach(Cors {})
|
||||
.mount("/api", routes![controller::person::get_by_dni])
|
||||
.mount("/api", routes![
|
||||
controller::person::get_by_dni,
|
||||
controller::course::get_all,
|
||||
])
|
||||
}
|
||||
|
||||
|
||||
|
29
backend/src/model/course.rs
Normal file
29
backend/src/model/course.rs
Normal file
@ -0,0 +1,29 @@
|
||||
use rocket::serde::Serialize;
|
||||
|
||||
#[derive(Serialize, Clone)]
|
||||
#[serde(crate = "rocket::serde")]
|
||||
pub struct Course {
|
||||
pub course_id: i32,
|
||||
/// Display code, shown on the certificate.
|
||||
/// Currently a 4-digit number. After 9999, it will be a 4-digit hex number.
|
||||
///
|
||||
/// Example: `0322`
|
||||
pub course_code: i32,
|
||||
/// Internal name, shown in the admin panel
|
||||
///
|
||||
/// Example: `4x4`
|
||||
pub course_name: String,
|
||||
/// Display name, partially shown on the certificate & public page
|
||||
///
|
||||
/// Example: `Manejo en 4x4 road danger`
|
||||
pub course_display_name: String,
|
||||
/// Number of days of the course.
|
||||
/// Used to calculate how to space the courses
|
||||
///
|
||||
/// Example: `2`
|
||||
pub course_days_amount: i32,
|
||||
/// Whether the course name can be extended with a label.
|
||||
/// Used in machinery courses, where the course name is the type of machinery,
|
||||
/// and the custom label the manufacturer and series (i.e. `320D CAT`).
|
||||
pub course_has_custom_label: bool,
|
||||
}
|
@ -1 +1,2 @@
|
||||
pub mod course;
|
||||
pub mod person;
|
||||
|
@ -1,11 +1,24 @@
|
||||
use rocket::serde::Serialize;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[derive(Serialize, Clone)]
|
||||
#[serde(crate = "rocket::serde")]
|
||||
pub struct Person {
|
||||
/// Internal id
|
||||
pub person_id: i32,
|
||||
/// Country-specific id. For now only supports Peru's DNI.
|
||||
///
|
||||
/// Example: `74185293`
|
||||
pub person_dni: String,
|
||||
/// Names
|
||||
///
|
||||
/// Example: `Juan Carlos`
|
||||
pub person_names: String,
|
||||
/// First surname
|
||||
///
|
||||
/// Example: `Perez`
|
||||
pub person_paternal_surname: String,
|
||||
/// Second surname
|
||||
///
|
||||
/// Example: `Gomez`
|
||||
pub person_maternal_surname: String,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user