diff --git a/employee-service.http b/employee-service.http index bfbd0b2..adfdda6 100644 --- a/employee-service.http +++ b/employee-service.http @@ -16,9 +16,20 @@ POST http://localhost:8080/employee Content-Type: application/json { - "firstName": "Test2", - "lastName": "Test2", - "secondName": "Test2", + "firstName": "fdsa", + "lastName": "asdf", + "secondName": "fds", + "department": 2, + "salary": 2000 +} +###Добавление сотрудника3 +POST http://localhost:8080/employee +Content-Type: application/json + +{ + "firstName": "fds2a", + "lastName": "asd3f", + "secondName": "fd s", "department": 2, "salary": 2000 } diff --git a/pom.xml b/pom.xml index 6706cb6..34eb14c 100644 --- a/pom.xml +++ b/pom.xml @@ -27,6 +27,10 @@ spring-boot-starter-test test + + org.apache.commons + commons-lang3 + diff --git a/src/main/java/ru/skypro/weblibrary/service/EmployeeServiceImpl.java b/src/main/java/ru/skypro/weblibrary/service/EmployeeServiceImpl.java index 91f74f7..55990db 100644 --- a/src/main/java/ru/skypro/weblibrary/service/EmployeeServiceImpl.java +++ b/src/main/java/ru/skypro/weblibrary/service/EmployeeServiceImpl.java @@ -1,6 +1,9 @@ package ru.skypro.weblibrary.service; +import org.apache.commons.lang3.StringUtils; +import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; +import org.springframework.web.server.ResponseStatusException; import ru.skypro.weblibrary.dto.EmployeeRequest; import ru.skypro.weblibrary.entity.Employee; @@ -21,8 +24,17 @@ public Employee addEmployee(EmployeeRequest employeeRequest) { if (employeeRequest.getFirstName() == null || employeeRequest.getLastName() == null) { throw new IllegalArgumentException("Employee name should be set"); } - Employee employee = new Employee(employeeRequest.getFirstName(), employeeRequest.getLastName(), employeeRequest.getSecondName(), - employeeRequest.getDepartment(), employeeRequest.getSalary()); + if (!StringUtils.isAlpha(employeeRequest.getFirstName()) + || !StringUtils.isAlpha(employeeRequest.getLastName()) + || !StringUtils.isAlpha(employeeRequest.getSecondName()) + ) + throw new ResponseStatusException(HttpStatus.BAD_REQUEST,"Name shoud be alpha"); + Employee employee = new Employee( + StringUtils.capitalize(employeeRequest.getFirstName()), + StringUtils.capitalize(employeeRequest.getLastName()), + StringUtils.capitalize(employeeRequest.getSecondName()), + employeeRequest.getDepartment(), + employeeRequest.getSalary()); this.employees.put(employee.getId(),employee); return employee; }