X-Git-Url: https://gerrit.akraino.org/r/gitweb?p=validation.git;a=blobdiff_plain;f=ui%2Fsrc%2Fmain%2Fjava%2Forg%2Fakraino%2Fvalidation%2Fui%2Fcontroller%2FTimeslotController.java;fp=ui%2Fsrc%2Fmain%2Fjava%2Forg%2Fakraino%2Fvalidation%2Fui%2Fcontroller%2FTimeslotsController.java;h=2e86406dc066ca76fa66e9484fea6aa692812327;hp=f82c273413356ee25843ebb619c2c746387dee48;hb=3ff5d7028b19a649f6b80c476ff45ced1fdd67dc;hpb=147ecf7bf79ea9967a121d0038103151a38ebef2 diff --git a/ui/src/main/java/org/akraino/validation/ui/controller/TimeslotsController.java b/ui/src/main/java/org/akraino/validation/ui/controller/TimeslotController.java similarity index 56% rename from ui/src/main/java/org/akraino/validation/ui/controller/TimeslotsController.java rename to ui/src/main/java/org/akraino/validation/ui/controller/TimeslotController.java index f82c273..2e86406 100644 --- a/ui/src/main/java/org/akraino/validation/ui/controller/TimeslotsController.java +++ b/ui/src/main/java/org/akraino/validation/ui/controller/TimeslotController.java @@ -19,7 +19,7 @@ package org.akraino.validation.ui.controller; import java.util.List; import org.akraino.validation.ui.entity.Timeslot; -import org.akraino.validation.ui.service.TimeslotService; +import org.akraino.validation.ui.service.DbAdapter; import org.onap.portalsdk.core.controller.RestrictedBaseController; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.web.support.UserUtils; @@ -27,19 +27,20 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @Controller -@RequestMapping("/api/v1/timeslots") -public class TimeslotsController extends RestrictedBaseController { +@RequestMapping("/api/v1/timeslot") +public class TimeslotController extends RestrictedBaseController { - private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(TimeslotsController.class); + private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(TimeslotController.class); @Autowired - TimeslotService service; + DbAdapter service; - public TimeslotsController() { + public TimeslotController() { super(); } @@ -49,8 +50,30 @@ public class TimeslotsController extends RestrictedBaseController { return new ResponseEntity<>(service.getTimeslots(), HttpStatus.OK); } catch (Exception e) { LOGGER.error(EELFLoggerDelegate.errorLogger, - "Error occured when trying to retrieve timeslots. " + UserUtils.getStackTrace(e)); + "Error occured when trying to retrieve timeslots." + UserUtils.getStackTrace(e)); } return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); } + + @RequestMapping(value = { "/" }, method = RequestMethod.POST) + public ResponseEntity createTimeslot(@RequestBody Timeslot timeslot) { + try { + service.saveTimeslot(timeslot); + return new ResponseEntity<>(timeslot, HttpStatus.OK); + } catch (Exception e) { + LOGGER.error(EELFLoggerDelegate.errorLogger, "Creation of timeslot failed. " + UserUtils.getStackTrace(e)); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); + } + } + + @RequestMapping(value = { "/" }, method = RequestMethod.DELETE) + public ResponseEntity deleteTimeslot(@RequestBody Timeslot timeslot) { + try { + service.deleteTimeslot(timeslot); + return new ResponseEntity<>(true, HttpStatus.OK); + } catch (Exception e) { + LOGGER.error(EELFLoggerDelegate.errorLogger, "Deletion of timeslot failed. " + UserUtils.getStackTrace(e)); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); + } + } }