Compare commits
5 Commits
73d50f3f50
...
a9e5e45872
Author | SHA1 | Date | |
---|---|---|---|
a9e5e45872 | |||
4e6c4ecf38 | |||
ec3c912847 | |||
5636d96478 | |||
fd357ba938 |
@ -5,9 +5,7 @@ import org.springframework.http.HttpStatus;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
||||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
import ovh.herisson.Clyde.Services.*;
|
||||||
import ovh.herisson.Clyde.Services.CurriculumCourseService;
|
|
||||||
import ovh.herisson.Clyde.Services.CurriculumService;
|
|
||||||
import ovh.herisson.Clyde.Tables.Curriculum;
|
import ovh.herisson.Clyde.Tables.Curriculum;
|
||||||
import ovh.herisson.Clyde.Tables.Role;
|
import ovh.herisson.Clyde.Tables.Role;
|
||||||
|
|
||||||
@ -21,11 +19,13 @@ public class CurriculumController {
|
|||||||
private final CurriculumService curriculumServ;
|
private final CurriculumService curriculumServ;
|
||||||
private final AuthenticatorService authServ;
|
private final AuthenticatorService authServ;
|
||||||
|
|
||||||
|
private final UserCurriculumService userCurriculumServ;
|
||||||
private final CurriculumCourseService curriculumCourseServ;
|
private final CurriculumCourseService curriculumCourseServ;
|
||||||
|
|
||||||
public CurriculumController(CurriculumService curriculumServ, AuthenticatorService authServ, CurriculumCourseService curriculumCourseServ){
|
public CurriculumController(CurriculumService curriculumServ, AuthenticatorService authServ, UserCurriculumService userCurriculumServ, CurriculumCourseService curriculumCourseServ){
|
||||||
this.curriculumServ = curriculumServ;
|
this.curriculumServ = curriculumServ;
|
||||||
this.authServ = authServ;
|
this.authServ = authServ;
|
||||||
|
this.userCurriculumServ = userCurriculumServ;
|
||||||
this.curriculumCourseServ = curriculumCourseServ;
|
this.curriculumCourseServ = curriculumCourseServ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,6 +39,19 @@ public class CurriculumController {
|
|||||||
return new ResponseEntity<>(curriculumCourseServ.getDepthCurriculum(foundCurriculum), HttpStatus.OK);
|
return new ResponseEntity<>(curriculumCourseServ.getDepthCurriculum(foundCurriculum), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/curriculum")
|
||||||
|
public ResponseEntity<Map<String ,Object>> findSelfCurriculum(@RequestHeader("Authorization") String token){
|
||||||
|
if (authServ.getUserFromToken(token) == null)
|
||||||
|
return new UnauthorizedResponse<>(null);
|
||||||
|
|
||||||
|
Curriculum curriculum = userCurriculumServ.findByUser(authServ.getUserFromToken(token));
|
||||||
|
|
||||||
|
if (curriculum == null)
|
||||||
|
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||||
|
|
||||||
|
return new ResponseEntity<>(curriculumCourseServ.getDepthCurriculum(curriculum),HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/curriculums")
|
@GetMapping("/curriculums")
|
||||||
public ResponseEntity<Iterable<Map<String, Object>>> findAllIndDepth(){
|
public ResponseEntity<Iterable<Map<String, Object>>> findAllIndDepth(){
|
||||||
return new ResponseEntity<>(curriculumCourseServ.getAllDepthCurriculum(),HttpStatus.OK);
|
return new ResponseEntity<>(curriculumCourseServ.getAllDepthCurriculum(),HttpStatus.OK);
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
package ovh.herisson.Clyde.Repositories;
|
package ovh.herisson.Clyde.Repositories;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
import ovh.herisson.Clyde.Tables.Curriculum;
|
||||||
|
import ovh.herisson.Clyde.Tables.User;
|
||||||
import ovh.herisson.Clyde.Tables.UserCurriculum;
|
import ovh.herisson.Clyde.Tables.UserCurriculum;
|
||||||
|
|
||||||
public interface UserCurriculumRepository extends CrudRepository<UserCurriculum, Long> {
|
public interface UserCurriculumRepository extends CrudRepository<UserCurriculum, Long> {
|
||||||
|
|
||||||
|
@Query("select uc.curriculum from UserCurriculum uc where uc.user = ?1")
|
||||||
|
Curriculum findByUser(User student);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
package ovh.herisson.Clyde.Services;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ovh.herisson.Clyde.Repositories.UserCurriculumRepository;
|
||||||
|
import ovh.herisson.Clyde.Tables.Curriculum;
|
||||||
|
import ovh.herisson.Clyde.Tables.User;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class UserCurriculumService {
|
||||||
|
|
||||||
|
private final UserCurriculumRepository userCurriculumRepository;
|
||||||
|
|
||||||
|
public UserCurriculumService(UserCurriculumRepository userCurriculumRepository) {
|
||||||
|
this.userCurriculumRepository = userCurriculumRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Curriculum findByUser(User student){
|
||||||
|
return userCurriculumRepository.findByUser(student);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user