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; import java.util.Date; import com.plannaplan.App; import com.plannaplan.models.TourData; import com.plannaplan.services.AssignmentService; import com.plannaplan.services.ConfiguratorService; import com.plannaplan.services.ExchangeService; /** * 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 { private static final long ONE_DAY = 86400000; @Autowired private AssignmentService assignmentService; @Autowired private ExchangeService exchangeService; @Autowired private ConfiguratorService configurationController; /** * @return if accept algorythm was perfomed */ @PreAuthorize("hasRole('ROLE_DEVELOPER')") @PostMapping(path = "/algorythm/accept") public ResponseEntity performAcceptAlgorythm() { this.assignmentService.callAcceptAlgorythm(); return new ResponseEntity<>("Success", HttpStatus.OK); } /** * @return if exchange algorythm was perfomed */ @PreAuthorize("hasRole('ROLE_DEVELOPER')") @PostMapping(path = "/algorythm/exchange") public ResponseEntity performExchangeAlgorythm() { this.exchangeService.performExchange(); return new ResponseEntity<>("Success", HttpStatus.OK); } /** * @return if tour was set */ @PreAuthorize("hasRole('ROLE_DEVELOPER')") @PostMapping(path = "/tours/first") public ResponseEntity 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 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 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); } }