removed unnecessary dirs
This commit is contained in:
parent
76b5703408
commit
35f89f9a7f
@ -14,16 +14,16 @@ public class EmployeeController {
|
||||
|
||||
private final EmployeeService employeeService;
|
||||
|
||||
@GetMapping("/{code}/auth")
|
||||
@ResponseStatus(code = HttpStatus.OK)
|
||||
public void login(@PathVariable String code) {
|
||||
employeeService.auth(code);
|
||||
}
|
||||
|
||||
@GetMapping("/{code}/info")
|
||||
@ResponseStatus(code = HttpStatus.OK)
|
||||
public EmployeeDto getByCode(@PathVariable String code) {
|
||||
return employeeService.getByCode(code);
|
||||
}
|
||||
|
||||
@GetMapping("/login/{username}/{password}")
|
||||
@ResponseStatus(code = HttpStatus.OK)
|
||||
public void login(@PathVariable String username, @PathVariable String password){
|
||||
employeeService.auth(username, password);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -19,6 +19,7 @@ public class EmployeeDto {
|
||||
private String name;
|
||||
private String photoUrl;
|
||||
private Map<LocalDate, PlaceDto> booking;
|
||||
private String password;
|
||||
|
||||
public static EmployeeDto toDto(Employee employee) {
|
||||
Map<LocalDate, PlaceDto> dtoTreeMap = new TreeMap<>();
|
||||
@ -26,6 +27,6 @@ public class EmployeeDto {
|
||||
dtoTreeMap.put(booking.getDate(), PlaceDto.toDto(booking.getPlace()));
|
||||
}
|
||||
|
||||
return new EmployeeDto(employee.getName(), employee.getPhotoUrl(), dtoTreeMap);
|
||||
return new EmployeeDto(employee.getName(), employee.getPhotoUrl(), dtoTreeMap, employee.getPassword());
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ -23,6 +24,12 @@ public class Employee {
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
|
||||
@Column(name = "username")
|
||||
private String username;
|
||||
|
||||
@Column(name = "password")
|
||||
private String password;
|
||||
|
||||
@Column(name = "code")
|
||||
private String code;
|
||||
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
package com.example.nto.exception;
|
||||
|
||||
public class EmployeeAlreadyExists extends RuntimeException {
|
||||
public EmployeeAlreadyExists(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package com.example.nto.exception;
|
||||
|
||||
public class InvalidUsername extends RuntimeException {
|
||||
public InvalidUsername(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@ -5,10 +5,12 @@ import org.springframework.data.jpa.repository.EntityGraph;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface EmployeeRepository extends JpaRepository<Employee, Long> {
|
||||
@EntityGraph(attributePaths = {"bookingList", "bookingList.place"})
|
||||
Optional<Employee> findByCode(String code);
|
||||
|
||||
Optional<Employee> findByUsername(String username);
|
||||
}
|
||||
|
||||
@ -1,9 +1,13 @@
|
||||
package com.example.nto.service;
|
||||
|
||||
import com.example.nto.controller.dto.EmployeeCreateDto;
|
||||
import com.example.nto.controller.dto.EmployeeDto;
|
||||
import com.example.nto.entity.Employee;
|
||||
import com.example.nto.exception.InvalidPassword;
|
||||
|
||||
public interface EmployeeService {
|
||||
EmployeeDto getByCode(String code);
|
||||
|
||||
void auth(String code);
|
||||
void auth(String username, String password) throws InvalidPassword;
|
||||
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ public class BookingServiceImpl implements BookingService {
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public Map<LocalDate, List<PlaceDto>> getFreePlace(String code) {
|
||||
employeeService.auth(code);
|
||||
// employeeService.auth(code);
|
||||
|
||||
List<Place> allPlaces = placeRepository.findAll();
|
||||
|
||||
|
||||
@ -1,13 +1,26 @@
|
||||
package com.example.nto.service.impl;
|
||||
|
||||
import com.example.nto.controller.dto.EmployeeCreateDto;
|
||||
import com.example.nto.controller.dto.EmployeeDto;
|
||||
import com.example.nto.entity.Employee;
|
||||
import com.example.nto.exception.EmployeeAlreadyExists;
|
||||
import com.example.nto.exception.EmployeeNotFoundException;
|
||||
import com.example.nto.exception.InvalidPassword;
|
||||
import com.example.nto.exception.InvalidUsername;
|
||||
import com.example.nto.repository.EmployeeRepository;
|
||||
import com.example.nto.service.EmployeeService;
|
||||
import com.example.nto.utils.PasswordValidator;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.java.Log;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class EmployeeServiceImpl implements EmployeeService {
|
||||
@ -21,11 +34,19 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
.orElseThrow(() -> new EmployeeNotFoundException("Employee with " + code + " code not found!"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public void auth(String code) {
|
||||
if (employeeRepository.findByCode(code).isEmpty()) {
|
||||
throw new EmployeeNotFoundException("Employee with " + code + " code not found!");
|
||||
public void auth(String username, String password) throws InvalidPassword {
|
||||
Optional<Employee> employee = employeeRepository.findByUsername(username);
|
||||
if(employee.isEmpty()){
|
||||
throw new InvalidUsername("Invalid Username");
|
||||
}
|
||||
|
||||
|
||||
if(!EmployeeDto.toDto(employee.get()).getPassword().equals(password)){
|
||||
throw new InvalidPassword("Wrong password: " + password + " " + EmployeeDto.toDto(employee.get()).getPassword());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +21,14 @@
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
|
||||
<column name="username" type="VARCHAR(100)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
|
||||
<column name="password" type="VARCHAR(100)">
|
||||
<constraints nullable="false"/>
|
||||
</column>
|
||||
|
||||
<column name="code" type="VARCHAR(100)">
|
||||
<constraints nullable="false" unique="true"/>
|
||||
</column>
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
name;code;photo_url
|
||||
Ivanov Ivan;1111;https://catalog-cdn.detmir.st/media/2fe02057f9915e72a378795d32c79ea9.jpeg
|
||||
Petrov Petr;2222;https://catalog-cdn.detmir.st/media/2fe02057f9915e72a378795d32c79ea9.jpeg
|
||||
Kozlov Oleg;3333;https://catalog-cdn.detmir.st/media/2fe02057f9915e72a378795d32c79ea9.jpeg
|
||||
Smirnova Anna;4444;https://catalog-cdn.detmir.st/media/2fe02057f9915e72a378795d32c79ea9.jpeg
|
||||
name;code;photo_url;password;username
|
||||
Ivanov Ivan;1111;https://catalog-cdn.detmir.st/media/2fe02057f9915e72a378795d32c79ea9.jpeg;bac12345;ivan
|
||||
Petrov Petr;2222;https://catalog-cdn.detmir.st/media/2fe02057f9915e72a378795d32c79ea9.jpeg;bac12345;petr
|
||||
Kozlov Oleg;3333;https://catalog-cdn.detmir.st/media/2fe02057f9915e72a378795d32c79ea9.jpeg;bac12345;oleg
|
||||
Smirnova Anna;4444;https://catalog-cdn.udetmir.st/media/2fe02057f9915e72a378795d32c79ea9.jpeg;bac12345;anna
|
||||
|
Loading…
x
Reference in New Issue
Block a user