Skip to content

Commit 310e6aa

Browse files
authored
Merge pull request #10 from LucasWerey/merging_branch
Merging branch
2 parents 4f1380b + 86d9573 commit 310e6aa

File tree

12 files changed

+186
-51
lines changed

12 files changed

+186
-51
lines changed

Api/Readme.md

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,23 @@ pub struct User {
5454
}
5555
```
5656

57-
## User Endpoints
57+
## Student Model
58+
59+
The `Student` model represents a user in the system. Here's the structure of the `Student` model:
60+
61+
```rust
62+
pub struct Students {
63+
pub user_id: Option<ObjectId>, // The student id linked to user ID
64+
pub duree: i32, // The duration of the stage/internship
65+
pub niveau: String, // The graduation level
66+
pub type_contrat: String, // Type of contract
67+
pub date_debut: BsonDateTime, // Date of start
68+
pub lieu: String, // Place of stage
69+
pub recherche: bool, // Currently looking for ?
70+
}
71+
```
72+
73+
## Endpoints
5874

5975
### Create User - `POST /user`
6076

@@ -71,43 +87,51 @@ curl -X POST -H "Content-Type: application/json" -d '{
7187
}' http://127.0.0.1:8000/user
7288
```
7389

74-
curl -X POST -H "Content-Type: application/json" -d '{
75-
"duree":5,
76-
"niveau": "BAC+5",
77-
"type_contrat": "alternance",
78-
"date_debut": {
79-
"$date": {"$numberLong": "1644566400000"}
80-
},
81-
"lieu": "Paris",
82-
"recherche": true
83-
84-
}' http://127.0.0.1:8000/student
90+
> To create a student statut must be set to "student"
8591
86-
### Get All Users - `GET /users`
92+
### Get queries
8793

8894
Returns a list of all users in the system. No request body is required for this endpoint.
8995

90-
Example:
96+
Examples:
97+
98+
#### Get All Users - `GET /users`
9199

92100
```bash
93101
curl -X GET http://127.0.0.1:8000/users
94102
```
95103

96-
### Get User - `GET /user/<id>`
104+
#### Get All Students - `GET /students`
105+
106+
```bash
107+
curl -X GET http://127.0.0.1:8000/students
108+
```
109+
110+
### Get queries
97111

98112
Returns the details of a specific user. Replace `<id>` with the ID of the user you want to retrieve. No request body is required for this endpoint.
99113

100-
Example:
114+
Examples:
115+
116+
#### Get User - `GET /user/<id>`
101117

102118
```bash
103119
curl -X GET http://127.0.0.1:8000/user/<id>
104120
```
105121

106-
### Update User - `PUT /user/<id>`
122+
#### Get Student - `GET /student/<id>`
123+
124+
```bash
125+
curl -X GET http://127.0.0.1:8000/student/<id>
126+
```
127+
128+
### Update queries
107129

108130
Updates the details of a specific user. Replace `<id>` with the ID of the user you want to update. The request body should be a JSON object with the fields to update.
109131

110-
Example:
132+
Examples:
133+
134+
#### Update User - `PUT /user/<id>`
111135

112136
```bash
113137
curl -X PUT -H "Content-Type: application/json" -d '{
@@ -119,6 +143,9 @@ curl -X PUT -H "Content-Type: application/json" -d '{
119143
}' http://127.0.0.1:8000/user/<id>
120144
```
121145

146+
#### Update Student - `PUT /student/<id>`
147+
148+
```bash
122149
curl -X PUT -H "Content-Type: application/json" -d '{
123150
"duree":4,
124151
"niveau": "BAC+4",
@@ -131,18 +158,27 @@ curl -X PUT -H "Content-Type: application/json" -d '{
131158
"lieu": "Paris",
132159
"recherche": false
133160
134-
}' http://127.0.0.1:8000/student/65a17960c47012ed8f140bfe
161+
}' http://127.0.0.1:8000/student/65a2c1f81cb256b4957fee3c
162+
```
135163

136-
### Delete User - `DELETE /user/<id>`
164+
### Delete queries
137165

138166
Deletes a specific user. Replace `<id>` with the ID of the user you want to delete. No request body is required for this endpoint.
139167

140-
Example:
168+
Examples:
169+
170+
#### Delete User - `DELETE /user/<id>`
141171

