protected course'owner password

This commit is contained in:
Bartha Maxime 2024-03-17 02:45:49 +01:00
parent 1d793cef4e
commit a70b05a0ef

View File

@ -9,6 +9,8 @@ import ovh.herisson.Clyde.Services.CourseService;
import ovh.herisson.Clyde.Services.TeacherCourseService; import ovh.herisson.Clyde.Services.TeacherCourseService;
import ovh.herisson.Clyde.Tables.Course; import ovh.herisson.Clyde.Tables.Course;
import ovh.herisson.Clyde.Tables.Role; import ovh.herisson.Clyde.Tables.Role;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
@RestController @RestController
@ -28,7 +30,7 @@ public class CourseController {
} }
@GetMapping("/course/{id}") @GetMapping("/course/{id}")
public ResponseEntity<Course> getCourse(@RequestHeader("Authorization") String token, @PathVariable long id){ public ResponseEntity<HashMap<String,Object>> getCourse(@RequestHeader("Authorization") String token, @PathVariable long id){
if (authServ.getUserFromToken(token) == null) if (authServ.getUserFromToken(token) == null)
return new UnauthorizedResponse<>(null); return new UnauthorizedResponse<>(null);
@ -37,7 +39,7 @@ public class CourseController {
if (foundCourse == null) if (foundCourse == null)
return new ResponseEntity<>(HttpStatus.BAD_REQUEST); return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
return new ResponseEntity<>(foundCourse, HttpStatus.OK); return new ResponseEntity<>(courseWithoutPassword(foundCourse), HttpStatus.OK);
} }
@ -85,4 +87,15 @@ public class CourseController {
return new ResponseEntity<>(HttpStatus.OK); return new ResponseEntity<>(HttpStatus.OK);
} }
private HashMap<String,Object> courseWithoutPassword(Course course){
HashMap<String ,Object> toReturn = new HashMap<>();
toReturn.put("courseId",course.getCourseID());
toReturn.put("credits",course.getCredits());
toReturn.put("title", course.getTitle());
toReturn.put("owner", authServ.userWithoutPassword(course.getOwner()));
}
} }