Untitled
unknown
plain_text
8 days ago
4.0 kB
4
Indexable
package com.santander.scib.dlx.service.impl; import com.fasterxml.jackson.databind.ObjectMapper; import com.santander.scib.dlx.model.nativ.DlxGenericResponse; import com.santander.scib.dlx.model.nativ.NativeCreateCalendarResponse; import com.santander.scib.dlx.model.nativ.NativeDeleteCalendarResponse; import com.santander.scib.dlx.model.nativ.NativeUpdateCalendarResponse; import com.santander.scib.dlx.model.web.CreateCalendarRequest; import com.santander.scib.dlx.model.web.GenericResponse; import com.santander.scib.dlx.model.web.UpdateCalendarRequest; import com.santander.scib.dlx.service.CalendarService; import com.santander.scib.dlx.service.DlxService; import com.santander.scib.dlx.util.QueryUtil; import com.santander.scib.dlx.util.ReplaceUtils; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; @Slf4j @Service @RequiredArgsConstructor public class CalendarServiceImpl implements CalendarService { private final DlxService dlxService; @Override public ResponseEntity<GenericResponse> createCalendar(String token, CreateCalendarRequest createCalendarRequest) { var query = QueryUtil.generateCreateCalendarQuery(); query = ReplaceUtils.replaceCalendar(query, createCalendarRequest.getCalendar()); DlxGenericResponse<NativeCreateCalendarResponse> response = dlxService.executeAndResponse(token, query); if(response.getErrors() != null) { log.error("CalendarService.createCalendar -> error: {}", response.getErrors()); return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR); } var data = new ObjectMapper().convertValue(response.getData(), NativeCreateCalendarResponse.class); log.info("CalendarService.createCalendar -> response: {}", data.getCreateCalendar().getResult()); return new ResponseEntity<>(data.getCreateCalendar().getResult(), HttpStatus.CREATED); } @Override public ResponseEntity<GenericResponse> updateCalendar(String token, String calendarId, UpdateCalendarRequest updateCalendarRequest) { var query = QueryUtil.generateUpdateCalendarQuery(); query = ReplaceUtils.replaceUpdateCalendar(query, calendarId, updateCalendarRequest.getCalendarUpdate()); DlxGenericResponse<NativeUpdateCalendarResponse> response = dlxService.executeAndResponse(token, query); if(response.getErrors() != null) { log.error("CalendarService.updateCalendar -> error: {}", response.getErrors()); return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR); } var data = new ObjectMapper().convertValue(response.getData(), NativeUpdateCalendarResponse.class); log.info("CalendarService.updateCalendar -> response: {}", data.getUpdateCalendar().getResult()); return new ResponseEntity<>(data.getUpdateCalendar().getResult(), HttpStatus.OK); } @Override public ResponseEntity<GenericResponse> deleteCalendar(String token, String calendarId) { var query = QueryUtil.generateDeleteCalendarQuery(); query = ReplaceUtils.replaceDeleteCalendar(query, calendarId); DlxGenericResponse<NativeDeleteCalendarResponse> response = dlxService.executeAndResponse(token, query); if(response.getErrors() != null) { log.error("CalendarService.deleteCalendar -> error: {}", response.getErrors()); return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR); } var data = new ObjectMapper().convertValue(response.getData(), NativeDeleteCalendarResponse.class); log.info("CalendarService.deleteCalendar -> response: {}", data.getDeleteCalendar().getResult()); return new ResponseEntity<>(data.getDeleteCalendar().getResult(), HttpStatus.OK); } }
Editor is loading...
Leave a Comment