Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions employee-service.http
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
}
Expand Down