Refactor part 1

{{url}}/api/v1/courses/getCourses =>  {{url}}/api/v1/courses/all
{{url}}/api/v1/groups/getCourseGroups?id=13 => {{url}}/api/v1/groups/course/13
{{url}}/api/v1/courses/getCoursesWithGroups => {{url}}/api/v1/courses/all?groups=true
{{url}}/api/v1/commisions/add => {{url}}/api/v1/commisions/user
{{url}}/api/v1/commisions/getAllCommisions => {{url}}/api/v1/commisions/user
{{url}}/api/v1/assignments/getCurrentAssignments =>{{url}}/api/v1/assignments/user
{{url}}/api/v1/users/searchForStudents => {{url}}/api/v1/users/search

Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
Marcin Woźniak 2020-10-30 16:42:57 +01:00
parent 4267fadf62
commit 2b59c181e5
6 changed files with 20 additions and 20 deletions

View File

@ -32,7 +32,7 @@ public class AssignmentsController extends TokenBasedController {
@Autowired @Autowired
private AssignmentService assignmentService; private AssignmentService assignmentService;
@GetMapping("/getCurrentAssignments") @GetMapping("/user")
public ResponseEntity<List<GetCurrentAssignmentsResponse>> getCurrentAssignments() throws Exception { public ResponseEntity<List<GetCurrentAssignmentsResponse>> getCurrentAssignments() throws Exception {
User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException("User not found")); User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException("User not found"));
Optional<Commision> com = this.commisionService.getNewestCommision(user); Optional<Commision> com = this.commisionService.getNewestCommision(user);

View File

@ -42,7 +42,7 @@ public class CommisionController extends TokenBasedController {
public CommisionController() { public CommisionController() {
} }
@PostMapping("/add") @PostMapping("/user")
public ResponseEntity<String> addCommision(@RequestBody List<Long> groups) throws UserNotFoundException { public ResponseEntity<String> addCommision(@RequestBody List<Long> groups) throws UserNotFoundException {
User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException()); User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException());
@ -58,7 +58,7 @@ public class CommisionController extends TokenBasedController {
return new ResponseEntity<>("Succes", HttpStatus.OK); return new ResponseEntity<>("Succes", HttpStatus.OK);
} }
@GetMapping("/getAllCommisions") @GetMapping("/user")
public ResponseEntity<List<CommisionResponse>> getAlCommisions() throws UserNotFoundException { public ResponseEntity<List<CommisionResponse>> getAlCommisions() throws UserNotFoundException {
User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException()); User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException());
List<CommisionResponse> result = CommisionResponseMappers List<CommisionResponse> result = CommisionResponseMappers

View File

@ -16,6 +16,8 @@ import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.plannaplan.responses.models.abstracts.CoursesResponse;
@RestController @RestController
@CrossOrigin @CrossOrigin
@ -24,20 +26,15 @@ public class CoursesController {
@Autowired @Autowired
private CourseService courseService; private CourseService courseService;
@GetMapping("/getCourses") @GetMapping("/all")
public ResponseEntity<List<GetCoursesResponse>> getMethodName() { public ResponseEntity<List<? extends CoursesResponse>> getMethodName(@RequestParam(name = "groups", defaultValue = "false") Boolean groups) {
List<Course> courses = this.courseService.getAllCourses(); List<Course> courses = this.courseService.getAllCourses();
List<GetCoursesResponse> response = CoursesResponseMappers.mapToGetCoursesResponse(courses); if (groups) {
return new ResponseEntity<>(response, HttpStatus.OK);
}
@GetMapping("/getCoursesWithGroups")
public ResponseEntity<List<GetCoursesWithGroupsResponse>> getCoursesWithGroups() {
final List<Course> courses = this.courseService.getAllCourses();
final List<GetCoursesWithGroupsResponse> response = CoursesResponseMappers final List<GetCoursesWithGroupsResponse> response = CoursesResponseMappers
.mapToGetCoursesWithGroupsResponse(courses); .mapToGetCoursesWithGroupsResponse(courses);
return new ResponseEntity<>(response, HttpStatus.OK); return new ResponseEntity<>(response, HttpStatus.OK);
} }
final List<GetCoursesResponse> response = CoursesResponseMappers.mapToGetCoursesResponse(courses);
return new ResponseEntity<>(response, HttpStatus.OK);
}
} }

View File

@ -14,19 +14,22 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@CrossOrigin @CrossOrigin
@RequestMapping("/api/" + App.API_VERSION + "/groups") @RequestMapping("/api/" + App.API_VERSION + "/groups")
public class GroupController { public class GroupController {
@Autowired @Autowired
private GroupService groupService; private GroupService groupService;
@GetMapping("/getCourseGroups") @GetMapping("/course/{id}")
public ResponseEntity<GetCourseGroupsResponse<? extends DefaultGroupResponse>> getCourses(@RequestParam("id") Long id,
public ResponseEntity<GetCourseGroupsResponse<? extends DefaultGroupResponse>> getCourses(@PathVariable(name = "id") Long id,
@RequestParam(name = "capacity", defaultValue = "true") Boolean capacity) { @RequestParam(name = "capacity", defaultValue = "true") Boolean capacity) {
List<Groups> groups = this.groupService.getGroupsByCourse(id); List<Groups> groups = this.groupService.getGroupsByCourse(id);
if (capacity) { if (capacity) {

View File

@ -27,7 +27,7 @@ public class UsersController {
@Autowired @Autowired
private UserService userService; private UserService userService;
@GetMapping("/searchForStudents") @GetMapping("/search")
@PreAuthorize("hasRole('ROLE_DEANERY')") @PreAuthorize("hasRole('ROLE_DEANERY')")
public ResponseEntity<List<SearchForStudentsResponse>> configApp(@RequestParam("query") String query) { public ResponseEntity<List<SearchForStudentsResponse>> configApp(@RequestParam("query") String query) {

View File

@ -36,8 +36,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override @Override
public void configure(final WebSecurity webSecurity) { public void configure(final WebSecurity webSecurity) {
webSecurity.ignoring().antMatchers("/token**").antMatchers("/api/v1/courses/getCourses") webSecurity.ignoring().antMatchers("/token**").antMatchers("/api/v1/courses/all")
.antMatchers("/api/v1/groups/getCourseGroups").antMatchers("/api/v1/courses/getCoursesWithGroups"); .antMatchers("/api/v1/groups/course/{id}");
} }
@Override @Override