Merge pull request 'refactor-api-endpoints' (#20) from refactor-api-endpoints into master
Reviewed-on: http://git.plannaplan.pl/filipizydorczyk/backend/pulls/20
This commit is contained in:
commit
bd4591f442
@ -36,6 +36,10 @@ python gettoken.py
|
|||||||
|
|
||||||
Na koniec w przęglądarce dostaniesz w odpowiedzi token. W samym pliku można zmienić porty aplikacji jeśli to potrzebne.
|
Na koniec w przęglądarce dostaniesz w odpowiedzi token. W samym pliku można zmienić porty aplikacji jeśli to potrzebne.
|
||||||
|
|
||||||
|
## Api docs
|
||||||
|
|
||||||
|
Żeby zobaczyć dokumentację api trzeba wejść w przeglądarce na `http://localhost:1285/swagger-ui.html` po odpaleniu aplikacji.
|
||||||
|
|
||||||
## Packaging
|
## Packaging
|
||||||
|
|
||||||
Zeby spakowac apke do `jara` wystarcza dwie komendy zaczynajac z glownego katalogu projektu
|
Zeby spakowac apke do `jara` wystarcza dwie komendy zaczynajac z glownego katalogu projektu
|
||||||
|
@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.source>1.14</maven.compiler.source>
|
<maven.compiler.source>14</maven.compiler.source>
|
||||||
<maven.compiler.target>1.14</maven.compiler.target>
|
<maven.compiler.target>14</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
88
docs/api.md
88
docs/api.md
@ -1,88 +0,0 @@
|
|||||||
# Dokumetacja API
|
|
||||||
|
|
||||||
| Api | Zadania endpointa |
|
|
||||||
| ------------------------------------------------------------- | ---------------------------------------------------------------------------- |
|
|
||||||
| [/api/v1/configurator/config](#config) | Załadowanie konfiguracji startowej do aplikacji PlanNaPlan |
|
|
||||||
| [/api/v1/courses/getCoursesWithGroups](#getcourseswithgroups) | Zwrócenie wszytskich kursów razem z grupami |
|
|
||||||
| [/api/v1/groups/getCourseGroups](#getcoursegroups) | Zwrócenie grup dla danego kursu |
|
|
||||||
| [/api/v1/courses/getCourses](#getcourses) | Zwrócenie wszystkich kursów |
|
|
||||||
| [/token](#token) | Wymienia ticket z CAS-a na token ktorym beda autoryzowane chronione requesty |
|
|
||||||
|
|
||||||
## config
|
|
||||||
|
|
||||||
Source code: [link](../restservice/src/main/java/com/plannaplan/controllers/ConfigController.java)
|
|
||||||
|
|
||||||
```
|
|
||||||
POST /config
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Opis
|
|
||||||
|
|
||||||
Endpoint konfigurujacy caly system i importujacy dane do bazy.
|
|
||||||
|
|
||||||
#### Parametry
|
|
||||||
|
|
||||||
| Type | Name | Consumes | Opis | Type |
|
|
||||||
| ---- | ----------------------- | ------------------- | ------------------------------- | ---- |
|
|
||||||
| Body | **file** </br> required | multipart/form-data | Plik .xlsx z potrzebnymi danymi | file |
|
|
||||||
|
|
||||||
## getCoursesWithGroups
|
|
||||||
|
|
||||||
Source code: [link](../restservice/src/main/java/com/plannaplan/controllers/getCoursesWithGroups.java)
|
|
||||||
|
|
||||||
```
|
|
||||||
GET /api/v1/courses/getCoursesWithGroups
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Opis
|
|
||||||
|
|
||||||
Zwraca wszystkie dostepne kursy wraz z listą grup.
|
|
||||||
|
|
||||||
## getCourseGroups
|
|
||||||
|
|
||||||
Source code: [link](../restservice/src/main/java/com/plannaplan/controllers/GroupController.java)
|
|
||||||
|
|
||||||
```
|
|
||||||
GET /api/v1/groups/getCourseGroups
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Opis
|
|
||||||
|
|
||||||
Zwraca wszytskie grupy dla danego kursu.
|
|
||||||
|
|
||||||
#### Parametry
|
|
||||||
|
|
||||||
| Type | Name | Consumes | Opis | Type |
|
|
||||||
| ----------- | --------------------- | -------- | ----------------------------------------- | ---- |
|
|
||||||
| Query Param | **id** </br> required | - | id kursu dla ktorego chcemy zwrocic grupy | int |
|
|
||||||
| Query Param | **capacity** </br> | - | czy ma zwrocic pole pojemnosci grupy | bool |
|
|
||||||
|
|
||||||
## getCourses
|
|
||||||
|
|
||||||
Source code: [link](../restservice/src/main/java/com/plannaplan/controllers/CoursesController.java)
|
|
||||||
|
|
||||||
```
|
|
||||||
GET /api/v1/courses/getCourses
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Opis
|
|
||||||
|
|
||||||
Zwraca wszystkie dostepne kursy.
|
|
||||||
|
|
||||||
## token
|
|
||||||
|
|
||||||
Source code: [link](../restservice/src/main/java/com/plannaplan/controllers/TokenController.java)
|
|
||||||
|
|
||||||
```
|
|
||||||
GET /token?ticket=ST-668405-W0gfvSVDRBdMUWLweKzv-cas.amu.edu.pl
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Opis
|
|
||||||
|
|
||||||
Po odpytaniu tego endpointa z podanym ticketem system zrobi nma nim validate i dostanie uzytkownika dla ktorego zostal on wygenerowany. System utworzy dla niego access token i go zwroci w odpowiedzi
|
|
||||||
|
|
||||||
#### Parametry
|
|
||||||
|
|
||||||
| Type | Name | Consumes | Opis | Type |
|
|
||||||
| ----------- | ------------------------- | -------- | --------------------------------------- | ------ |
|
|
||||||
| Query Param | **ticket** </br> required | - | ticket uzyskany z logowania poprzez CAS | string |
|
|
@ -18,9 +18,10 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.source>1.14</maven.compiler.source>
|
<maven.compiler.source>14</maven.compiler.source>
|
||||||
<maven.compiler.target>1.14</maven.compiler.target>
|
<maven.compiler.target>14</maven.compiler.target>
|
||||||
<start-class>com.plannaplan.App</start-class>
|
<start-class>com.plannaplan.App</start-class>
|
||||||
|
<swagger.version>2.9.2</swagger.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -85,6 +86,22 @@
|
|||||||
<groupId>com.plannaplan</groupId>
|
<groupId>com.plannaplan</groupId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.springfox</groupId>
|
||||||
|
<artifactId>springfox-swagger2</artifactId>
|
||||||
|
<version>${swagger.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.springfox</groupId>
|
||||||
|
<artifactId>springfox-swagger-ui</artifactId>
|
||||||
|
<version>${swagger.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||||
|
|
||||||
import org.springframework.context.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@ -53,7 +54,7 @@ public class App {
|
|||||||
mar.setEmail("marwoz16@st.amu.edu.pl");
|
mar.setEmail("marwoz16@st.amu.edu.pl");
|
||||||
mar.setName("Marcin");
|
mar.setName("Marcin");
|
||||||
mar.setSurname("Woźniak");
|
mar.setSurname("Woźniak");
|
||||||
mar.setRole(UserRoles.STUDENT);
|
mar.setRole(UserRoles.ADMIN);
|
||||||
this.userService.save(mar);
|
this.userService.save(mar);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
38
restservice/src/main/java/com/plannaplan/Swagger2Config.java
Executable file
38
restservice/src/main/java/com/plannaplan/Swagger2Config.java
Executable file
@ -0,0 +1,38 @@
|
|||||||
|
package com.plannaplan;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||||
|
import springfox.documentation.builders.ApiInfoBuilder;
|
||||||
|
import springfox.documentation.builders.PathSelectors;
|
||||||
|
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||||
|
import springfox.documentation.service.ApiInfo;
|
||||||
|
import springfox.documentation.spi.DocumentationType;
|
||||||
|
import springfox.documentation.spring.web.plugins.Docket;
|
||||||
|
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableSwagger2
|
||||||
|
public class Swagger2Config extends WebMvcConfigurationSupport {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Docket createRestApi() {
|
||||||
|
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
|
||||||
|
.apis(RequestHandlerSelectors.basePackage("com.plannaplan.controllers")).paths(PathSelectors.any())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
|
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
|
||||||
|
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||||
|
}
|
||||||
|
|
||||||
|
private ApiInfo apiInfo() {
|
||||||
|
return new ApiInfoBuilder().title("plannaplan").description("Aplikacja do zapisów na zajęcia UAM.")
|
||||||
|
.termsOfServiceUrl("https://plannaplan.pl/")
|
||||||
|
// .contact("")
|
||||||
|
.version("1.0").build();
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,9 @@ 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.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@ -24,6 +27,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@RequestMapping("/api/" + App.API_VERSION + "/assignments")
|
@RequestMapping("/api/" + App.API_VERSION + "/assignments")
|
||||||
|
@Api(tags = {
|
||||||
|
"Assignments" }, value = "Assignments", description = "Assignment is representation of student willing to join given group (lecture or calss)")
|
||||||
public class AssignmentsController extends TokenBasedController {
|
public class AssignmentsController extends TokenBasedController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -32,7 +37,8 @@ public class AssignmentsController extends TokenBasedController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private AssignmentService assignmentService;
|
private AssignmentService assignmentService;
|
||||||
|
|
||||||
@GetMapping("/getCurrentAssignments")
|
@GetMapping("/user")
|
||||||
|
@ApiOperation(value = "Retrun user current assignemts (from newest commision). STUDENT Token needs to be provided.")
|
||||||
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);
|
||||||
|
@ -2,8 +2,12 @@ package com.plannaplan.controllers;
|
|||||||
|
|
||||||
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.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import io.swagger.annotations.ApiParam;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -24,15 +28,16 @@ import com.plannaplan.types.UserRoles;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@RequestMapping("/api/" + App.API_VERSION + "/commisions")
|
@RequestMapping("/api/" + App.API_VERSION + "/commisions")
|
||||||
|
@Api(tags = { "Commisions" }, value = "Commisions", description = "Commision is representation of student selected assignments at time. All assignments are attached to some commision so we can see current assignments and also browse histroy of changes for given user")
|
||||||
public class CommisionController extends TokenBasedController {
|
public class CommisionController extends TokenBasedController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -47,8 +52,10 @@ public class CommisionController extends TokenBasedController {
|
|||||||
public CommisionController() {
|
public CommisionController() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = { "/add", "/add/{id}" })
|
@PostMapping(value = { "/user", "/user/{id}" })
|
||||||
public ResponseEntity<String> addCommision(@RequestBody List<Long> groups,
|
@ApiOperation(value = "Create commision with assignents to given groups. If group doesn't exist error will be thrown")
|
||||||
|
public ResponseEntity<String> addCommision(
|
||||||
|
@RequestBody @ApiParam(value = "List of groups ids user want to assign to. If group doesnt exisit error will be thrown") List<Long> groups,
|
||||||
@PathVariable(name = "id", required = false) Long userId) {
|
@PathVariable(name = "id", required = false) Long userId) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -62,7 +69,7 @@ public class CommisionController extends TokenBasedController {
|
|||||||
: asker;
|
: asker;
|
||||||
|
|
||||||
Assert.isTrue((asker.getRole() == UserRoles.DEANERY && user.getRole() == UserRoles.STUDENT
|
Assert.isTrue((asker.getRole() == UserRoles.DEANERY && user.getRole() == UserRoles.STUDENT
|
||||||
|| (asker.getId() == user.getId() && user.getRole() == UserRoles.STUDENT)),
|
|| (asker.getId().equals(user.getId()) && user.getRole() == UserRoles.STUDENT)),
|
||||||
"Incorrect attempt to change plan");
|
"Incorrect attempt to change plan");
|
||||||
|
|
||||||
Optional<Long> notExistingGroup = this.groupServcicxe.findNotExistingGroup(groups);
|
Optional<Long> notExistingGroup = this.groupServcicxe.findNotExistingGroup(groups);
|
||||||
@ -87,7 +94,8 @@ public class CommisionController extends TokenBasedController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/getAllCommisions")
|
@GetMapping("/user")
|
||||||
|
@ApiOperation("Return list of user all commisions (history of schedules)")
|
||||||
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
|
||||||
@ -97,6 +105,7 @@ public class CommisionController extends TokenBasedController {
|
|||||||
|
|
||||||
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
||||||
@GetMapping("/user/{id}")
|
@GetMapping("/user/{id}")
|
||||||
|
@ApiOperation("Return list of commisions for given user. To be able to access this data u need to provide DEANERY token")
|
||||||
public ResponseEntity<List<CommisionResponse>> getCommision(@PathVariable(name = "id") Long userId)
|
public ResponseEntity<List<CommisionResponse>> getCommision(@PathVariable(name = "id") Long userId)
|
||||||
throws UserNotFoundException {
|
throws UserNotFoundException {
|
||||||
User user = this.userService.getById(userId).orElseThrow(() -> new NullPointerException());
|
User user = this.userService.getById(userId).orElseThrow(() -> new NullPointerException());
|
||||||
|
@ -19,10 +19,15 @@ 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.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import io.swagger.annotations.ApiParam;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@RequestMapping("/api/" + App.API_VERSION + "/configurator")
|
@RequestMapping("/api/" + App.API_VERSION + "/configurator")
|
||||||
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
||||||
|
@Api(tags = { "ConfigController" }, value = "ConfigController", description = "All endpoints to configure an app")
|
||||||
public class ConfigController {
|
public class ConfigController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -30,8 +35,9 @@ public class ConfigController {
|
|||||||
|
|
||||||
@PostMapping("/config")
|
@PostMapping("/config")
|
||||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||||
|
@ApiOperation("Imports data to system. To call you need to provide ADMIN token")
|
||||||
public ResponseEntity<String> configApp(@RequestParam("file") MultipartFile file) {
|
public ResponseEntity<String> configApp(
|
||||||
|
@RequestParam("file") @ApiParam(value = "file .xlsx that contains courses and groups with apoinnted rules") MultipartFile file) {
|
||||||
try {
|
try {
|
||||||
final ConfigData data = new ConfigData(null, null, file.getInputStream());
|
final ConfigData data = new ConfigData(null, null, file.getInputStream());
|
||||||
this.contrl.config(data);
|
this.contrl.config(data);
|
||||||
|
@ -14,30 +14,36 @@ 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.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import io.swagger.annotations.ApiParam;
|
||||||
|
|
||||||
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
|
||||||
@RequestMapping("/api/" + App.API_VERSION + "/courses")
|
@RequestMapping("/api/" + App.API_VERSION + "/courses")
|
||||||
|
@Api(tags = {
|
||||||
|
"Course" }, value = "Course", description = "Endpoints to deal with courses. All courses can have classes, lectures or both.")
|
||||||
public class CoursesController {
|
public class CoursesController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private CourseService courseService;
|
private CourseService courseService;
|
||||||
|
|
||||||
@GetMapping("/getCourses")
|
@GetMapping("/all")
|
||||||
public ResponseEntity<List<GetCoursesResponse>> getMethodName() {
|
@ApiOperation(value = "Return all courses")
|
||||||
|
public ResponseEntity<List<? extends CoursesResponse>> getMethodName(
|
||||||
|
@RequestParam(name = "groups", defaultValue = "false") @ApiParam(value = "Boolean if you want to have resopnse with associated groups or without") Boolean groups) {
|
||||||
List<Course> courses = this.courseService.getAllCourses();
|
List<Course> courses = this.courseService.getAllCourses();
|
||||||
List<GetCoursesResponse> response = CoursesResponseMappers.mapToGetCoursesResponse(courses);
|
if (groups) {
|
||||||
|
final List<GetCoursesWithGroupsResponse> response = CoursesResponseMappers
|
||||||
|
.mapToGetCoursesWithGroupsResponse(courses);
|
||||||
|
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
final List<GetCoursesResponse> response = CoursesResponseMappers.mapToGetCoursesResponse(courses);
|
||||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
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
|
|
||||||
.mapToGetCoursesWithGroupsResponse(courses);
|
|
||||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -14,20 +14,30 @@ 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;
|
||||||
|
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import io.swagger.annotations.ApiParam;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
|
|
||||||
@RequestMapping("/api/" + App.API_VERSION + "/groups")
|
@RequestMapping("/api/" + App.API_VERSION + "/groups")
|
||||||
|
@Api(tags = {
|
||||||
|
"Group" }, value = "Group", description = "Enpoints to deal with gorups. Group is related directly to course and can be either class and lecture")
|
||||||
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,
|
@ApiOperation(value = "Return list of lectures and classes (if present) given course")
|
||||||
@RequestParam(name = "capacity", defaultValue = "true") Boolean capacity) {
|
public ResponseEntity<GetCourseGroupsResponse<? extends DefaultGroupResponse>> getCourses(
|
||||||
|
@PathVariable(name = "id") Long id,
|
||||||
|
@RequestParam(name = "capacity", defaultValue = "true") @ApiParam(value = "Boolean if we want to have capacity field in response") Boolean capacity) {
|
||||||
List<Groups> groups = this.groupService.getGroupsByCourse(id);
|
List<Groups> groups = this.groupService.getGroupsByCourse(id);
|
||||||
if (capacity) {
|
if (capacity) {
|
||||||
return new ResponseEntity<>(GroupsMappers.mapToGetCourseGroupsWithCapacityResponse(groups), HttpStatus.OK);
|
return new ResponseEntity<>(GroupsMappers.mapToGetCourseGroupsWithCapacityResponse(groups), HttpStatus.OK);
|
||||||
|
@ -13,8 +13,13 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|||||||
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;
|
||||||
|
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import io.swagger.annotations.ApiParam;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
|
@Api(tags = { "Token" }, value = "Token", description = "Enpoints to get authorization.")
|
||||||
public class TokenController {
|
public class TokenController {
|
||||||
|
|
||||||
private final static String SERVICE_URL = "http://localhost:3000";
|
private final static String SERVICE_URL = "http://localhost:3000";
|
||||||
@ -23,7 +28,9 @@ public class TokenController {
|
|||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
|
||||||
@GetMapping("/token")
|
@GetMapping("/token")
|
||||||
public ResponseEntity<String> getToken(@RequestParam("ticket") final String ticket) {
|
@ApiOperation(value = "Endpoint to access token required to call secured endpoints. In order to access token we need to provide access token comming from unviersity CAS system")
|
||||||
|
public ResponseEntity<String> getToken(
|
||||||
|
@RequestParam("ticket") @ApiParam(value = "Ticket get from CAS system. It should look like ST-1376572-wo41gty5R0JCZFKMMie2-cas.amu.edu.pl") final String ticket) {
|
||||||
final CasValidator validator = new CasValidator(SERVICE_URL, ticket);
|
final CasValidator validator = new CasValidator(SERVICE_URL, ticket);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -15,6 +15,11 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
|||||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import io.swagger.annotations.ApiParam;
|
||||||
|
|
||||||
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 org.springframework.web.bind.annotation.RequestParam;
|
||||||
@ -23,14 +28,16 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@RequestMapping("/api/" + App.API_VERSION + "/users")
|
@RequestMapping("/api/" + App.API_VERSION + "/users")
|
||||||
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
||||||
|
@Api(tags = { "Users" }, value = "Users", description = "Endpoints to deal with users.")
|
||||||
public class UsersController {
|
public class UsersController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
|
||||||
@GetMapping("/searchForStudents")
|
@GetMapping("/student/search")
|
||||||
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
||||||
|
@ApiOperation(value = "Serch for user by providing query. If query is empty it will return all students. You need token with DEANERY role to call this")
|
||||||
public ResponseEntity<List<SearchForStudentsResponse>> configApp(@RequestParam("query") String query) {
|
public ResponseEntity<List<SearchForStudentsResponse>> configApp(
|
||||||
|
@RequestParam("query") @ApiParam(value = "Query to filter all students. If empty will match everyone") String query) {
|
||||||
final List<User> searches = this.userService.searchForStudents(query);
|
final List<User> searches = this.userService.searchForStudents(query);
|
||||||
final List<SearchForStudentsResponse> response = UserResponseMappers.mapToDefaultResponse(searches);
|
final List<SearchForStudentsResponse> response = UserResponseMappers.mapToDefaultResponse(searches);
|
||||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||||
|
@ -18,6 +18,7 @@ import org.springframework.security.web.authentication.HttpStatusEntryPoint;
|
|||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
|
|
||||||
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||||
|
|
||||||
private static final RequestMatcher PROTECTED_URLS = new OrRequestMatcher(new AntPathRequestMatcher("/api/**"));
|
private static final RequestMatcher PROTECTED_URLS = new OrRequestMatcher(new AntPathRequestMatcher("/api/**"));
|
||||||
@ -36,8 +37,9 @@ 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}").antMatchers("/v2/api-docs", "/configuration/ui",
|
||||||
|
"/swagger-resources/**", "/configuration/security", "/swagger-ui.html", "/webjars/**");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -22,7 +22,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
public class AssignmentsControllerTest extends AbstractControllerTest {
|
public class AssignmentsControllerTest extends AbstractControllerTest {
|
||||||
|
|
||||||
private static final String ASSIGFNMENTS_ENDPOINT = "/api/v1/assignments/getCurrentAssignments";
|
private static final String ASSIGFNMENTS_ENDPOINT = "/api/v1/assignments/user";
|
||||||
private static final String TEST_MAIL = "notexistingassignmentuser@mail.domain";
|
private static final String TEST_MAIL = "notexistingassignmentuser@mail.domain";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -40,8 +40,8 @@ public class CommisionControllerTest extends AbstractControllerTest {
|
|||||||
private static final String TEST_COMMISIONS_DEANERY_EMAIL = "commisions.deanery@notexisting.domain";
|
private static final String TEST_COMMISIONS_DEANERY_EMAIL = "commisions.deanery@notexisting.domain";
|
||||||
private static final String TEST_COMMISIONS_OTHER_DEANERY_EMAIL = "commisions.deanery2@notexisting.domain";
|
private static final String TEST_COMMISIONS_OTHER_DEANERY_EMAIL = "commisions.deanery2@notexisting.domain";
|
||||||
|
|
||||||
private static final String ADD_COMMISION_ENDPOINT = "/api/v1/commisions/add";
|
private static final String ADD_COMMISION_ENDPOINT = "/api/v1/commisions/user";
|
||||||
private static final String GET_COMMISIONS_ENDPOINT = "/api/v1/commisions/getAllCommisions";
|
private static final String GET_COMMISIONS_ENDPOINT = "/api/v1/commisions/user";
|
||||||
private static final String GET_SOMEONE_COMMISIONS_ENDPOINT = "/api/v1/commisions/user";
|
private static final String GET_SOMEONE_COMMISIONS_ENDPOINT = "/api/v1/commisions/user";
|
||||||
|
|
||||||
private static final MediaType APPLICATION_JSON_UTF8 = new MediaType(MediaType.APPLICATION_JSON.getType(),
|
private static final MediaType APPLICATION_JSON_UTF8 = new MediaType(MediaType.APPLICATION_JSON.getType(),
|
||||||
|
@ -16,8 +16,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
public class CoursesControllerTest extends AbstractControllerTest {
|
public class CoursesControllerTest extends AbstractControllerTest {
|
||||||
|
|
||||||
private static final String COURSES_ENDPOINT = "/api/v1/courses/getCourses";
|
private static final String COURSES_ENDPOINT = "/api/v1/courses/all";
|
||||||
private static final String COURSESGROUPS_ENDPOINT = "/api/v1/courses/getCoursesWithGroups";
|
private static final String COURSESGROUPS_ENDPOINT = "/api/v1/courses/all?groups=true";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnAllCoursesOk() throws Exception {
|
public void shouldReturnAllCoursesOk() throws Exception {
|
||||||
|
@ -14,18 +14,19 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
|
|
||||||
public class GroupControllerTest extends AbstractControllerTest {
|
public class GroupControllerTest extends AbstractControllerTest {
|
||||||
private static final String GROUPS_BY_COURSE_ENDPOINT = "/api/v1/groups/getCourseGroups";
|
private static final String GROUPS_BY_COURSE_ENDPOINT = "/api/v1/groups/course";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldFailWithNoParaeter() throws Exception {
|
public void shouldFailWithNoParaeter() throws Exception {
|
||||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
|
||||||
mockMvc.perform(get(GROUPS_BY_COURSE_ENDPOINT)).andExpect(status().isBadRequest());
|
mockMvc.perform(get(GROUPS_BY_COURSE_ENDPOINT)).andExpect(status().isNotFound());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnGroupsOk() throws Exception {
|
public void shouldReturnGroupsOk() throws Exception {
|
||||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
|
||||||
mockMvc.perform(get(GROUPS_BY_COURSE_ENDPOINT).param("id", "2")).andExpect(status().isOk());
|
mockMvc.perform(get(GROUPS_BY_COURSE_ENDPOINT + "/2")).andExpect(status().isOk());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
|
|
||||||
public class UsersControllerTest extends AbstractControllerTest {
|
public class UsersControllerTest extends AbstractControllerTest {
|
||||||
private static final String ENDPOINT = "/api/v1/users/searchForStudents";
|
private static final String ENDPOINT = "/api/v1/users/student/search";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserService service;
|
private UserService service;
|
||||||
|
Loading…
Reference in New Issue
Block a user