Added response mappers
This commit is contained in:
@ -32,7 +32,7 @@ public class App {
|
||||
filip.setEmail("filizy@st.amu.edu.pl");
|
||||
filip.setName("Filip");
|
||||
filip.setSurname("Izydorczyk");
|
||||
filip.setRole(UserRoles.STUDENT);
|
||||
filip.setRole(UserRoles.DEANERY);
|
||||
this.userService.save(filip);
|
||||
|
||||
User hub = new User();
|
||||
|
@ -1,10 +1,15 @@
|
||||
package com.plannaplan.controllers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.App;
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.responses.mappers.CoursesResponseMappers;
|
||||
import com.plannaplan.responses.mappers.UserResponseMappers;
|
||||
import com.plannaplan.responses.models.GetCoursesResponse;
|
||||
import com.plannaplan.responses.models.GetCoursesWithGroupsResponse;
|
||||
import com.plannaplan.responses.models.SearchForStudentsResponse;
|
||||
import com.plannaplan.services.CourseService;
|
||||
import com.plannaplan.services.UserService;
|
||||
|
||||
@ -21,16 +26,18 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/api/" + App.API_VERSION + "/students")
|
||||
@RequestMapping("/api/" + App.API_VERSION + "/users")
|
||||
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
||||
public class StudentsController {
|
||||
public class UsersController {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@GetMapping("/searchForUsers")
|
||||
@GetMapping("/searchForStudents")
|
||||
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
||||
|
||||
public ResponseEntity<String> configApp(@RequestParam("query") String query) {
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
public ResponseEntity<List<SearchForStudentsResponse>> configApp(@RequestParam("query") String query) {
|
||||
final List<User> searches = this.userService.searchForStudents(query);
|
||||
final List<SearchForStudentsResponse> response = UserResponseMappers.mapToDefaultResponse(searches);
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.plannaplan.responses.mappers;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.responses.models.SearchForStudentsResponse;
|
||||
|
||||
public class UserResponseMappers {
|
||||
public static List<SearchForStudentsResponse> mapToDefaultResponse(List<User> groups) {
|
||||
return groups.stream().filter(Objects::nonNull).map(SearchForStudentsResponse::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.plannaplan.responses.models;
|
||||
|
||||
import com.plannaplan.entities.User;
|
||||
|
||||
public class SearchForStudentsResponse {
|
||||
|
||||
private Long id;
|
||||
private String name;
|
||||
private String surname;
|
||||
private String email;
|
||||
|
||||
public SearchForStudentsResponse(User user) {
|
||||
this.id = user.getId();
|
||||
this.name = user.getName();
|
||||
this.surname = user.getSurname();
|
||||
this.email = user.getEmail();
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public String getSurname() {
|
||||
return surname;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user