2021-01-19 12:05:31 +01:00
|
|
|
package com.plannaplan.controllers;
|
|
|
|
|
|
|
|
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.web.bind.annotation.CrossOrigin;
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
2021-01-19 12:47:14 +01:00
|
|
|
import java.util.Date;
|
|
|
|
|
2021-01-19 12:05:31 +01:00
|
|
|
import com.plannaplan.App;
|
2021-01-19 12:47:14 +01:00
|
|
|
import com.plannaplan.models.TourData;
|
2021-01-19 12:05:31 +01:00
|
|
|
import com.plannaplan.services.AssignmentService;
|
2021-01-19 12:47:14 +01:00
|
|
|
import com.plannaplan.services.ConfiguratorService;
|
2021-01-19 12:13:26 +01:00
|
|
|
import com.plannaplan.services.ExchangeService;
|
2021-01-19 12:05:31 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Rest controller to enpoint that help deveopler test the app
|
|
|
|
*/
|
|
|
|
@RestController
|
|
|
|
@CrossOrigin
|
|
|
|
@RequestMapping("/api/" + App.API_VERSION + "/developer")
|
|
|
|
@Api(tags = {
|
|
|
|
"DeveloperController" }, value = "DeveloperController", description = "All endpoints to use in development time to help app testing")
|
|
|
|
public class DeveloperController {
|
|
|
|
|
2021-01-19 12:47:14 +01:00
|
|
|
private static final long ONE_DAY = 86400000;
|
|
|
|
|
2021-01-19 12:05:31 +01:00
|
|
|
@Autowired
|
|
|
|
private AssignmentService assignmentService;
|
|
|
|
|
2021-01-19 12:13:26 +01:00
|
|
|
@Autowired
|
|
|
|
private ExchangeService exchangeService;
|
|
|
|
|
2021-01-19 12:47:14 +01:00
|
|
|
@Autowired
|
|
|
|
private ConfiguratorService configurationController;
|
|
|
|
|
2021-01-19 12:05:31 +01:00
|
|
|
/**
|
2021-01-19 12:47:14 +01:00
|
|
|
* @return if accept algorythm was perfomed
|
2021-01-19 12:05:31 +01:00
|
|
|
*/
|
|
|
|
@PreAuthorize("hasRole('ROLE_DEVELOPER')")
|
2021-01-19 12:13:26 +01:00
|
|
|
@PostMapping(path = "/algorythm/accept")
|
2021-01-19 12:05:31 +01:00
|
|
|
public ResponseEntity<String> performAcceptAlgorythm() {
|
|
|
|
this.assignmentService.callAcceptAlgorythm();
|
|
|
|
return new ResponseEntity<>("Success", HttpStatus.OK);
|
|
|
|
}
|
2021-01-19 12:13:26 +01:00
|
|
|
|
|
|
|
/**
|
2021-01-19 12:47:14 +01:00
|
|
|
* @return if exchange algorythm was perfomed
|
2021-01-19 12:13:26 +01:00
|
|
|
*/
|
|
|
|
@PreAuthorize("hasRole('ROLE_DEVELOPER')")
|
|
|
|
@PostMapping(path = "/algorythm/exchange")
|
|
|
|
public ResponseEntity<String> performExchangeAlgorythm() {
|
|
|
|
this.exchangeService.performExchange();
|
|
|
|
return new ResponseEntity<>("Success", HttpStatus.OK);
|
|
|
|
}
|
2021-01-19 12:47:14 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return if tour was set
|
|
|
|
*/
|
|
|
|
@PreAuthorize("hasRole('ROLE_DEVELOPER')")
|
|
|
|
@PostMapping(path = "/tours/first")
|
|
|
|
public ResponseEntity<String> setFirstTour() {
|
|
|
|
this.configurationController.saveTours(
|
|
|
|
new TourData(new Date(System.currentTimeMillis() - ONE_DAY),
|
|
|
|
new Date(System.currentTimeMillis() + ONE_DAY)),
|
|
|
|
new TourData(new Date(System.currentTimeMillis() + 2 * ONE_DAY),
|
|
|
|
new Date(System.currentTimeMillis() + 3 * ONE_DAY)));
|
|
|
|
return new ResponseEntity<>("Success", HttpStatus.OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return if tour was set
|
|
|
|
*/
|
|
|
|
@PreAuthorize("hasRole('ROLE_DEVELOPER')")
|
|
|
|
@PostMapping(path = "/tours/second")
|
|
|
|
public ResponseEntity<String> setSecondTour() {
|
|
|
|
this.configurationController.saveTours(
|
|
|
|
new TourData(new Date(System.currentTimeMillis() - 3 * ONE_DAY),
|
|
|
|
new Date(System.currentTimeMillis() - 2 * ONE_DAY)),
|
|
|
|
new TourData(new Date(System.currentTimeMillis() - ONE_DAY),
|
|
|
|
new Date(System.currentTimeMillis() + ONE_DAY)));
|
|
|
|
return new ResponseEntity<>("Success", HttpStatus.OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return if tour was set
|
|
|
|
*/
|
|
|
|
@PreAuthorize("hasRole('ROLE_DEVELOPER')")
|
|
|
|
@PostMapping(path = "/tours/no")
|
|
|
|
public ResponseEntity<String> setNoTour() {
|
|
|
|
this.configurationController.saveTours(
|
|
|
|
new TourData(new Date(System.currentTimeMillis() - ONE_DAY), new Date(System.currentTimeMillis())),
|
|
|
|
new TourData(new Date(System.currentTimeMillis() + ONE_DAY),
|
|
|
|
new Date(System.currentTimeMillis() + 2 * ONE_DAY)));
|
|
|
|
return new ResponseEntity<>("Success", HttpStatus.OK);
|
|
|
|
}
|
2021-01-19 12:05:31 +01:00
|
|
|
}
|