142172
```bash
143173
curl -X DELETE http://127.0.0.1:8000/user/<id>
144174
```
145175

176+
#### Delete Student - `DELETE /student/<id>`
177+
178+
```bash
179+
curl -X DELETE http://127.0.0.1:8000/student/<id>
180+
```
181+
146182
### Login - `POST /login`
147183

148184
Logs in a user. The request body should be a JSON object with the following properties:

Api/src/api/students_api.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,22 @@
1-
use crate::{models::students_model::Students, models::user_model::User, repository::mongodb_repo::MongoRepo};
1+
use crate::{models::students_model::Students, repository::mongodb_repo::MongoRepo};
22
use mongodb::{bson::oid::ObjectId, results::InsertOneResult};
33
use rocket::{http::Status, serde::json::Json, State};
4-
use bcrypt::{hash, DEFAULT_COST};
5-
use bcrypt::verify;
6-
use jsonwebtoken::{encode, EncodingKey, Header, Algorithm};
7-
use std::collections::BTreeMap;
8-
use rocket::serde::Serialize;
9-
use rocket::serde::Deserialize;
10-
use chrono::{Utc, Duration};
11-
use std::env;
12-
use dotenv::dotenv;
13-
use mongodb::bson::DateTime as BsonDateTime;
4+
145

