2020-10-19 11:12:24 +02:00
|
|
|
package com.plannaplan.controllers;
|
|
|
|
|
2020-10-19 12:13:02 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2020-10-19 11:12:24 +02:00
|
|
|
import com.plannaplan.App;
|
2020-10-19 12:13:02 +02:00
|
|
|
import com.plannaplan.entities.User;
|
|
|
|
import com.plannaplan.responses.mappers.UserResponseMappers;
|
|
|
|
import com.plannaplan.responses.models.SearchForStudentsResponse;
|
2020-10-19 11:12:24 +02:00
|
|
|
import com.plannaplan.services.UserService;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
|
|
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
2020-11-04 16:40:02 +01:00
|
|
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
2020-10-19 11:12:24 +02:00
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@CrossOrigin
|
2020-10-19 12:13:02 +02:00
|
|
|
@RequestMapping("/api/" + App.API_VERSION + "/users")
|
2020-10-19 11:12:24 +02:00
|
|
|
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
2020-11-04 16:40:02 +01:00
|
|
|
@Api(tags = { "Users" }, value = "Users", description = "Endpoints to deal with users.")
|
2020-10-19 12:13:02 +02:00
|
|
|
public class UsersController {
|
2020-10-19 11:12:24 +02:00
|
|
|
@Autowired
|
|
|
|
private UserService userService;
|
|
|
|
|
2020-10-30 16:42:57 +01:00
|
|
|
@GetMapping("/search")
|
2020-10-19 11:12:24 +02:00
|
|
|
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
|
|
|
|
2020-10-19 12:13:02 +02:00
|
|
|
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);
|
2020-10-19 11:12:24 +02:00
|
|
|
}
|
|
|
|
}
|