From 1a7dba918d1c7165096c8399e4381bc4af723a7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D1=8F=D1=87=D0=B5=D1=81=D0=BB=D0=B0=D0=B2=20=D0=A2?= =?UTF-8?q?=D0=B8=D1=85=D0=BE=D0=BD=D0=BE=D0=B2?= Date: Sun, 27 Nov 2022 12:20:38 +0300 Subject: [PATCH] Init --- employee-service.http | 17 ++++++++++++++--- pom.xml | 4 ++++ .../weblibrary/service/EmployeeServiceImpl.java | 16 ++++++++++++++-- 3 files changed, 32 insertions(+), 5 deletions(-) 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; }