156
#[post("/student", data = "<new_students>")]
167
pub fn create_students(
178
db: &State<MongoRepo>,
189
new_students: Json<Students>,
1910
) -> Result<Json<InsertOneResult>, Status> {
2011
let data = Students {
21-
id: None,
12+
user_id: new_students.user_id,
2213
duree: new_students.duree,
2314
niveau: new_students.niveau.to_owned(),
2415
type_contrat: new_students.type_contrat.to_owned(),
2516
date_debut: new_students.date_debut,
2617
lieu: new_students.lieu.to_owned(),
2718
recherche: new_students.recherche,
28-
19+
2920
};
3021
let students_detail = db.create_students(data);
3122
match students_detail {
@@ -59,7 +50,7 @@ pub fn update_students(
5950
return Err(Status::BadRequest);
6051
};
6152
let data = Students {
62-
id: Some(ObjectId::parse_str(&id).unwrap()),
53+
user_id: Some(ObjectId::parse_str(&id).unwrap()),
6354
duree: new_students.duree,
6455
niveau: new_students.niveau.to_owned(),
6556
type_contrat: new_students.type_contrat.to_owned(),

Api/src/api/user_api.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,21 @@ pub fn create_user(
3737
statut: new_user.statut.to_owned(),
3838
date: Some(BsonDateTime::from_millis(Utc::now().timestamp_millis())),
3939
};
40-
let user_clone = data.clone();
40+
let user_clone = data.clone();
4141
let user_detail = db.create_user(user_clone);
4242
match user_detail {
4343
Ok(user) =>{
4444
if data.statut == "student" {
4545
let student_data = Students {
46-
id: data.id.as_ref().map(|id| id).copied(), // Utilisez le même ID que l'utilisateur
47-
duree: 0, // Vous devez définir une valeur par défaut ou récupérer cette information ailleurs
46+
user_id: Some(user.inserted_id.as_object_id().unwrap().clone()), // Use the same ID as the user
47+
duree: 0, // You need to set a default value or get this information from somewhere else
4848
niveau: String::new(),
4949
type_contrat: String::new(),
5050
date_debut: BsonDateTime::now(),
5151
lieu: String::new(),
5252
recherche: false,
5353
};
54-
55-
// Créez l'étudiant
54+
5655
let _ = db.create_students(student_data);
5756
}
5857
Ok(Json(user))

Api/src/models/students_model.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ use mongodb::bson::DateTime as BsonDateTime;
77
#[derive(Debug, Serialize, Deserialize)]
88
pub struct Students {
99
#[serde(rename = "_id", skip_serializing_if = "Option::is_none")]
10-
pub id: Option<ObjectId>,
10+
pub user_id: Option<ObjectId>,
1111
pub duree: i32,
1212
pub niveau: String,
1313
pub type_contrat: String,
1414
pub date_debut: BsonDateTime,
1515
pub lieu: String,
16-
pub recherche: bool,
16+
pub recherche: bool,
1717
}
1818

1919

Api/src/repository/mongodb_repo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,14 @@ pub struct MongoRepo {
115115

116116
pub fn create_students(&self, new_students: Students) -> Result<InsertOneResult, Error> {
117117
let new_doc = Students {
118-
id: None,
118+
user_id: new_students.user_id,
119119
duree: new_students.duree,
120120
niveau: new_students.niveau,
121121
type_contrat: new_students.type_contrat,
122122
date_debut: new_students.date_debut,
123123
lieu: new_students.lieu,
124124
recherche: new_students.recherche
125-
125+
126126
};
127127
let students = self
128128
.col2

Front/src/auto-imports.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ declare global {
3939
const createReactiveFn: typeof import('@vueuse/core')['createReactiveFn']
4040
const createReusableTemplate: typeof import('@vueuse/core')['createReusableTemplate']
4141
const createSharedComposable: typeof import('@vueuse/core')['createSharedComposable']
42+
const createStudent: typeof import('./utils/studentApiUtils')['createStudent']
4243
const createTemplatePromise: typeof import('@vueuse/core')['createTemplatePromise']
4344
const createUnrefFn: typeof import('@vueuse/core')['createUnrefFn']
4445
const createUser: typeof import('./utils/userApiUtils')['createUser']
@@ -48,6 +49,7 @@ declare global {
4849
const defineAsyncComponent: typeof import('vue')['defineAsyncComponent']
4950
const defineComponent: typeof import('vue')['defineComponent']
5051
const defineStore: typeof import('pinia')['defineStore']
52+
const deleteStudent: typeof import('./utils/studentApiUtils')['deleteStudent']
5153
const deleteUser: typeof import('./utils/userApiUtils')['deleteUser']
5254
const describe: typeof import('vitest')['describe']
5355
const difference: typeof import('./utils/arrayUtils')['difference']
@@ -57,12 +59,14 @@ declare global {
5759
const expect: typeof import('vitest')['expect']
5860
const extendRef: typeof import('@vueuse/core')['extendRef']
5961
const getActivePinia: typeof import('pinia')['getActivePinia']
62+
const getAllStudents: typeof import('./utils/studentApiUtils')['getAllStudents']
6063
const getAllUsers: typeof import('./utils/userApiUtils')['getAllUsers']
6164
const getCurrentInstance: typeof import('vue')['getCurrentInstance']
6265
const getCurrentScope: typeof import('vue')['getCurrentScope']
6366
const getLocalStorage: typeof import('./utils/storageUtils')['getLocalStorage']
6467
const getQueryParameter: typeof import('./utils/getQueryRouteUtils')['getQueryParameter']
6568
const getSessionStorage: typeof import('./utils/storageUtils')['getSessionStorage']
69+
const getStudent: typeof import('./utils/studentApiUtils')['getStudent']
6670
const getUser: typeof import('./utils/userApiUtils')['getUser']
6771
const h: typeof import('vue')['h']
6872
const handleApiError: typeof import('./utils/apiErrorUtils')['handleApiError']
@@ -167,6 +171,7 @@ declare global {
167171
const unref: typeof import('vue')['unref']
168172
const unrefElement: typeof import('@vueuse/core')['unrefElement']
169173
const until: typeof import('@vueuse/core')['until']
174+
const updateStudent: typeof import('./utils/studentApiUtils')['updateStudent']
170175
const updateUser: typeof import('./utils/userApiUtils')['updateUser']
171176
const useActiveElement: typeof import('@vueuse/core')['useActiveElement']
172177
const useAnimate: typeof import('@vueuse/core')['useAnimate']
@@ -395,6 +400,7 @@ declare module 'vue' {
395400
readonly createReactiveFn: UnwrapRef<typeof import('@vueuse/core')['createReactiveFn']>
396401
readonly createReusableTemplate: UnwrapRef<typeof import('@vueuse/core')['createReusableTemplate']>
397402
readonly createSharedComposable: UnwrapRef<typeof import('@vueuse/core')['createSharedComposable']>
403+
readonly createStudent: UnwrapRef<typeof import('./utils/studentApiUtils')['createStudent']>
398404
readonly createTemplatePromise: UnwrapRef<typeof import('@vueuse/core')['createTemplatePromise']>
399405
readonly createUnrefFn: UnwrapRef<typeof import('@vueuse/core')['createUnrefFn']>
400406
readonly createUser: UnwrapRef<typeof import('./utils/userApiUtils')['createUser']>
@@ -404,6 +410,7 @@ declare module 'vue' {
404410
readonly defineAsyncComponent: UnwrapRef<typeof import('vue')['defineAsyncComponent']>
405411
readonly defineComponent: UnwrapRef<typeof import('vue')['defineComponent']>
406412
readonly defineStore: UnwrapRef<typeof import('pinia')['defineStore']>
413+
readonly deleteStudent: UnwrapRef<typeof import('./utils/studentApiUtils')['deleteStudent']>
407414
readonly deleteUser: UnwrapRef<typeof import('./utils/userApiUtils')['deleteUser']>
408415
readonly describe: UnwrapRef<typeof import('vitest')['describe']>
409416
readonly difference: UnwrapRef<typeof import('./utils/arrayUtils')['difference']>
@@ -413,12 +420,14 @@ declare module 'vue' {
413420
readonly expect: UnwrapRef<typeof import('vitest')['expect']>
414421
readonly extendRef: UnwrapRef<typeof import('@vueuse/core')['extendRef']>
415422
readonly getActivePinia: UnwrapRef<typeof import('pinia')['getActivePinia']>
423+
readonly getAllStudents: UnwrapRef<typeof import('./utils/studentApiUtils')['getAllStudents']>
416424
readonly getAllUsers: UnwrapRef<typeof import('./utils/userApiUtils')['getAllUsers']>
417425
readonly getCurrentInstance: UnwrapRef<typeof import('vue')['getCurrentInstance']>
418426
readonly getCurrentScope: UnwrapRef<typeof import('vue')['getCurrentScope']>
419427
readonly getLocalStorage: UnwrapRef<typeof import('./utils/storageUtils')['getLocalStorage']>
420428
readonly getQueryParameter: UnwrapRef<typeof import('./utils/getQueryRouteUtils')['getQueryParameter']>
421429
readonly getSessionStorage: UnwrapRef<typeof import('./utils/storageUtils')['getSessionStorage']>
430+
readonly getStudent: UnwrapRef<typeof import('./utils/studentApiUtils')['getStudent']>
422431
readonly getUser: UnwrapRef<typeof import('./utils/userApiUtils')['getUser']>
423432
readonly h: UnwrapRef<typeof import('vue')['h']>
424433
readonly handleApiError: UnwrapRef<typeof import('./utils/apiErrorUtils')['handleApiError']>
@@ -519,6 +528,7 @@ declare module 'vue' {
519528
readonly unref: UnwrapRef<typeof import('vue')['unref']>
520529
readonly unrefElement: UnwrapRef<typeof import('@vueuse/core')['unrefElement']>
521530
readonly until: UnwrapRef<typeof import('@vueuse/core')['until']>
531+
readonly updateStudent: UnwrapRef<typeof import('./utils/studentApiUtils')['updateStudent']>
522532
readonly updateUser: UnwrapRef<typeof import('./utils/userApiUtils')['updateUser']>
523533
readonly useActiveElement: UnwrapRef<typeof import('@vueuse/core')['useActiveElement']>
524534
readonly useAnimate: UnwrapRef<typeof import('@vueuse/core')['useAnimate']>
@@ -739,6 +749,7 @@ declare module '@vue/runtime-core' {
739749
readonly createReactiveFn: UnwrapRef<typeof import('@vueuse/core')['createReactiveFn']>
740750
readonly createReusableTemplate: UnwrapRef<typeof import('@vueuse/core')['createReusableTemplate']>
741751
readonly createSharedComposable: UnwrapRef<typeof import('@vueuse/core')['createSharedComposable']>
752+
readonly createStudent: UnwrapRef<typeof import('./utils/studentApiUtils')['createStudent']>
742753
readonly createTemplatePromise: UnwrapRef<typeof import('@vueuse/core')['createTemplatePromise']>
743754
readonly createUnrefFn: UnwrapRef<typeof import('@vueuse/core')['createUnrefFn']>
744755
readonly createUser: UnwrapRef<typeof import('./utils/userApiUtils')['createUser']>
@@ -748,6 +759,7 @@ declare module '@vue/runtime-core' {
748759
readonly defineAsyncComponent: UnwrapRef<typeof import('vue')['defineAsyncComponent']>
749760
readonly defineComponent: UnwrapRef<typeof import('vue')['defineComponent']>
750761
readonly defineStore: UnwrapRef<typeof import('pinia')['defineStore']>
762+
readonly deleteStudent: UnwrapRef<typeof import('./utils/studentApiUtils')['deleteStudent']>
751763
readonly deleteUser: UnwrapRef<typeof import('./utils/userApiUtils')['deleteUser']>
752764
readonly describe: UnwrapRef<typeof import('vitest')['describe']>
753765
readonly difference: UnwrapRef<typeof import('./utils/arrayUtils')['difference']>
@@ -757,12 +769,14 @@ declare module '@vue/runtime-core' {
757769
readonly expect: UnwrapRef<typeof import('vitest')['expect']>
758770
readonly extendRef: UnwrapRef<typeof import('@vueuse/core')['extendRef']>
759771
readonly getActivePinia: UnwrapRef<typeof import('pinia')['getActivePinia']>
772+
readonly getAllStudents: UnwrapRef<typeof import('./utils/studentApiUtils')['getAllStudents']>
760773
readonly getAllUsers: UnwrapRef<typeof import('./utils/userApiUtils')['getAllUsers']>
761774
readonly getCurrentInstance: UnwrapRef<typeof import('vue')['getCurrentInstance']>
762775
readonly getCurrentScope: UnwrapRef<typeof import('vue')['getCurrentScope']>
763776
readonly getLocalStorage: UnwrapRef<typeof import('./utils/storageUtils')['getLocalStorage']>
764777
readonly getQueryParameter: UnwrapRef<typeof import('./utils/getQueryRouteUtils')['getQueryParameter']>
765778
readonly getSessionStorage: UnwrapRef<typeof import('./utils/storageUtils')['getSessionStorage']>
779+
readonly getStudent: UnwrapRef<typeof import('./utils/studentApiUtils')['getStudent']>
766780
readonly getUser: UnwrapRef<typeof import('./utils/userApiUtils')['getUser']>
767781
readonly h: UnwrapRef<typeof import('vue')['h']>
768782
readonly handleApiError: UnwrapRef<typeof import('./utils/apiErrorUtils')['handleApiError']>
@@ -863,6 +877,7 @@ declare module '@vue/runtime-core' {
863877
readonly unref: UnwrapRef<typeof import('vue')['unref']>
864878
readonly unrefElement: UnwrapRef<typeof import('@vueuse/core')['unrefElement']>
865879
readonly until: UnwrapRef<typeof import('@vueuse/core')['until']>
880+
readonly updateStudent: UnwrapRef<typeof import('./utils/studentApiUtils')['updateStudent']>
866881
readonly updateUser: UnwrapRef<typeof import('./utils/userApiUtils')['updateUser']>
867882
readonly useActiveElement: UnwrapRef<typeof import('@vueuse/core')['useActiveElement']>
868883
readonly useAnimate: UnwrapRef<typeof import('@vueuse/core')['useAnimate']>

Front/src/components/signUp/StudentSignup.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@ const handleSubmit = () => {
4848
}
4949
}
5050
51+
const response = ref(null)
52+
onMounted(async () => {
53+
try {
54+
response.value = await createUser({
55+
firstname: 'Firezazaezaest Student',
56+
lastname: 'Last Student',
57+
email: 'user@example.com',
58+
password: 'password',
59+
statut: 'student'
60+
})
61+
console.log(response.value)
62+
} catch (error) {
63+
const apiError = handleApiError(error)
64+
console.log(apiError)
65+
}
66+
})
67+
5168
const goBack = () => {
5269
if (store.step === 1) router.push('/')
5370
if (store.step > 1) store.prevStep()

Front/src/stores/studentRegistration.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ export const useRegistrationStore = defineStore({
77
form1: {
88
email: '',
99
password: '',
10-
keepLogged: false
10+
keepLogged: false,
11+
userType: 'Student'
1112
},
1213
form2: {
1314
name: '',
1415
firstname: '',
1516
schoolGrade: '',
1617
contractType: 'stage',
17-
duration: '',
18+
duration: 0,
1819
start: new Date(),
1920
location: '',
2021
actualLookingFor: false

0 commit comments

Comments
 (0)