From 9ebb9435c9263b1694b9654cdd2b8d97169bc510 Mon Sep 17 00:00:00 2001 From: Michal Badin <xbadin@fi.muni.cz> Date: Mon, 10 Apr 2023 16:55:12 +0200 Subject: [PATCH] refactoring(Dtos): M1 feedback - renamed models to contain suffix Dto --- application/openapi.yaml | 67 +++-- .../pa165/rest/ApplicationController.java | 40 ++- .../pa165/rest/ApplicationControllerTest.java | 60 ++-- core/openapi.yaml | 268 ++++++++++-------- .../pa165/rest/CarComponentController.java | 45 ++- .../cz/muni/pa165/rest/CarController.java | 35 ++- .../muni/pa165/rest/DepartmentController.java | 43 +-- .../cz/muni/pa165/rest/DriverController.java | 59 ++-- .../rest/CarComponentControllerTest.java | 50 ++-- .../cz/muni/pa165/rest/CarControllerTest.java | 38 +-- .../pa165/rest/DepartmentControllerTest.java | 45 +-- .../muni/pa165/rest/DriverControllerTest.java | 38 +-- notification/openapi.yaml | 38 +-- .../pa165/rest/NotificationController.java | 24 +- .../rest/NotificationControllerTest.java | 10 +- visualization/openapi.yaml | 8 +- .../pa165/rest/VisualizationController.java | 8 +- .../rest/VisualizationControllerTest.java | 6 +- 18 files changed, 449 insertions(+), 433 deletions(-) diff --git a/application/openapi.yaml b/application/openapi.yaml index 681bbe0..4513121 100644 --- a/application/openapi.yaml +++ b/application/openapi.yaml @@ -17,7 +17,7 @@ components: - rejected - accepted - Application: + ApplicationDto: type: object title: Application description: Application for becoming driver @@ -52,6 +52,35 @@ components: format: date status: $ref: '#/components/schemas/ApplicationStatus' + ApplicationCreateDto: + type: object + properties: + name: + type: string + description: Name of the person + surname: + type: string + description: Name of the person + birthday: + type: string + description: Date of birth + example: 1977-09-30 + format: date + fillingOutDate: + type: string + description: Date of filling out the application + example: 2023-01-01 + format: date + required: + - name + - surname + - fillingOutDate + ApplicationUpdateDto: + type: object + properties: + status: + $ref: '#/components/schemas/ApplicationStatus' + responses: NotFound: description: The specified resource was not found @@ -87,35 +116,14 @@ paths: content: application/json: schema: - type: object - properties: - name: - type: string - description: Name of the person - surname: - type: string - description: Name of the person - birthday: - type: string - description: Date of birth - example: 1977-09-30 - format: date - fillingOutDate: - type: string - description: Date of filling out the application - example: 2023-01-01 - format: date - required: - - name - - surname - - fillingOutDate + $ref: '#/components/schemas/ApplicationCreateDto' responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/Application' + $ref: '#/components/schemas/ApplicationDto' default: $ref: '#/components/responses/Unexpected' get: @@ -131,7 +139,7 @@ paths: schema: type: array items: - $ref: '#/components/schemas/Application' + $ref: '#/components/schemas/ApplicationDto' default: $ref: '#/components/responses/Unexpected' @@ -149,7 +157,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/Application' + $ref: '#/components/schemas/ApplicationDto' "404": $ref: '#/components/responses/NotFound' default: @@ -167,17 +175,14 @@ paths: content: application/json: schema: - type: object - properties: - status: - $ref: '#/components/schemas/ApplicationStatus' + $ref: '#/components/schemas/ApplicationUpdateDto' responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/Application' + $ref: '#/components/schemas/ApplicationDto' "404": $ref: '#/components/responses/NotFound' default: diff --git a/application/src/main/java/cz/muni/pa165/rest/ApplicationController.java b/application/src/main/java/cz/muni/pa165/rest/ApplicationController.java index bb3cad4..f8f65c9 100644 --- a/application/src/main/java/cz/muni/pa165/rest/ApplicationController.java +++ b/application/src/main/java/cz/muni/pa165/rest/ApplicationController.java @@ -1,9 +1,9 @@ package cz.muni.pa165.rest; import cz.muni.pa165.generated.api.ApplicationServiceApiDelegate; -import cz.muni.pa165.generated.model.Application; -import cz.muni.pa165.generated.model.CreateApplicationRequest; -import cz.muni.pa165.generated.model.UpdateApplicationRequest; +import cz.muni.pa165.generated.model.ApplicationDto; +import cz.muni.pa165.generated.model.ApplicationCreateDto; +import cz.muni.pa165.generated.model.ApplicationUpdateDto; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; @@ -22,23 +22,23 @@ public class ApplicationController implements ApplicationServiceApiDelegate { private static final Logger log = LoggerFactory.getLogger(ApplicationController.class); - private final List<Application> applications = new ArrayList<>(); + private final List<ApplicationDto> applications = new ArrayList<>(); @Override - public ResponseEntity<List<Application>> getAllApplications() { + public ResponseEntity<List<ApplicationDto>> getAllApplications() { log.debug("getAllApplications() called"); return new ResponseEntity<>(applications, HttpStatus.OK); } @Override - public ResponseEntity<Application> createApplication(CreateApplicationRequest createApplicationRequest) { + public ResponseEntity<ApplicationDto> createApplication(ApplicationCreateDto applicationCreateDto) { log.debug("createApplication() called"); - var application = new Application() + var application = new ApplicationDto() .id(getNewId()) - .name(createApplicationRequest.getName()) - .surname(createApplicationRequest.getSurname()) - .birthday(createApplicationRequest.getBirthday()) - .fillingOutDate(createApplicationRequest.getFillingOutDate()); + .name(applicationCreateDto.getName()) + .surname(applicationCreateDto.getSurname()) + .birthday(applicationCreateDto.getBirthday()) + .fillingOutDate(applicationCreateDto.getFillingOutDate()); applications.add(application); @@ -46,8 +46,8 @@ public class ApplicationController implements ApplicationServiceApiDelegate { } @Override - public ResponseEntity<Application> getApplication(Integer id) { - Application application = findById(id); + public ResponseEntity<ApplicationDto> getApplication(Integer id) { + ApplicationDto application = findById(id); if (application == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); @@ -57,19 +57,19 @@ public class ApplicationController implements ApplicationServiceApiDelegate { } @Override - public ResponseEntity<Application> updateApplication(Integer id, UpdateApplicationRequest updateApplicationRequest) { - Application application = findById(id); + public ResponseEntity<ApplicationDto> updateApplication(Integer id, ApplicationUpdateDto applicationUpdateDto) { + ApplicationDto application = findById(id); if(application == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } - application.setStatus(updateApplicationRequest.getStatus()); + application.setStatus(applicationUpdateDto.getStatus()); return new ResponseEntity<>(application, HttpStatus.OK); } - private Application findById(int id) { - for (Application a : applications){ + private ApplicationDto findById(int id) { + for (ApplicationDto a : applications){ if (a.getId() == id) { return a; } @@ -79,11 +79,9 @@ public class ApplicationController implements ApplicationServiceApiDelegate { private int getNewId(){ int highestId = 0; - - for (Application application : applications) { + for (ApplicationDto application : applications) { if(application.getId() > highestId) highestId = application.getId(); } - return highestId + 1; } } diff --git a/application/src/test/java/cz/muni/pa165/rest/ApplicationControllerTest.java b/application/src/test/java/cz/muni/pa165/rest/ApplicationControllerTest.java index d460867..c38c3df 100644 --- a/application/src/test/java/cz/muni/pa165/rest/ApplicationControllerTest.java +++ b/application/src/test/java/cz/muni/pa165/rest/ApplicationControllerTest.java @@ -1,9 +1,9 @@ package cz.muni.pa165.rest; -import cz.muni.pa165.generated.model.Application; +import cz.muni.pa165.generated.model.ApplicationDto; import cz.muni.pa165.generated.model.ApplicationStatus; -import cz.muni.pa165.generated.model.CreateApplicationRequest; -import cz.muni.pa165.generated.model.UpdateApplicationRequest; +import cz.muni.pa165.generated.model.ApplicationCreateDto; +import cz.muni.pa165.generated.model.ApplicationUpdateDto; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -26,10 +26,10 @@ class ApplicationControllerTest { void testCreateApplication() { log.debug("testing createApplication()"); - ResponseEntity<Application> created = controller.createApplication(getCreateApplicationRequest()); + ResponseEntity<ApplicationDto> created = controller.createApplication(getCreateApplicationRequest()); assertEquals(HttpStatus.OK, created.getStatusCode()); - Application createdApplication = created.getBody(); + ApplicationDto createdApplication = created.getBody(); assertNotEquals(null, createdApplication); assert createdApplication != null; @@ -43,17 +43,17 @@ class ApplicationControllerTest { void testGetApplication() { log.debug("testing getApplication()"); - ResponseEntity<Application> created = controller.createApplication(getCreateApplicationRequest()); + ResponseEntity<ApplicationDto> created = controller.createApplication(getCreateApplicationRequest()); assertEquals(HttpStatus.OK, created.getStatusCode()); - Application createdApplication = created.getBody(); + ApplicationDto createdApplication = created.getBody(); assertNotEquals(null, createdApplication); assert createdApplication != null; - ResponseEntity<Application> received = controller.getApplication(createdApplication.getId()); + ResponseEntity<ApplicationDto> received = controller.getApplication(createdApplication.getId()); assertEquals(HttpStatus.OK, received.getStatusCode()); - Application receivedApplication = received.getBody(); + ApplicationDto receivedApplication = received.getBody(); assertNotEquals(null, receivedApplication); assert receivedApplication != null; @@ -67,7 +67,7 @@ class ApplicationControllerTest { void testGetNonExistingApplication() { log.debug("testing getNonExistingApplication()"); - ResponseEntity<Application> nonExistent = controller.getApplication(-1); + ResponseEntity<ApplicationDto> nonExistent = controller.getApplication(-1); assertEquals(HttpStatus.NOT_FOUND, nonExistent.getStatusCode()); } @@ -75,18 +75,18 @@ class ApplicationControllerTest { void testUpdateRejectApplication() { log.debug("testing updateRejectApplication()"); - ResponseEntity<Application> created = controller.createApplication(getCreateApplicationRequest()); + ResponseEntity<ApplicationDto> created = controller.createApplication(getCreateApplicationRequest()); assertEquals(HttpStatus.OK, created.getStatusCode()); - Application createdApplication = created.getBody(); + ApplicationDto createdApplication = created.getBody(); assertNotEquals(null, createdApplication); assert createdApplication != null; - ResponseEntity<Application> rejected = controller.updateApplication(createdApplication.getId(), - new UpdateApplicationRequest().status(ApplicationStatus.REJECTED)); + ResponseEntity<ApplicationDto> rejected = controller.updateApplication(createdApplication.getId(), + new ApplicationUpdateDto().status(ApplicationStatus.REJECTED)); assertEquals(HttpStatus.OK, rejected.getStatusCode()); - Application rejectedApplication = rejected.getBody(); + ApplicationDto rejectedApplication = rejected.getBody(); assertNotEquals(null, rejectedApplication); assert rejectedApplication != null; @@ -97,18 +97,18 @@ class ApplicationControllerTest { void testUpdateAcceptApplication() { log.debug("testing updateAcceptApplication()"); - ResponseEntity<Application> created = controller.createApplication(getCreateApplicationRequest()); + ResponseEntity<ApplicationDto> created = controller.createApplication(getCreateApplicationRequest()); assertEquals(HttpStatus.OK, created.getStatusCode()); - Application createdApplication = created.getBody(); + ApplicationDto createdApplication = created.getBody(); assertNotEquals(null, createdApplication); assert createdApplication != null; - ResponseEntity<Application> accepted = controller.updateApplication(createdApplication.getId(), - new UpdateApplicationRequest().status(ApplicationStatus.ACCEPTED)); + ResponseEntity<ApplicationDto> accepted = controller.updateApplication(createdApplication.getId(), + new ApplicationUpdateDto().status(ApplicationStatus.ACCEPTED)); assertEquals(HttpStatus.OK, accepted.getStatusCode()); - Application acceptedApplication = accepted.getBody(); + ApplicationDto acceptedApplication = accepted.getBody(); assertNotEquals(null, acceptedApplication); assert acceptedApplication != null; @@ -119,8 +119,8 @@ class ApplicationControllerTest { void testUpdateNonExistingApplication() { log.debug("testing updateNonExistingApplication()"); - ResponseEntity<Application> accepted = controller.updateApplication(-123, - new UpdateApplicationRequest().status(ApplicationStatus.ACCEPTED)); + ResponseEntity<ApplicationDto> accepted = controller.updateApplication(-123, + new ApplicationUpdateDto().status(ApplicationStatus.ACCEPTED)); assertEquals(HttpStatus.NOT_FOUND, accepted.getStatusCode()); } @@ -128,32 +128,32 @@ class ApplicationControllerTest { void testGetAllApplications() { log.debug("testing getAllApplications()"); - ResponseEntity<Application> created = controller.createApplication(getCreateApplicationRequest()); + ResponseEntity<ApplicationDto> created = controller.createApplication(getCreateApplicationRequest()); assertEquals(HttpStatus.OK, created.getStatusCode()); - Application createdApplication = created.getBody(); + ApplicationDto createdApplication = created.getBody(); assertNotEquals(null, createdApplication); assert createdApplication != null; - ResponseEntity<Application> created2 = controller.createApplication(getCreateApplicationRequest()); + ResponseEntity<ApplicationDto> created2 = controller.createApplication(getCreateApplicationRequest()); assertEquals(HttpStatus.OK, created2.getStatusCode()); - Application createdApplication2 = created2.getBody(); + ApplicationDto createdApplication2 = created2.getBody(); assertNotEquals(null, createdApplication2); assert createdApplication2 != null; - ResponseEntity<List<Application>> received = controller.getAllApplications(); + ResponseEntity<List<ApplicationDto>> received = controller.getAllApplications(); assertEquals(HttpStatus.OK, received.getStatusCode()); - List<Application> receivedApplications = received.getBody(); + List<ApplicationDto> receivedApplications = received.getBody(); assertNotEquals(null, receivedApplications); assert receivedApplications != null; assertEquals(Arrays.asList(createdApplication, createdApplication2), receivedApplications); } - private CreateApplicationRequest getCreateApplicationRequest() { - return new CreateApplicationRequest() + private ApplicationCreateDto getCreateApplicationRequest() { + return new ApplicationCreateDto() .name("John") .surname("Doe") .birthday(LocalDate.of(1990, 1, 1)) diff --git a/core/openapi.yaml b/core/openapi.yaml index 2ac7d1c..b49388d 100644 --- a/core/openapi.yaml +++ b/core/openapi.yaml @@ -22,7 +22,7 @@ components: - frontWing - suspension - CarComponent: + CarComponentDto: type: object title: Component description: Component of a car @@ -45,8 +45,34 @@ components: type: string description: Specific information about component example: lightweight front wing v2 (black) + CarComponentCreateDto: + type: object + properties: + componentType: + $ref: '#/components/schemas/CarComponentType' + weight: + type: number + description: Component's weight + information: + type: string + description: Specific information about component + required: + - componentType + - weight + - information + CarComponentUpdateDto: + type: object + properties: + componentType: + $ref: '#/components/schemas/CarComponentType' + weight: + type: number + description: car's weight + information: + type: string + description: Specific information about component - Car: + CarDto: type: object title: Car description: Formula @@ -61,27 +87,27 @@ components: type: array description: List of components in the car items: - $ref: '#/components/schemas/CarComponent' + $ref: '#/components/schemas/CarComponentDto' driver: - $ref: '#/components/schemas/Driver' - CreateCarRequest: + $ref: '#/components/schemas/DriverDto' + CarCreateDto: type: object properties: components: type: array description: List of components in the car items: - $ref: '#/components/schemas/CarComponent' + $ref: '#/components/schemas/CarComponentDto' required: - components - UpdateCarRequest: + CarUpdateDto: type: object properties: components: type: array description: List of components in the car items: - $ref: '#/components/schemas/CarComponent' + $ref: '#/components/schemas/CarComponentDto' required: - components @@ -101,7 +127,7 @@ components: - excellent in the corners - excellent in straight lines - Driver: + DriverDto: type: object title: Driver description: Driver of a car @@ -144,8 +170,59 @@ components: description: Set of driver's characteristics items: $ref: '#/components/schemas/Characteristic' + DriverUpdateDto: + type: object + properties: + name: + type: string + description: Name of the driver + surname: + type: string + description: Name of the driver + nationality: + type: string + description: nationality of the driver + height: + type: integer + description: Height in cm + characteristics: + type: array + description: Set of driver's characteristics + items: + $ref: '#/components/schemas/Characteristic' + DriverCreateDto: + type: object + properties: + name: + type: string + description: Name of the driver + surname: + type: string + description: Name of the driver + nationality: + type: string + description: Nationality of the driver + height: + type: integer + description: Height in cm + birthday: + type: string + description: Date of birth + format: date + example: 1997-09-30 + nullable: true + characteristics: + type: array + description: Set of driver's characteristics + items: + $ref: '#/components/schemas/Characteristic' + required: + - name + - surname + - nationality + - characteristics - Engineer: + EngineerDto: type: object title: Engineer description: Engineer from a department @@ -166,7 +243,7 @@ components: description: Surname of the engineer example: Doe - Department: + DepartmentDto: type: object title: Department description: Department @@ -179,9 +256,26 @@ components: type: array description: List of engineers belonging to the department items: - $ref: '#/components/schemas/Engineer' + $ref: '#/components/schemas/EngineerDto' specialization: type: string + DepartmentUpdateDto: + type: object + properties: + specialization: + type: string + description: New specialization + DepartmentCreateDto: + type: object + properties: + engineers: + type: array + description: List of engineers belonging to the department + items: + $ref: '#/components/schemas/EngineerDto' + specialization: + type: string + responses: NotFound: description: The specified resource was not found @@ -228,43 +322,14 @@ paths: content: application/json: schema: - type: object - properties: - name: - type: string - description: Name of the driver - surname: - type: string - description: Name of the driver - nationality: - type: string - description: Nationality of the driver - height: - type: integer - description: Height in cm - birthday: - type: string - description: Date of birth - format: date - example: 1997-09-30 - nullable: true - characteristics: - type: array - description: Set of driver's characteristics - items: - $ref: '#/components/schemas/Characteristic' - required: - - name - - surname - - nationality - - characteristics + $ref: '#/components/schemas/DriverCreateDto' responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/Driver' + $ref: '#/components/schemas/DriverDto' default: $ref: '#/components/responses/Unexpected' get: @@ -280,7 +345,7 @@ paths: schema: type: array items: - $ref: '#/components/schemas/Driver' + $ref: '#/components/schemas/DriverDto' default: $ref: '#/components/responses/Unexpected' patch: @@ -288,43 +353,27 @@ paths: - DriverService summary: Updates driver with the given id operationId: updateDriver + parameters: + - in: path + name: id + schema: + type: integer + required: true + description: "ID of driver" requestBody: description: Request body for updating driver required: true content: application/json: schema: - type: object - properties: - id: - type: integer - description: Id of the driver - name: - type: string - description: Name of the driver - surname: - type: string - description: Name of the driver - nationality: - type: string - description: nationality of the driver - height: - type: integer - description: Height in cm - characteristics: - type: array - description: Set of driver's characteristics - items: - $ref: '#/components/schemas/Characteristic' - required: - - id + $ref: '#/components/schemas/DriverUpdateDto' responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/Driver' + $ref: '#/components/schemas/DriverDto' "404": $ref: '#/components/responses/NotFound' default: @@ -343,7 +392,7 @@ paths: schema: type: array items: - $ref: '#/components/schemas/Driver' + $ref: '#/components/schemas/DriverDto' default: $ref: '#/components/responses/Unexpected' /driver/{id}: @@ -360,7 +409,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/Driver' + $ref: '#/components/schemas/DriverDto' "404": $ref: '#/components/responses/NotFound' default: @@ -392,14 +441,14 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/CreateCarRequest' + $ref: '#/components/schemas/CarCreateDto' responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/Car' + $ref: '#/components/schemas/CarDto' default: $ref: '#/components/responses/Unexpected' /car/{id}: @@ -416,7 +465,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/Car' + $ref: '#/components/schemas/CarDto' "404": $ref: '#/components/responses/NotFound' default: @@ -434,19 +483,14 @@ paths: content: application/json: schema: - type: object - properties: - driver: - $ref: '#/components/schemas/Driver' - required: - - driver + $ref: '#/components/schemas/DriverDto' responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/Car' + $ref: '#/components/schemas/CarDto' "404": $ref: '#/components/responses/NotFound' default: @@ -464,14 +508,14 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/UpdateCarRequest' + $ref: '#/components/schemas/CarUpdateDto' responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/Car' + $ref: '#/components/schemas/CarDto' "404": $ref: '#/components/responses/NotFound' default: @@ -505,7 +549,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/CarComponent' + $ref: '#/components/schemas/CarComponentDto' "404": $ref: '#/components/responses/NotFound' default: @@ -537,23 +581,14 @@ paths: content: application/json: schema: - type: object - properties: - componentType: - $ref: '#/components/schemas/CarComponentType' - weight: - type: number - description: car's weight - information: - type: string - description: Specific information about component + $ref: '#/components/schemas/CarComponentUpdateDto' responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/CarComponent' + $ref: '#/components/schemas/CarComponentDto' "404": $ref: '#/components/responses/NotFound' default: @@ -573,7 +608,7 @@ paths: schema: type: array items: - $ref: '#/components/schemas/CarComponent' + $ref: '#/components/schemas/CarComponentDto' default: $ref: '#/components/responses/Unexpected' post: @@ -587,27 +622,14 @@ paths: content: application/json: schema: - type: object - properties: - componentType: - $ref: '#/components/schemas/CarComponentType' - weight: - type: number - description: Component's weight - information: - type: string - description: Specific information about component - required: - - componentType - - weight - - information + $ref: '#/components/schemas/CarComponentCreateDto' responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/CarComponent' + $ref: '#/components/schemas/CarComponentDto' default: $ref: '#/components/responses/Unexpected' @@ -627,7 +649,7 @@ paths: schema: type: array items: - $ref: '#/components/schemas/CarComponent' + $ref: '#/components/schemas/CarComponentDto' default: $ref: '#/components/responses/Unexpected' @@ -650,7 +672,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/Department' + $ref: '#/components/schemas/DepartmentDto' "404": $ref: '#/components/responses/NotFound' default: @@ -673,14 +695,14 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/Engineer' + $ref: '#/components/schemas/EngineerDto' responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/Department' + $ref: '#/components/schemas/DepartmentDto' "404": $ref: '#/components/responses/NotFound' default: @@ -703,7 +725,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/Department' + $ref: '#/components/schemas/DepartmentDto' "404": $ref: '#/components/responses/NotFound' default: @@ -726,18 +748,14 @@ paths: content: application/json: schema: - type: object - properties: - specialization: - type: string - description: New specialization + $ref: '#/components/schemas/DepartmentUpdateDto' responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/Department' + $ref: '#/components/schemas/DepartmentDto' "404": $ref: '#/components/responses/NotFound' default: @@ -756,7 +774,7 @@ paths: schema: type: array items: - $ref: '#/components/schemas/Department' + $ref: '#/components/schemas/DepartmentDto' "404": $ref: '#/components/responses/NotFound' default: @@ -772,14 +790,14 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/Department' + $ref: '#/components/schemas/DepartmentCreateDto' responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/Department' + $ref: '#/components/schemas/DepartmentDto' "404": $ref: '#/components/responses/NotFound' default: diff --git a/core/src/main/java/cz/muni/pa165/rest/CarComponentController.java b/core/src/main/java/cz/muni/pa165/rest/CarComponentController.java index 82342d1..6fb3d60 100644 --- a/core/src/main/java/cz/muni/pa165/rest/CarComponentController.java +++ b/core/src/main/java/cz/muni/pa165/rest/CarComponentController.java @@ -17,11 +17,11 @@ public class CarComponentController implements CarComponentServiceApiDelegate { private static final Logger log = LoggerFactory.getLogger(CarComponentController.class); - private final List<CarComponent> carComponents = new ArrayList<>(); + private final List<CarComponentDto> carComponents = new ArrayList<>(); @Override - public ResponseEntity<CarComponent> getCarComponent(Integer id) { + public ResponseEntity<CarComponentDto> getCarComponent(Integer id) { log.debug("getCarComponent() called"); if(findById(id) != null){ @@ -31,11 +31,11 @@ public class CarComponentController implements CarComponentServiceApiDelegate { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } - public ResponseEntity<List<CarComponent>> getAllCarComponents() { + public ResponseEntity<List<CarComponentDto>> getAllCarComponents() { return new ResponseEntity<>(carComponents, HttpStatus.OK); } - public ResponseEntity<List<CarComponent>> getCarComponentsByType(CarComponentType carComponentType) { + public ResponseEntity<List<CarComponentDto>> getCarComponentsByType(CarComponentType carComponentType) { return new ResponseEntity<>( carComponents.stream().filter(component -> component.getComponentType() == carComponentType).collect(Collectors.toList()), HttpStatus.OK @@ -43,14 +43,14 @@ public class CarComponentController implements CarComponentServiceApiDelegate { } @Override - public ResponseEntity<CarComponent> createCarComponent(CreateCarComponentRequest createCarComponentRequest) { + public ResponseEntity<CarComponentDto> createCarComponent(CarComponentCreateDto carComponentCreateDto) { log.debug("createCarComponent() called"); - CarComponent component = new CarComponent() + CarComponentDto component = new CarComponentDto() .id(getNewId()) - .componentType(createCarComponentRequest.getComponentType()) - .weight(createCarComponentRequest.getWeight()) - .information(createCarComponentRequest.getInformation()); + .componentType(carComponentCreateDto.getComponentType()) + .weight(carComponentCreateDto.getWeight()) + .information(carComponentCreateDto.getInformation()); carComponents.add(component); return new ResponseEntity<>(component, HttpStatus.OK); @@ -60,7 +60,7 @@ public class CarComponentController implements CarComponentServiceApiDelegate { public ResponseEntity<Void> deleteCarComponent(Integer id) { log.debug("deleteCarComponent() called"); - CarComponent component = findById(id); + CarComponentDto component = findById(id); if (component == null){ return new ResponseEntity<>(HttpStatus.NOT_FOUND); @@ -72,23 +72,23 @@ public class CarComponentController implements CarComponentServiceApiDelegate { } @Override - public ResponseEntity<CarComponent> updateCarComponent(Integer id, UpdateCarComponentRequest updateCarComponentRequest) { + public ResponseEntity<CarComponentDto> updateCarComponent(Integer id, CarComponentUpdateDto carComponentUpdateDto) { log.debug("updateCarComponent() called"); - CarComponent component = findById(id); + CarComponentDto component = findById(id); if (component == null){ return new ResponseEntity<>(HttpStatus.NOT_FOUND); } - if (updateCarComponentRequest.getComponentType() != null){ - component.componentType(updateCarComponentRequest.getComponentType()); + if (carComponentUpdateDto.getComponentType() != null){ + component.componentType(carComponentUpdateDto.getComponentType()); } - if (updateCarComponentRequest.getWeight() != null){ - component.weight(updateCarComponentRequest.getWeight()); + if (carComponentUpdateDto.getWeight() != null){ + component.weight(carComponentUpdateDto.getWeight()); } - if (updateCarComponentRequest.getInformation() != null){ - component.information(updateCarComponentRequest.getInformation()); + if (carComponentUpdateDto.getInformation() != null){ + component.information(carComponentUpdateDto.getInformation()); } carComponents.remove(findById(id)); @@ -98,8 +98,8 @@ public class CarComponentController implements CarComponentServiceApiDelegate { } - private CarComponent findById(int id) { - for (CarComponent c : carComponents){ + private CarComponentDto findById(int id) { + for (CarComponentDto c : carComponents){ if (c.getId() == id) { return c; } @@ -108,13 +108,10 @@ public class CarComponentController implements CarComponentServiceApiDelegate { } private int getNewId(){ - int highestId = 0; - - for (CarComponent c : carComponents) { + for (CarComponentDto c : carComponents) { if(c.getId() > highestId) highestId = c.getId(); } - return highestId + 1; } } diff --git a/core/src/main/java/cz/muni/pa165/rest/CarController.java b/core/src/main/java/cz/muni/pa165/rest/CarController.java index c85e0a9..1b020d3 100644 --- a/core/src/main/java/cz/muni/pa165/rest/CarController.java +++ b/core/src/main/java/cz/muni/pa165/rest/CarController.java @@ -14,32 +14,32 @@ import java.util.List; @Component public class CarController implements CarServiceApiDelegate { - private final List<Car> cars = new ArrayList<>(); + private final List<CarDto> cars = new ArrayList<>(); private static final Logger log = LoggerFactory.getLogger(CarController.class); @Override - public ResponseEntity<Car> createCar(CreateCarRequest createCarRequest) { + public ResponseEntity<CarDto> createCar(CarCreateDto carCreateDto) { log.debug("createCar() called"); - Car car = new Car() + CarDto car = new CarDto() .id(getNewId()) - .components(createCarRequest.getComponents()); + .components(carCreateDto.getComponents()); cars.add(car); return new ResponseEntity<>(car, HttpStatus.OK); } @Override - public ResponseEntity<Car> setDriver(Integer id, SetDriverRequest setDriverRequest) { + public ResponseEntity<CarDto> setDriver(Integer id, DriverDto driverDto) { log.debug("setDriver() called"); - Car car = findById(id); + CarDto car = findById(id); if(car == null){ return new ResponseEntity<>(HttpStatus.NOT_FOUND); } - car.driver(setDriverRequest.getDriver()); + car.driver(driverDto); cars.remove(findById(id)); cars.add(car); @@ -47,10 +47,10 @@ public class CarController implements CarServiceApiDelegate { } @Override - public ResponseEntity<Car> getCar(Integer id) { + public ResponseEntity<CarDto> getCar(Integer id) { log.debug("getCar() called"); - Car car = findById(id); + CarDto car = findById(id); if(car == null){ return new ResponseEntity<>(HttpStatus.NOT_FOUND); @@ -63,7 +63,7 @@ public class CarController implements CarServiceApiDelegate { public ResponseEntity<Void> deleteCar(Integer id) { log.debug("deleteCar() called"); - Car car = findById(id); + CarDto car = findById(id); if(car == null){ return new ResponseEntity<>(HttpStatus.NOT_FOUND); @@ -75,16 +75,16 @@ public class CarController implements CarServiceApiDelegate { } @Override - public ResponseEntity<Car> updateCar(Integer id, UpdateCarRequest updateCarRequest) { + public ResponseEntity<CarDto> updateCar(Integer id, CarUpdateDto carUpdateDto) { log.debug("updateCar() called"); - Car car = findById(id); + CarDto car = findById(id); if(car == null){ return new ResponseEntity<>(HttpStatus.NOT_FOUND); } - car.components(updateCarRequest.getComponents()); + car.components(carUpdateDto.getComponents()); cars.remove(findById(id)); cars.add(car); @@ -92,8 +92,8 @@ public class CarController implements CarServiceApiDelegate { return new ResponseEntity<>(car, HttpStatus.OK); } - private Car findById(int id) { - for (Car car : cars){ + private CarDto findById(int id) { + for (CarDto car : cars){ if (car.getId() == id) { return car; } @@ -102,13 +102,10 @@ public class CarController implements CarServiceApiDelegate { } private int getNewId(){ - int highestId = 0; - - for (Car car : cars) { + for (CarDto car : cars) { if(car.getId() > highestId) highestId = car.getId(); } - return highestId + 1; } } diff --git a/core/src/main/java/cz/muni/pa165/rest/DepartmentController.java b/core/src/main/java/cz/muni/pa165/rest/DepartmentController.java index 6e85466..06f560e 100644 --- a/core/src/main/java/cz/muni/pa165/rest/DepartmentController.java +++ b/core/src/main/java/cz/muni/pa165/rest/DepartmentController.java @@ -1,9 +1,10 @@ package cz.muni.pa165.rest; import cz.muni.pa165.generated.core.api.DepartmentServiceApiDelegate; -import cz.muni.pa165.generated.core.model.Department; -import cz.muni.pa165.generated.core.model.Engineer; -import cz.muni.pa165.generated.core.model.UpdateSpecializationRequest; +import cz.muni.pa165.generated.core.model.DepartmentDto; +import cz.muni.pa165.generated.core.model.DepartmentUpdateDto; +import cz.muni.pa165.generated.core.model.DepartmentCreateDto; +import cz.muni.pa165.generated.core.model.EngineerDto; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; @@ -21,40 +22,40 @@ import java.util.List; public class DepartmentController implements DepartmentServiceApiDelegate { private static final Logger log = LoggerFactory.getLogger(DepartmentController.class); - private final List<Department> departments = new ArrayList<>(); + private final List<DepartmentDto> departments = new ArrayList<>(); @Override - public ResponseEntity<Department> addEngineer(Integer departmentId, Engineer engineer) { + public ResponseEntity<DepartmentDto> addEngineer(Integer departmentId, EngineerDto engineerDto) { log.debug("addEngineer() called"); - Department department = findById(departmentId); + DepartmentDto department = findById(departmentId); if(department == null){ return new ResponseEntity<>(HttpStatus.NOT_FOUND); } - department.addEngineersItem(engineer); + department.addEngineersItem(engineerDto); return new ResponseEntity<>(department, HttpStatus.OK); } @Override - public ResponseEntity<Department> createDepartment(Department departmentFromRequest) { + public ResponseEntity<DepartmentDto> createDepartment(DepartmentCreateDto departmentCreateDto) { log.debug("createDepartment() called"); - Department department = new Department() + DepartmentDto department = new DepartmentDto() .id(departments.size()) - .specialization(departmentFromRequest.getSpecialization()) - .engineers(departmentFromRequest.getEngineers()); + .specialization(departmentCreateDto.getSpecialization()) + .engineers(departmentCreateDto.getEngineers()); departments.add(department); return new ResponseEntity<>(department, HttpStatus.OK); } @Override - public ResponseEntity<Department> deleteDepartment(Integer departmentId) { + public ResponseEntity<DepartmentDto> deleteDepartment(Integer departmentId) { log.debug("deleteDepartment() called"); - Department department = findById(departmentId); + DepartmentDto department = findById(departmentId); if (department == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); @@ -65,10 +66,10 @@ public class DepartmentController implements DepartmentServiceApiDelegate { } @Override - public ResponseEntity<Department> getDepartment(Integer departmentId) { + public ResponseEntity<DepartmentDto> getDepartment(Integer departmentId) { log.debug("getDepartment() called"); - Department department = findById(departmentId); + DepartmentDto department = findById(departmentId); if (department == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); @@ -77,26 +78,26 @@ public class DepartmentController implements DepartmentServiceApiDelegate { } @Override - public ResponseEntity<List<Department>> getDepartments() { + public ResponseEntity<List<DepartmentDto>> getDepartments() { log.debug("getDepartments() called"); return new ResponseEntity<>(departments, HttpStatus.OK); } @Override - public ResponseEntity<Department> updateSpecialization(Integer departmentId, UpdateSpecializationRequest updateSpecializationRequest) { + public ResponseEntity<DepartmentDto> updateSpecialization(Integer departmentId, DepartmentUpdateDto departmentUpdateDto) { log.debug("updateSpecialization() called"); - Department department = findById(departmentId); + DepartmentDto department = findById(departmentId); if (department == null) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } - department.specialization(updateSpecializationRequest.getSpecialization()); + department.specialization(departmentUpdateDto.getSpecialization()); return new ResponseEntity<>(department, HttpStatus.OK); } - private Department findById(int id) { - for (Department department : departments){ + private DepartmentDto findById(int id) { + for (DepartmentDto department : departments){ if (department.getId() == id) { return department; } diff --git a/core/src/main/java/cz/muni/pa165/rest/DriverController.java b/core/src/main/java/cz/muni/pa165/rest/DriverController.java index 1e00cc3..ffee32e 100644 --- a/core/src/main/java/cz/muni/pa165/rest/DriverController.java +++ b/core/src/main/java/cz/muni/pa165/rest/DriverController.java @@ -18,7 +18,7 @@ import java.util.List; public class DriverController implements DriverServiceApiDelegate { private static final Logger log = LoggerFactory.getLogger(DriverController.class); - private final List<Driver> drivers = new ArrayList<>(); + private final List<DriverDto> drivers = new ArrayList<>(); @Override public ResponseEntity<Void> deleteDriver(Integer id) { @@ -32,48 +32,48 @@ public class DriverController implements DriverServiceApiDelegate { } @Override - public ResponseEntity<List<Driver>> getAllTestDrivers() { + public ResponseEntity<List<DriverDto>> getAllTestDrivers() { log.debug("getAllTestDrivers() called"); return new ResponseEntity<>(drivers, HttpStatus.OK); } @Override - public ResponseEntity<Driver> updateDriver(UpdateDriverRequest updateDriverRequest) { + public ResponseEntity<DriverDto> updateDriver(Integer id, DriverUpdateDto driverUpdateDto) { log.debug("updateDriver() called"); - Driver driver = findById(updateDriverRequest.getId()); + DriverDto driver = findById(id); if (driver == null){ return new ResponseEntity<>(HttpStatus.NOT_FOUND); } - if (updateDriverRequest.getName() != null){ - driver.name(updateDriverRequest.getName()); + if (driverUpdateDto.getName() != null){ + driver.name(driverUpdateDto.getName()); } - if (updateDriverRequest.getSurname() != null){ - driver.surname(updateDriverRequest.getSurname()); + if (driverUpdateDto.getSurname() != null){ + driver.surname(driverUpdateDto.getSurname()); } - if (updateDriverRequest.getNationality() != null){ - driver.nationality(updateDriverRequest.getNationality()); + if (driverUpdateDto.getNationality() != null){ + driver.nationality(driverUpdateDto.getNationality()); } - if (updateDriverRequest.getHeight() != null){ - driver.height(updateDriverRequest.getHeight()); + if (driverUpdateDto.getHeight() != null){ + driver.height(driverUpdateDto.getHeight()); } - if (updateDriverRequest.getCharacteristics() != null){ - driver.characteristics(updateDriverRequest.getCharacteristics()); + if (driverUpdateDto.getCharacteristics() != null){ + driver.characteristics(driverUpdateDto.getCharacteristics()); } - drivers.remove(findById(updateDriverRequest.getId())); + drivers.remove(findById(id)); drivers.add(driver); return new ResponseEntity<>(driver, HttpStatus.OK); } @Override - public ResponseEntity<List<Driver>> getAllDrivers() { + public ResponseEntity<List<DriverDto>> getAllDrivers() { log.debug("getAllDriver() called"); return new ResponseEntity<>(drivers, HttpStatus.OK); } @Override - public ResponseEntity<Driver> getDriver(Integer id) { + public ResponseEntity<DriverDto> getDriver(Integer id) { log.debug("getDriver() called"); if(findById(id) != null){ @@ -84,24 +84,24 @@ public class DriverController implements DriverServiceApiDelegate { } @Override - public ResponseEntity<Driver> createDriver(CreateDriverRequest createDriverRequest) { + public ResponseEntity<DriverDto> createDriver(DriverCreateDto driverCreateDto) { log.debug("addDriver() called"); - var driver = new Driver() + var driver = new DriverDto() .id(getNewId()) - .name(createDriverRequest.getName()) - .surname(createDriverRequest.getSurname()) - .birthday(createDriverRequest.getBirthday().get()) - .height(createDriverRequest.getHeight()) - .nationality(createDriverRequest.getNationality()) - .characteristics(createDriverRequest.getCharacteristics()); + .name(driverCreateDto.getName()) + .surname(driverCreateDto.getSurname()) + .birthday(driverCreateDto.getBirthday().get()) + .height(driverCreateDto.getHeight()) + .nationality(driverCreateDto.getNationality()) + .characteristics(driverCreateDto.getCharacteristics()); drivers.add(driver); return new ResponseEntity<>(driver, HttpStatus.OK); } - private Driver findById(int id) { - for (Driver d : drivers){ + private DriverDto findById(int id) { + for (DriverDto d : drivers){ if (d.getId() == id) { return d; } @@ -110,13 +110,10 @@ public class DriverController implements DriverServiceApiDelegate { } private int getNewId(){ - int highestId = 0; - - for (Driver driver : drivers) { + for (DriverDto driver : drivers) { if(driver.getId() > highestId) highestId = driver.getId(); } - return highestId + 1; } } diff --git a/core/src/test/java/cz/muni/pa165/rest/CarComponentControllerTest.java b/core/src/test/java/cz/muni/pa165/rest/CarComponentControllerTest.java index 5364cdb..a4252db 100644 --- a/core/src/test/java/cz/muni/pa165/rest/CarComponentControllerTest.java +++ b/core/src/test/java/cz/muni/pa165/rest/CarComponentControllerTest.java @@ -25,7 +25,7 @@ class CarComponentControllerTest { void testGetNonExistingCarComponent() { log.debug("starting testGetNonExistingComponent()"); - ResponseEntity<CarComponent> response = carComponentController.getCarComponent(1); + ResponseEntity<CarComponentDto> response = carComponentController.getCarComponent(1); assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode()); Assertions.assertNull(response.getBody()); @@ -35,16 +35,16 @@ class CarComponentControllerTest { void testGetExistingCarComponent() { log.debug("starting testGetExistingComponent()"); - CreateCarComponentRequest requestEngine = new CreateCarComponentRequest(); + CarComponentCreateDto requestEngine = new CarComponentCreateDto(); requestEngine.setComponentType(CarComponentType.ENGINE); requestEngine.setWeight(BigDecimal.valueOf(100)); requestEngine.setInformation("Test engine"); - ResponseEntity<CarComponent> created = carComponentController.createCarComponent(requestEngine); + ResponseEntity<CarComponentDto> created = carComponentController.createCarComponent(requestEngine); assertEquals(HttpStatus.OK, created.getStatusCode()); - ResponseEntity<CarComponent> received = carComponentController.getCarComponent(created.getBody().getId()); + ResponseEntity<CarComponentDto> received = carComponentController.getCarComponent(created.getBody().getId()); assertEquals(HttpStatus.OK, received.getStatusCode()); assertEquals(created, received); @@ -54,21 +54,21 @@ class CarComponentControllerTest { void testGetAllCarComponents() { log.debug("starting testGetAllComponents()"); - CreateCarComponentRequest requestEngine = new CreateCarComponentRequest(); + CarComponentCreateDto requestEngine = new CarComponentCreateDto(); requestEngine.setComponentType(CarComponentType.ENGINE); requestEngine.setWeight(BigDecimal.valueOf(100)); requestEngine.setInformation("Test engine"); carComponentController.createCarComponent(requestEngine); - CreateCarComponentRequest requestChassis = new CreateCarComponentRequest(); + CarComponentCreateDto requestChassis = new CarComponentCreateDto(); requestChassis.setComponentType(CarComponentType.CHASSIS); requestChassis.setWeight(BigDecimal.valueOf(20)); requestChassis.setInformation("Test chassis"); carComponentController.createCarComponent(requestChassis); - ResponseEntity<List<CarComponent>> response = carComponentController.getAllCarComponents(); + ResponseEntity<List<CarComponentDto>> response = carComponentController.getAllCarComponents(); assertEquals(HttpStatus.OK, response.getStatusCode()); assertEquals(2, response.getBody().size()); } @@ -77,14 +77,14 @@ class CarComponentControllerTest { void testGetCarComponentsByType() { log.debug("starting testGetComponentsByType()"); - CarComponent component1 = new CarComponent().id(1).componentType(CarComponentType.ENGINE).weight(BigDecimal.valueOf(500)).information("Engine information"); - CarComponent component2 = new CarComponent().id(2).componentType(CarComponentType.FRONTWING).weight(BigDecimal.valueOf(20)).information("Frontwing information"); - CarComponent component3 = new CarComponent().id(3).componentType(CarComponentType.ENGINE).weight(BigDecimal.valueOf(550)).information("Engine information"); + CarComponentDto component1 = new CarComponentDto().id(1).componentType(CarComponentType.ENGINE).weight(BigDecimal.valueOf(500)).information("Engine information"); + CarComponentDto component2 = new CarComponentDto().id(2).componentType(CarComponentType.FRONTWING).weight(BigDecimal.valueOf(20)).information("Frontwing information"); + CarComponentDto component3 = new CarComponentDto().id(3).componentType(CarComponentType.ENGINE).weight(BigDecimal.valueOf(550)).information("Engine information"); carComponentController.getAllCarComponents().getBody().add(component1); carComponentController.getAllCarComponents().getBody().add(component2); carComponentController.getAllCarComponents().getBody().add(component3); - ResponseEntity<List<CarComponent>> response = carComponentController.getCarComponentsByType(CarComponentType.ENGINE); + ResponseEntity<List<CarComponentDto>> response = carComponentController.getCarComponentsByType(CarComponentType.ENGINE); assertEquals(HttpStatus.OK, response.getStatusCode()); assertEquals(2, response.getBody().size()); assertTrue(response.getBody().contains(component1)); @@ -95,22 +95,22 @@ class CarComponentControllerTest { void testCreateCarComponent() { log.debug("starting testCreateComponent()"); - CreateCarComponentRequest request = new CreateCarComponentRequest(); + CarComponentCreateDto request = new CarComponentCreateDto(); request.setComponentType(CarComponentType.ENGINE); request.setWeight(BigDecimal.valueOf(100)); request.setInformation("Test engine"); - ResponseEntity<CarComponent> response = carComponentController.createCarComponent(request); + ResponseEntity<CarComponentDto> response = carComponentController.createCarComponent(request); assertEquals(HttpStatus.OK, response.getStatusCode()); - CarComponent component = response.getBody(); + CarComponentDto component = response.getBody(); assertNotNull(component); assertEquals(1, component.getId()); assertEquals(CarComponentType.ENGINE, component.getComponentType()); assertEquals(BigDecimal.valueOf(100), component.getWeight()); assertEquals("Test engine", component.getInformation()); - ResponseEntity<List<CarComponent>> getAllResponse = carComponentController.getAllCarComponents(); + ResponseEntity<List<CarComponentDto>> getAllResponse = carComponentController.getAllCarComponents(); assertEquals(HttpStatus.OK, getAllResponse.getStatusCode()); assertEquals(1, getAllResponse.getBody().size()); } @@ -128,15 +128,15 @@ class CarComponentControllerTest { void testDeleteExistingCar() { log.debug("starting testDeleteExistingCar()"); - CreateCarComponentRequest request = new CreateCarComponentRequest(); + CarComponentCreateDto request = new CarComponentCreateDto(); request.setComponentType(CarComponentType.ENGINE); request.setWeight(BigDecimal.valueOf(100)); request.setInformation("Test engine"); - ResponseEntity<CarComponent> created = carComponentController.createCarComponent(request); + ResponseEntity<CarComponentDto> created = carComponentController.createCarComponent(request); assertEquals(HttpStatus.OK, created.getStatusCode()); - ResponseEntity<CarComponent> received = carComponentController.getCarComponent(created.getBody().getId()); + ResponseEntity<CarComponentDto> received = carComponentController.getCarComponent(created.getBody().getId()); assertEquals(HttpStatus.OK, received.getStatusCode()); ResponseEntity<Void> deletedResponse = carComponentController.deleteCarComponent(created.getBody().getId()); @@ -150,7 +150,7 @@ class CarComponentControllerTest { void testUpdateNonExistingCarComponent() { log.debug("starting testUpdateNonExistingComponent()"); - ResponseEntity<CarComponent> received = carComponentController.updateCarComponent(1, new UpdateCarComponentRequest()); + ResponseEntity<CarComponentDto> received = carComponentController.updateCarComponent(1, new CarComponentUpdateDto()); assertEquals(HttpStatus.NOT_FOUND, received.getStatusCode()); } @@ -158,15 +158,15 @@ class CarComponentControllerTest { void testUpdateExistingCarComponent() { log.debug("starting testUpdateExistingComponent()"); - CreateCarComponentRequest request = new CreateCarComponentRequest(); + CarComponentCreateDto request = new CarComponentCreateDto(); request.setComponentType(CarComponentType.ENGINE); request.setWeight(BigDecimal.valueOf(100)); request.setInformation("Test engine"); - ResponseEntity<CarComponent> created = carComponentController.createCarComponent(request); + ResponseEntity<CarComponentDto> created = carComponentController.createCarComponent(request); assertEquals(HttpStatus.OK, created.getStatusCode()); - request = new CreateCarComponentRequest(); + request = new CarComponentCreateDto(); request.setComponentType(CarComponentType.ENGINE); request.setWeight(BigDecimal.valueOf(1000)); request.setInformation("Test engine 2"); @@ -176,14 +176,14 @@ class CarComponentControllerTest { int createdID = created.getBody().getId(); - ResponseEntity<CarComponent> received = carComponentController.getCarComponent(createdID); + ResponseEntity<CarComponentDto> received = carComponentController.getCarComponent(createdID); assertEquals(HttpStatus.OK, received.getStatusCode()); - ResponseEntity<CarComponent> response = carComponentController.updateCarComponent(createdID, new UpdateCarComponentRequest() + ResponseEntity<CarComponentDto> response = carComponentController.updateCarComponent(createdID, new CarComponentUpdateDto() .componentType(CarComponentType.FRONTWING)); assertEquals(HttpStatus.OK, response.getStatusCode()); - ResponseEntity<List<CarComponent>> receivedComponents = carComponentController.getCarComponentsByType(CarComponentType.FRONTWING); + ResponseEntity<List<CarComponentDto>> receivedComponents = carComponentController.getCarComponentsByType(CarComponentType.FRONTWING); assertEquals(HttpStatus.OK, receivedComponents.getStatusCode()); assertEquals(1, receivedComponents.getBody().size()); assertEquals(createdID, receivedComponents.getBody().get(0).getId()); diff --git a/core/src/test/java/cz/muni/pa165/rest/CarControllerTest.java b/core/src/test/java/cz/muni/pa165/rest/CarControllerTest.java index 49ec7da..dacdf0a 100644 --- a/core/src/test/java/cz/muni/pa165/rest/CarControllerTest.java +++ b/core/src/test/java/cz/muni/pa165/rest/CarControllerTest.java @@ -16,24 +16,24 @@ class CarControllerTest { private static final Logger log = LoggerFactory.getLogger(CarControllerTest.class); private final CarController controller = new CarController(); - private final CreateCarRequest emptyCarRequest = new CreateCarRequest().components(new ArrayList<>()); + private final CarCreateDto emptyCarRequest = new CarCreateDto().components(new ArrayList<>()); @Test void testGetNonExistingCar() { log.debug("starting testGetNonExistingCar()"); - ResponseEntity<Car> received = controller.getCar(1); + ResponseEntity<CarDto> received = controller.getCar(1); assertEquals(HttpStatus.NOT_FOUND, received.getStatusCode()); } @Test void testGetExistingCar() { log.debug("starting testGetExistingCar()"); - ResponseEntity<Car> created = controller.createCar(emptyCarRequest); + ResponseEntity<CarDto> created = controller.createCar(emptyCarRequest); assertEquals(HttpStatus.OK, created.getStatusCode()); - ResponseEntity<Car> received = controller.getCar(created.getBody().getId()); + ResponseEntity<CarDto> received = controller.getCar(created.getBody().getId()); assertEquals(HttpStatus.OK, received.getStatusCode()); assertEquals(created, received); @@ -50,10 +50,10 @@ class CarControllerTest { @Test void testDeleteExistingCar() { log.debug("starting testDeleteExistingCar()"); - ResponseEntity<Car> created = controller.createCar(emptyCarRequest); + ResponseEntity<CarDto> created = controller.createCar(emptyCarRequest); assertEquals(HttpStatus.OK, created.getStatusCode()); - ResponseEntity<Car> received = controller.getCar(created.getBody().getId()); + ResponseEntity<CarDto> received = controller.getCar(created.getBody().getId()); assertEquals(HttpStatus.OK, received.getStatusCode()); ResponseEntity<Void> deletedResponse = controller.deleteCar(1); @@ -67,30 +67,30 @@ class CarControllerTest { void testUpdateNonExistingCar() { log.debug("starting testUpdateNonExistingCar()"); - ResponseEntity<Car> received = controller.updateCar(1, new UpdateCarRequest()); + ResponseEntity<CarDto> received = controller.updateCar(1, new CarUpdateDto()); assertEquals(HttpStatus.NOT_FOUND, received.getStatusCode()); } @Test void testUpdateExistingCar() { log.debug("starting testUpdateExistingCar()"); - ResponseEntity<Car> created = controller.createCar(emptyCarRequest); + ResponseEntity<CarDto> created = controller.createCar(emptyCarRequest); assertEquals(HttpStatus.OK, created.getStatusCode()); assertNotEquals( null, created.getBody()); var createdID = created.getBody().getId(); - ResponseEntity<Car> received = controller.getCar(createdID); + ResponseEntity<CarDto> received = controller.getCar(createdID); assertEquals(HttpStatus.OK, received.getStatusCode()); - List<CarComponent> testListOfComponents = new ArrayList<>(); - testListOfComponents.add(new CarComponent().id(5).componentType(CarComponentType.ENGINE).weight(BigDecimal.valueOf(30)).information("test")); + List<CarComponentDto> testListOfComponents = new ArrayList<>(); + testListOfComponents.add(new CarComponentDto().id(5).componentType(CarComponentType.ENGINE).weight(BigDecimal.valueOf(30)).information("test")); - ResponseEntity<Car> updatedResponse = controller.updateCar(createdID, new UpdateCarRequest() + ResponseEntity<CarDto> updatedResponse = controller.updateCar(createdID, new CarUpdateDto() .components(testListOfComponents)); assertEquals(HttpStatus.OK, updatedResponse.getStatusCode()); - ResponseEntity<Car> updatedReceived = controller.getCar(createdID); + ResponseEntity<CarDto> updatedReceived = controller.getCar(createdID); assertEquals(HttpStatus.OK, received.getStatusCode()); assertEquals(testListOfComponents, updatedReceived.getBody().getComponents()); } @@ -99,27 +99,27 @@ class CarControllerTest { void testSetDriverNonExistingCar() { log.debug("starting testSetDriverNonExistingCar()"); - ResponseEntity<Car> received = controller.setDriver(1, new SetDriverRequest().driver(new Driver())); + ResponseEntity<CarDto> received = controller.setDriver(1, new DriverDto()); assertEquals(HttpStatus.NOT_FOUND, received.getStatusCode()); } @Test void testSetDriverExistingCar() { log.debug("starting testSetDriverExistingCar()"); - ResponseEntity<Car> created = controller.createCar(emptyCarRequest); + ResponseEntity<CarDto> created = controller.createCar(emptyCarRequest); assertEquals(HttpStatus.OK, created.getStatusCode()); int createdID = created.getBody().getId(); - ResponseEntity<Car> received = controller.getCar(createdID); + ResponseEntity<CarDto> received = controller.getCar(createdID); assertEquals(HttpStatus.OK, received.getStatusCode()); - Driver driver = new Driver().id(1).name("Test").surname("Surname").height(180).addCharacteristicsItem(Characteristic.AGGRESSIVENESS); + DriverDto driver = new DriverDto().id(1).name("Test").surname("Surname").height(180).addCharacteristicsItem(Characteristic.AGGRESSIVENESS); - ResponseEntity<Car> driverResponse = controller.setDriver(createdID, new SetDriverRequest().driver(driver)); + ResponseEntity<CarDto> driverResponse = controller.setDriver(createdID, driver); assertEquals(HttpStatus.OK, driverResponse.getStatusCode()); - ResponseEntity<Car> driverReceived = controller.getCar(createdID); + ResponseEntity<CarDto> driverReceived = controller.getCar(createdID); assertEquals(HttpStatus.OK, driverReceived.getStatusCode()); assertEquals(driver, driverReceived.getBody().getDriver()); } diff --git a/core/src/test/java/cz/muni/pa165/rest/DepartmentControllerTest.java b/core/src/test/java/cz/muni/pa165/rest/DepartmentControllerTest.java index 0a507cb..2c982f1 100644 --- a/core/src/test/java/cz/muni/pa165/rest/DepartmentControllerTest.java +++ b/core/src/test/java/cz/muni/pa165/rest/DepartmentControllerTest.java @@ -1,8 +1,9 @@ package cz.muni.pa165.rest; -import cz.muni.pa165.generated.core.model.Department; -import cz.muni.pa165.generated.core.model.Engineer; -import cz.muni.pa165.generated.core.model.UpdateSpecializationRequest; +import cz.muni.pa165.generated.core.model.DepartmentCreateDto; +import cz.muni.pa165.generated.core.model.DepartmentDto; +import cz.muni.pa165.generated.core.model.EngineerDto; +import cz.muni.pa165.generated.core.model.DepartmentUpdateDto; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -17,15 +18,15 @@ class DepartmentControllerTest { private static final Logger log = LoggerFactory.getLogger(DepartmentControllerTest.class); private final DepartmentController controller = new DepartmentController(); - private final Department emptyDepartment = new Department().specialization("test"); - private final Engineer testEngineer = new Engineer().id(1).name("John").surname("Doe"); + private final DepartmentCreateDto createEmptyDepartment = new DepartmentCreateDto().specialization("test"); + private final EngineerDto testEngineer = new EngineerDto().id(1).name("John").surname("Doe"); @Test void testGetNonExistingDepartment() { log.debug("starting testGetNonExistingDepartment()"); - ResponseEntity<Department> received = controller.getDepartment(1); + ResponseEntity<DepartmentDto> received = controller.getDepartment(1); assertEquals(HttpStatus.NOT_FOUND, received.getStatusCode()); } @@ -33,7 +34,7 @@ class DepartmentControllerTest { void testCreateDepartment() { log.debug("starting testCreateDepartment()"); - ResponseEntity<Department> received = controller.createDepartment(emptyDepartment); + ResponseEntity<DepartmentDto> received = controller.createDepartment(createEmptyDepartment); assertEquals(HttpStatus.OK, received.getStatusCode()); assertEquals("test", received.getBody().getSpecialization()); } @@ -42,10 +43,10 @@ class DepartmentControllerTest { void testGetEmptyDepartment() { log.debug("starting testGetEmptyDepartment()"); - ResponseEntity<Department> created = controller.createDepartment(emptyDepartment); + ResponseEntity<DepartmentDto> created = controller.createDepartment(createEmptyDepartment); int createdID = created.getBody().getId(); - ResponseEntity<Department> received = controller.getDepartment(createdID); + ResponseEntity<DepartmentDto> received = controller.getDepartment(createdID); assertEquals(HttpStatus.OK, received.getStatusCode()); assertEquals("test", received.getBody().getSpecialization()); assertNull(received.getBody().getEngineers()); @@ -55,12 +56,12 @@ class DepartmentControllerTest { void testAddEngineers() { log.debug("starting testAddEngineers()"); - ResponseEntity<Department> created = controller.createDepartment(emptyDepartment); + ResponseEntity<DepartmentDto> created = controller.createDepartment(createEmptyDepartment); int createdID = created.getBody().getId(); controller.addEngineer(createdID, testEngineer); - ResponseEntity<Department> received = controller.getDepartment(createdID); + ResponseEntity<DepartmentDto> received = controller.getDepartment(createdID); assertEquals(HttpStatus.OK, received.getStatusCode()); assertEquals("test", received.getBody().getSpecialization()); assertEquals(1, received.getBody().getEngineers().size()); @@ -71,7 +72,7 @@ class DepartmentControllerTest { void testGetAllDepartmentsEmpty() { log.debug("starting testGetAllDepartmentsEmpty()"); - ResponseEntity<List<Department>> received = controller.getDepartments(); + ResponseEntity<List<DepartmentDto>> received = controller.getDepartments(); assertEquals(HttpStatus.OK, received.getStatusCode()); assertEquals(0, received.getBody().size()); } @@ -80,10 +81,10 @@ class DepartmentControllerTest { void testGetAllDepartments() { log.debug("starting testGetAllDepartments()"); - controller.createDepartment(emptyDepartment); - controller.createDepartment(emptyDepartment); + controller.createDepartment(createEmptyDepartment); + controller.createDepartment(createEmptyDepartment); - ResponseEntity<List<Department>> received = controller.getDepartments(); + ResponseEntity<List<DepartmentDto>> received = controller.getDepartments(); assertEquals(HttpStatus.OK, received.getStatusCode()); assertEquals(2, received.getBody().size()); assertEquals("test", received.getBody().get(0).getSpecialization()); @@ -93,14 +94,14 @@ class DepartmentControllerTest { void testUpdateSpecialization() { log.debug("starting testUpdateSpecialization()"); - ResponseEntity<Department> created = controller.createDepartment(emptyDepartment); + ResponseEntity<DepartmentDto> created = controller.createDepartment(createEmptyDepartment); int createdID = created.getBody().getId(); assertEquals("test", created.getBody().getSpecialization()); - controller.updateSpecialization(createdID, new UpdateSpecializationRequest().specialization("aerodynamics")); + controller.updateSpecialization(createdID, new DepartmentUpdateDto().specialization("aerodynamics")); - ResponseEntity<Department> received = controller.getDepartment(createdID); + ResponseEntity<DepartmentDto> received = controller.getDepartment(createdID); assertEquals(HttpStatus.OK, received.getStatusCode()); assertEquals("aerodynamics", received.getBody().getSpecialization()); } @@ -109,15 +110,15 @@ class DepartmentControllerTest { void testDeleteDepartment() { log.debug("starting testDeleteDepartment()"); - ResponseEntity<Department> created = controller.createDepartment(emptyDepartment); + ResponseEntity<DepartmentDto> created = controller.createDepartment(createEmptyDepartment); int createdID = created.getBody().getId(); - ResponseEntity<Department> received = controller.getDepartment(createdID); + ResponseEntity<DepartmentDto> received = controller.getDepartment(createdID); assertEquals(HttpStatus.OK, received.getStatusCode()); controller.deleteDepartment(createdID); - ResponseEntity<Department> receivedAfterDelete = controller.getDepartment(createdID); + ResponseEntity<DepartmentDto> receivedAfterDelete = controller.getDepartment(createdID); assertEquals(HttpStatus.NOT_FOUND, receivedAfterDelete.getStatusCode()); } @@ -125,7 +126,7 @@ class DepartmentControllerTest { void testDeleteNonExistingDepartment() { log.debug("starting testDeleteNonExistingDepartment()"); - ResponseEntity<Department> received = controller.deleteDepartment(0); + ResponseEntity<DepartmentDto> received = controller.deleteDepartment(0); assertEquals(HttpStatus.NOT_FOUND, received.getStatusCode()); } } \ No newline at end of file diff --git a/core/src/test/java/cz/muni/pa165/rest/DriverControllerTest.java b/core/src/test/java/cz/muni/pa165/rest/DriverControllerTest.java index 7a659d0..793ad2a 100644 --- a/core/src/test/java/cz/muni/pa165/rest/DriverControllerTest.java +++ b/core/src/test/java/cz/muni/pa165/rest/DriverControllerTest.java @@ -1,8 +1,8 @@ package cz.muni.pa165.rest; import cz.muni.pa165.generated.core.model.Characteristic; -import cz.muni.pa165.generated.core.model.CreateDriverRequest; -import cz.muni.pa165.generated.core.model.Driver; +import cz.muni.pa165.generated.core.model.DriverCreateDto; +import cz.muni.pa165.generated.core.model.DriverDto; import org.junit.jupiter.api.Test; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -21,7 +21,7 @@ class DriverControllerTest { @Test void createDriver() { - ResponseEntity<Driver> created = controller.createDriver(getCreateDriverRequestWithCharacteristics()); + ResponseEntity<DriverDto> created = controller.createDriver(getCreateDriverRequestWithCharacteristics()); assertEquals(HttpStatus.OK, created.getStatusCode()); assertNotEquals(null, created); assertEquals("John", created.getBody().getName()); @@ -35,13 +35,13 @@ class DriverControllerTest { @Test void deleteExistingDriver() { - ResponseEntity<Driver> created = controller.createDriver(getCreateDriverRequest()); + ResponseEntity<DriverDto> created = controller.createDriver(getCreateDriverRequest()); assertEquals(HttpStatus.OK, created.getStatusCode()); assertNotEquals(null, created); Integer driverID = created.getBody().getId(); - ResponseEntity<Driver> received = controller.getDriver(driverID); + ResponseEntity<DriverDto> received = controller.getDriver(driverID); assertEquals(HttpStatus.OK, received.getStatusCode()); assertNotEquals(null, received); @@ -54,52 +54,52 @@ class DriverControllerTest { @Test void getAllTestDrivers() { - ResponseEntity<Driver> created = controller.createDriver(getCreateDriverRequest()); + ResponseEntity<DriverDto> created = controller.createDriver(getCreateDriverRequest()); assertEquals(HttpStatus.OK, created.getStatusCode()); assertNotEquals(null, created); - ResponseEntity<Driver> created2 = controller.createDriver(getCreateDriverRequestWithCharacteristics()); + ResponseEntity<DriverDto> created2 = controller.createDriver(getCreateDriverRequestWithCharacteristics()); assertEquals(HttpStatus.OK, created.getStatusCode()); assertNotEquals(null, created); - ResponseEntity<List<Driver>> drivers = controller.getAllTestDrivers(); + ResponseEntity<List<DriverDto>> drivers = controller.getAllTestDrivers(); assertEquals(Arrays.asList(created.getBody(), created2.getBody()), drivers.getBody()); } @Test void updateDriver() { - ResponseEntity<Driver> created = controller.createDriver(getCreateDriverRequest()); + ResponseEntity<DriverDto> created = controller.createDriver(getCreateDriverRequest()); assertEquals(HttpStatus.OK, created.getStatusCode()); assertNotEquals(null, created); Integer driverID = created.getBody().getId(); - ResponseEntity<Driver> received = controller.getDriver(driverID); + ResponseEntity<DriverDto> received = controller.getDriver(driverID); assertEquals(HttpStatus.OK, received.getStatusCode()); assertNotEquals(null, received); } @Test void getAllDrivers() { - ResponseEntity<Driver> created = controller.createDriver(getCreateDriverRequest()); + ResponseEntity<DriverDto> created = controller.createDriver(getCreateDriverRequest()); assertEquals(HttpStatus.OK, created.getStatusCode()); assertNotEquals(null, created); - ResponseEntity<Driver> created2 = controller.createDriver(getCreateDriverRequestWithCharacteristics()); + ResponseEntity<DriverDto> created2 = controller.createDriver(getCreateDriverRequestWithCharacteristics()); assertEquals(HttpStatus.OK, created.getStatusCode()); assertNotEquals(null, created); - ResponseEntity<List<Driver>> drivers = controller.getAllTestDrivers(); + ResponseEntity<List<DriverDto>> drivers = controller.getAllTestDrivers(); assertEquals(Arrays.asList(created.getBody(), created2.getBody()), drivers.getBody()); } @Test void getDriver() { - ResponseEntity<Driver> created = controller.createDriver(getCreateDriverRequest()); + ResponseEntity<DriverDto> created = controller.createDriver(getCreateDriverRequest()); assertEquals(HttpStatus.OK, created.getStatusCode()); assertNotEquals(null, created); - ResponseEntity<Driver> received = controller.getDriver(created.getBody().getId()); + ResponseEntity<DriverDto> received = controller.getDriver(created.getBody().getId()); assertEquals(HttpStatus.OK, received.getStatusCode()); assertNotEquals(null, received); assertEquals("John", received.getBody().getName()); @@ -110,12 +110,12 @@ class DriverControllerTest { assertEquals(new ArrayList<>(), received.getBody().getCharacteristics()); } - private CreateDriverRequest getCreateDriverRequestWithCharacteristics() { + private DriverCreateDto getCreateDriverRequestWithCharacteristics() { List<Characteristic> characteristicList = new ArrayList<>(); characteristicList.add(Characteristic.AGGRESSIVENESS); characteristicList.add(Characteristic.REACT_QUICKLY); - return new CreateDriverRequest() + return new DriverCreateDto() .name("John") .surname("Doe") .nationality("Italian") @@ -124,8 +124,8 @@ class DriverControllerTest { .characteristics(characteristicList); } - private CreateDriverRequest getCreateDriverRequest() { - return new CreateDriverRequest() + private DriverCreateDto getCreateDriverRequest() { + return new DriverCreateDto() .name("John") .surname("Doe") .nationality("Italian") diff --git a/notification/openapi.yaml b/notification/openapi.yaml index ca96adf..3493a9f 100644 --- a/notification/openapi.yaml +++ b/notification/openapi.yaml @@ -10,7 +10,7 @@ tags: - name: NotificationService components: schemas: - Receiver: + ReceiverDto: type: object title: Receiver description: Receiver of notification @@ -20,7 +20,7 @@ components: emailAddress: type: string description: Email address where to send the Notification - Sender: + SenderDto: type: object title: Sender description: Receiver of email @@ -30,7 +30,7 @@ components: emailAddress: type: string description: Email address from which was sent the Notification - Notification: + NotificationDto: type: object title: Notification description: Notification to be send to receivers @@ -45,9 +45,23 @@ components: receivers: type: array items: - $ref: '#/components/schemas/Receiver' + $ref: '#/components/schemas/ReceiverDto' subject: type: string + ConfirmationDto: + type: object + title: Confirmation + properties: + message: + type: string + subject: + type: string + receivers: + type: array + items: + $ref: '#/components/schemas/ReceiverDto' + sender: + $ref: '#/components/schemas/SenderDto' paths: /notification: @@ -62,26 +76,14 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/Notification' + $ref: '#/components/schemas/NotificationDto' responses: "200": description: OK content: application/json: schema: - type: object - title: Confirmation - properties: - message: - type: string - subject: - type: string - receivers: - type: array - items: - $ref: '#/components/schemas/Receiver' - sender: - $ref: '#/components/schemas/Sender' + $ref: '#/components/schemas/ConfirmationDto' default: description: Unexpected error content: diff --git a/notification/src/main/java/cz/muni/pa165/rest/NotificationController.java b/notification/src/main/java/cz/muni/pa165/rest/NotificationController.java index 4b3b635..537754b 100644 --- a/notification/src/main/java/cz/muni/pa165/rest/NotificationController.java +++ b/notification/src/main/java/cz/muni/pa165/rest/NotificationController.java @@ -1,10 +1,10 @@ package cz.muni.pa165.rest; import cz.muni.pa165.generated.api.NotificationServiceApiDelegate; -import cz.muni.pa165.generated.model.Confirmation; -import cz.muni.pa165.generated.model.Notification; -import cz.muni.pa165.generated.model.Receiver; -import cz.muni.pa165.generated.model.Sender; +import cz.muni.pa165.generated.model.ConfirmatioDton; +import cz.muni.pa165.generated.model.NotificationDto; +import cz.muni.pa165.generated.model.ReceiverDto; +import cz.muni.pa165.generated.model.SenderDto; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; @@ -21,20 +21,20 @@ public class NotificationController implements NotificationServiceApiDelegate { private static final Logger log = LoggerFactory.getLogger(NotificationController.class); @Override - public ResponseEntity<Confirmation> notify(Notification notification) { + public ResponseEntity<ConfirmationDto> notify(NotificationDto notificationDto) { log.debug("notify() called"); - Sender sender = new Sender().emailAddress("noreply@formula1.com"); + SenderDto sender = new SenderDto().emailAddress("noreply@formula1.com"); - for (Receiver receiver: notification.getReceivers()) { - log.debug("Sending mail with subject " + notification.getSubject() + " and body " - + notification.getMessage() + " to " + receiver.getEmailAddress() + for (ReceiverDto receiver: notificationDto.getReceivers()) { + log.debug("Sending mail with subject " + notificationDto.getSubject() + " and body " + + notificationDto.getMessage() + " to " + receiver.getEmailAddress() + " from " + sender.getEmailAddress()); } - Confirmation confirmation = new Confirmation() - .message(notification.getMessage()) - .receivers(notification.getReceivers()) + ConfirmationDto confirmation = new ConfirmationDto() + .message(notificationDto.getMessage()) + .receivers(notificationDto.getReceivers()) .sender(sender); return new ResponseEntity<>(confirmation, HttpStatus.OK); diff --git a/notification/src/test/java/cz/muni/pa165/rest/NotificationControllerTest.java b/notification/src/test/java/cz/muni/pa165/rest/NotificationControllerTest.java index 2f24228..dc133fc 100644 --- a/notification/src/test/java/cz/muni/pa165/rest/NotificationControllerTest.java +++ b/notification/src/test/java/cz/muni/pa165/rest/NotificationControllerTest.java @@ -1,8 +1,8 @@ package cz.muni.pa165.rest; -import cz.muni.pa165.generated.model.Confirmation; -import cz.muni.pa165.generated.model.Notification; -import cz.muni.pa165.generated.model.Receiver; +import cz.muni.pa165.generated.model.ConfirmationDto; +import cz.muni.pa165.generated.model.NotificationDto; +import cz.muni.pa165.generated.model.ReceiverDto; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,9 +19,9 @@ class NotificationControllerTest { void testNotify() { log.debug("testNotify() running"); - ResponseEntity<Confirmation> received = controller.notify(new Notification() + ResponseEntity<ConfirmationDto> received = controller.notify(new NotificationDto() .message("Hello") - .addReceiversItem(new Receiver().emailAddress("test@doamin.com"))); + .addReceiversItem(new ReceiverDto().emailAddress("test@doamin.com"))); assertEquals("Hello", received.getBody().getMessage()); assertEquals(1, received.getBody().getReceivers().size()); diff --git a/visualization/openapi.yaml b/visualization/openapi.yaml index 4a9f39e..131d21e 100644 --- a/visualization/openapi.yaml +++ b/visualization/openapi.yaml @@ -10,7 +10,7 @@ tags: - name: Visualization components: schemas: - VisualizationSchema: + VisualizationSchemaDto: type: object title: Visualization description: visualization of given data @@ -20,7 +20,7 @@ components: message: type: string description: short message - VisualizationRequestSchema: + VisualizationSchemaCreateDto: type: object title: VisualizationRequest description: data to visualize @@ -44,11 +44,11 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/VisualizationRequestSchema' + $ref: '#/components/schemas/VisualizationSchemaCreateDto' responses: "200": description: OK content: application/json: schema: - $ref: '#/components/schemas/VisualizationSchema' + $ref: '#/components/schemas/VisualizationSchemaDto' diff --git a/visualization/src/main/java/cz/muni/pa165/rest/VisualizationController.java b/visualization/src/main/java/cz/muni/pa165/rest/VisualizationController.java index 4f565b4..6b7b044 100644 --- a/visualization/src/main/java/cz/muni/pa165/rest/VisualizationController.java +++ b/visualization/src/main/java/cz/muni/pa165/rest/VisualizationController.java @@ -1,8 +1,8 @@ package cz.muni.pa165.rest; import cz.muni.pa165.generated.api.VisualizationApiDelegate; -import cz.muni.pa165.generated.model.VisualizationRequestSchema; -import cz.muni.pa165.generated.model.VisualizationSchema; +import cz.muni.pa165.generated.model.VisualizationSchemaCreateDto; +import cz.muni.pa165.generated.model.VisualizationSchemaDto; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.slf4j.Logger; @@ -14,10 +14,10 @@ public class VisualizationController implements VisualizationApiDelegate { private static final Logger log = LoggerFactory.getLogger(VisualizationController.class); @Override - public ResponseEntity<VisualizationSchema> getVisualization(VisualizationRequestSchema visualizationRequestSchema) { + public ResponseEntity<VisualizationSchemaDto> getVisualization(VisualizationSchemaCreateDto visualizationSchemaCreateDto) { log.debug("getVisualization() called"); - return new ResponseEntity<>(new VisualizationSchema().message("--VISUALIZATION--"), HttpStatus.OK); + return new ResponseEntity<>(new VisualizationSchemaDto().message("--VISUALIZATION--"), HttpStatus.OK); } } diff --git a/visualization/src/test/java/cz/muni/pa165/rest/VisualizationControllerTest.java b/visualization/src/test/java/cz/muni/pa165/rest/VisualizationControllerTest.java index 3049549..4056c05 100644 --- a/visualization/src/test/java/cz/muni/pa165/rest/VisualizationControllerTest.java +++ b/visualization/src/test/java/cz/muni/pa165/rest/VisualizationControllerTest.java @@ -1,7 +1,7 @@ package cz.muni.pa165.rest; -import cz.muni.pa165.generated.model.VisualizationRequestSchema; -import cz.muni.pa165.generated.model.VisualizationSchema; +import cz.muni.pa165.generated.model.VisualizationSchemaCreateDto; +import cz.muni.pa165.generated.model.VisualizationSchemaDto; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -22,7 +22,7 @@ class VisualizationControllerTest { void testGetVisualization() { log.debug("testGetVisualization() running"); - ResponseEntity<VisualizationSchema> responseEntity = visualizationController.getVisualization(new VisualizationRequestSchema().data("test")); + ResponseEntity<VisualizationSchemaDto> responseEntity = visualizationController.getVisualization(new VisualizationSchemaCreateDto().data("test")); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertNotNull(responseEntity.getBody()); assertEquals("--VISUALIZATION--", responseEntity.getBody().getMessage()); -- GitLab