Compare commits
No commits in common. "f2507ddcdd6b05d34b5e7f30615b80a4ad8e5c41" and "c5d7ce41785be4156a3fbbbdd7a36fc11bc357b8" have entirely different histories.
f2507ddcdd
...
c5d7ce4178
@ -9,8 +9,6 @@ import ovh.herisson.Clyde.Services.CourseService;
|
||||
import ovh.herisson.Clyde.Services.TeacherCourseService;
|
||||
import ovh.herisson.Clyde.Tables.Course;
|
||||
import ovh.herisson.Clyde.Tables.Role;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@ -30,7 +28,7 @@ public class CourseController {
|
||||
}
|
||||
|
||||
@GetMapping("/course/{id}")
|
||||
public ResponseEntity<HashMap<String,Object>> getCourse(@RequestHeader("Authorization") String token, @PathVariable long id){
|
||||
public ResponseEntity<Course> getCourse(@RequestHeader("Authorization") String token, @PathVariable long id){
|
||||
if (authServ.getUserFromToken(token) == null)
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
@ -39,7 +37,7 @@ public class CourseController {
|
||||
if (foundCourse == null)
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
return new ResponseEntity<>(courseWithoutPassword(foundCourse), HttpStatus.OK);
|
||||
return new ResponseEntity<>(foundCourse, HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@ -87,16 +85,4 @@ public class CourseController {
|
||||
|
||||
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()));
|
||||
return toReturn;
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public class UserController {
|
||||
User user = authServ.getUserFromToken(token);
|
||||
if (user == null) return new UnauthorizedResponse<>(null);
|
||||
|
||||
return new ResponseEntity<>(authServ.userWithoutPassword(user), HttpStatus.OK);
|
||||
return new ResponseEntity<>(userWithoutPassword(user), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/user")
|
||||
@ -44,7 +44,7 @@ public class UserController {
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService,Role.Secretary},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
return new ResponseEntity<>(authServ.userWithoutPassword(userService.save(user)),HttpStatus.CREATED);
|
||||
return new ResponseEntity<>(userWithoutPassword(userService.save(user)),HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@GetMapping("/users")
|
||||
@ -57,7 +57,7 @@ public class UserController {
|
||||
ArrayList<HashMap<String, Object>> withoutPassword = new ArrayList<>();
|
||||
|
||||
for (User u :users){
|
||||
withoutPassword.add(authServ.userWithoutPassword(u));
|
||||
withoutPassword.add(userWithoutPassword(u));
|
||||
}
|
||||
return new ResponseEntity<>(withoutPassword, HttpStatus.OK);
|
||||
}
|
||||
@ -95,10 +95,30 @@ public class UserController {
|
||||
ArrayList<HashMap<String, Object>> withoutPassword = new ArrayList<>();
|
||||
|
||||
for (User t: teachers){
|
||||
withoutPassword.add(authServ.userWithoutPassword(t));
|
||||
withoutPassword.add(userWithoutPassword(t));
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(withoutPassword, HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** return user's data except password
|
||||
* @param user the user to return
|
||||
* @return all the user data without the password
|
||||
*/
|
||||
private HashMap<String,Object> userWithoutPassword(User user){
|
||||
HashMap<String,Object> toReturn = new HashMap<>();
|
||||
toReturn.put("regNo",user.getRegNo());
|
||||
toReturn.put("lastName",user.getLastName());
|
||||
toReturn.put("firstName",user.getFirstName());
|
||||
toReturn.put("email", user.getEmail());
|
||||
toReturn.put("address",user.getAddress());
|
||||
toReturn.put("birthDate",user.getBirthDate());
|
||||
toReturn.put("country",user.getCountry());
|
||||
toReturn.put("profilePictureUrl",user.getProfilePictureUrl());
|
||||
toReturn.put("role",user.getRole());
|
||||
return toReturn;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@ import ovh.herisson.Clyde.Tables.Token;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
@Service
|
||||
public class AuthenticatorService {
|
||||
@ -53,25 +52,5 @@ public class AuthenticatorService {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** return user's data except password
|
||||
* @param user the user to return
|
||||
* @return all the user data without the password
|
||||
*/
|
||||
public HashMap<String,Object> userWithoutPassword(User user){
|
||||
HashMap<String,Object> toReturn = new HashMap<>();
|
||||
toReturn.put("regNo",user.getRegNo());
|
||||
toReturn.put("lastName",user.getLastName());
|
||||
toReturn.put("firstName",user.getFirstName());
|
||||
toReturn.put("email", user.getEmail());
|
||||
toReturn.put("address",user.getAddress());
|
||||
toReturn.put("birthDate",user.getBirthDate());
|
||||
toReturn.put("country",user.getCountry());
|
||||
toReturn.put("profilePictureUrl",user.getProfilePictureUrl());
|
||||
toReturn.put("role",user.getRole());
|
||||
return toReturn;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user