[Classroom][BE] Include classroom_username in the person entity.

This commit is contained in:
Araozu 2023-10-05 11:25:23 -05:00
parent d49cda6e4e
commit 2dc1b6ba59
4 changed files with 12 additions and 2 deletions

View File

@ -11,9 +11,14 @@ CREATE TABLE person (
person_names VARCHAR(50) NOT NULL, person_names VARCHAR(50) NOT NULL,
person_paternal_surname VARCHAR(30) NOT NULL, person_paternal_surname VARCHAR(30) NOT NULL,
person_maternal_surname VARCHAR(30) NOT NULL, person_maternal_surname VARCHAR(30) NOT NULL,
person_classroom_id INTEGER DEFAULT -1 person_classroom_id INTEGER DEFAULT -1,
person_classroom_username VARCHAR(30) NULL DEFAULT NULL,
); );
-- Add person_classroom_username
ALTER TABLE `person` ADD `person_classroom_username` VARCHAR(30) NULL DEFAULT NULL AFTER `person_classroom_id`;
CREATE TABLE course ( CREATE TABLE course (
course_id INTEGER PRIMARY KEY AUTO_INCREMENT, course_id INTEGER PRIMARY KEY AUTO_INCREMENT,
course_name VARCHAR(50) NOT NULL, course_name VARCHAR(50) NOT NULL,

View File

@ -118,6 +118,7 @@ pub async fn get_by_dni(dni: i32) -> (Status, Json<JsonResult<Person>>) {
person_paternal_surname: p.apellidoPaterno, person_paternal_surname: p.apellidoPaterno,
person_maternal_surname: p.apellidoMaterno, person_maternal_surname: p.apellidoMaterno,
person_classroom_id: None, person_classroom_id: None,
person_classroom_username: None,
}), }),
); );
} }

View File

@ -24,6 +24,7 @@ pub struct Person {
pub person_maternal_surname: String, pub person_maternal_surname: String,
/// Id of the online classroom user id linked to this user /// Id of the online classroom user id linked to this user
pub person_classroom_id: Option<i32>, pub person_classroom_id: Option<i32>,
pub person_classroom_username: Option<String>,
} }
impl Person { impl Person {
@ -68,6 +69,7 @@ impl PersonCreate {
pub struct PersonLink { pub struct PersonLink {
pub person_id: i32, pub person_id: i32,
pub person_classroom_id: i32, pub person_classroom_id: i32,
pub person_classroom_username: String,
} }
impl PersonLink { impl PersonLink {
@ -75,8 +77,9 @@ impl PersonLink {
let db = db(); let db = db();
let res = sqlx::query!( let res = sqlx::query!(
"UPDATE person SET person_classroom_id = ? WHERE person_id = ?", "UPDATE person SET person_classroom_id = ?, person_classroom_username = ? WHERE person_id = ?",
self.person_classroom_id, self.person_classroom_id,
self.person_classroom_username,
self.person_id, self.person_id,
) )
.execute(db) .execute(db)

View File

@ -38,6 +38,7 @@ pub async fn create(data: &ClassroomPersonCreate) -> Result<PersonLink, String>
let person_link = PersonLink { let person_link = PersonLink {
person_id: data.person_id, person_id: data.person_id,
person_classroom_id: user_id, person_classroom_id: user_id,
person_classroom_username: data.person_username.clone(),
}; };
let result = person_link.insert().await; let result = person_link.insert().await;