backend/restservice/src/main/java/com/plannaplan/controllers/ConfigController.java

50 lines
2.0 KiB
Java
Raw Normal View History

2020-08-04 17:30:03 +02:00
package com.plannaplan.controllers;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
2020-09-15 11:31:30 +02:00
import com.plannaplan.App;
2020-08-04 17:30:03 +02:00
import com.plannaplan.models.ConfigData;
import com.plannaplan.services.ConfiguratorService;
2020-08-04 17:30:03 +02:00
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
2020-10-16 16:31:10 +02:00
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
2020-08-04 17:30:03 +02:00
import org.springframework.web.bind.annotation.PostMapping;
2020-09-15 11:31:30 +02:00
import org.springframework.web.bind.annotation.RequestMapping;
2020-08-04 17:30:03 +02:00
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
2020-11-04 16:40:02 +01:00
import io.swagger.annotations.Api;
2020-11-04 16:58:26 +01:00
import io.swagger.annotations.ApiOperation;
2020-11-04 17:23:29 +01:00
import io.swagger.annotations.ApiParam;
2020-11-04 16:40:02 +01:00
2020-08-04 17:30:03 +02:00
@RestController
@CrossOrigin
2020-09-15 11:31:30 +02:00
@RequestMapping("/api/" + App.API_VERSION + "/configurator")
2020-10-16 16:31:10 +02:00
@EnableGlobalMethodSecurity(prePostEnabled = true)
2020-11-04 16:40:02 +01:00
@Api(tags = { "ConfigController" }, value = "ConfigController", description = "All endpoints to configure an app")
2020-08-04 17:30:03 +02:00
public class ConfigController {
@Autowired
private ConfiguratorService contrl;
2020-08-04 17:30:03 +02:00
@PostMapping("/config")
@PreAuthorize("hasRole('ROLE_ADMIN')")
2020-11-04 16:58:26 +01:00
@ApiOperation("Imports data to system. To call you need to provide ADMIN token")
2020-11-04 17:23:29 +01:00
public ResponseEntity<String> configApp(
@RequestParam("file") @ApiParam(value = "file .xlsx that contains courses and groups with apoinnted rules") MultipartFile file) {
2020-08-04 17:30:03 +02:00
try {
2020-09-25 16:43:24 +02:00
final ConfigData data = new ConfigData(null, null, file.getInputStream());
2020-08-04 17:30:03 +02:00
this.contrl.config(data);
return new ResponseEntity<>("Sucess", HttpStatus.OK);
} catch (IOException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}