[Classroom][BE] Include classroom_username in the person entity.
This commit is contained in:
parent
d49cda6e4e
commit
2dc1b6ba59
@ -11,9 +11,14 @@ CREATE TABLE person (
|
||||
person_names VARCHAR(50) NOT NULL,
|
||||
person_paternal_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 (
|
||||
course_id INTEGER PRIMARY KEY AUTO_INCREMENT,
|
||||
course_name VARCHAR(50) NOT NULL,
|
||||
|
@ -118,6 +118,7 @@ pub async fn get_by_dni(dni: i32) -> (Status, Json<JsonResult<Person>>) {
|
||||
person_paternal_surname: p.apellidoPaterno,
|
||||
person_maternal_surname: p.apellidoMaterno,
|
||||
person_classroom_id: None,
|
||||
person_classroom_username: None,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ pub struct Person {
|
||||
pub person_maternal_surname: String,
|
||||
/// Id of the online classroom user id linked to this user
|
||||
pub person_classroom_id: Option<i32>,
|
||||
pub person_classroom_username: Option<String>,
|
||||
}
|
||||
|
||||
impl Person {
|
||||
@ -68,6 +69,7 @@ impl PersonCreate {
|
||||
pub struct PersonLink {
|
||||
pub person_id: i32,
|
||||
pub person_classroom_id: i32,
|
||||
pub person_classroom_username: String,
|
||||
}
|
||||
|
||||
impl PersonLink {
|
||||
@ -75,8 +77,9 @@ impl PersonLink {
|
||||
let db = db();
|
||||
|
||||
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_username,
|
||||
self.person_id,
|
||||
)
|
||||
.execute(db)
|
||||
|
@ -38,6 +38,7 @@ pub async fn create(data: &ClassroomPersonCreate) -> Result<PersonLink, String>
|
||||
let person_link = PersonLink {
|
||||
person_id: data.person_id,
|
||||
person_classroom_id: user_id,
|
||||
person_classroom_username: data.person_username.clone(),
|
||||
};
|
||||
let result = person_link.insert().await;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user