release/2025-02-20-10-37

This commit is contained in:
geniy 2025-02-20 10:37:23 +03:00
parent e3d9694b01
commit 899ce38b87
13 changed files with 112 additions and 21 deletions

View File

@ -1,5 +1,7 @@
package com.example.nto.controller; package com.example.nto.controller;
import com.example.nto.dto.EmployeeDataDto;
import com.example.nto.dto.EntryDto;
import com.example.nto.entity.EmployeeData; import com.example.nto.entity.EmployeeData;
import com.example.nto.entity.Entry; import com.example.nto.entity.Entry;
import com.example.nto.service.AdminService; import com.example.nto.service.AdminService;
@ -23,7 +25,7 @@ public class AdminController {
private void amIAdmin() {} private void amIAdmin() {}
@PostMapping("/panel/get-employee-info") @PostMapping("/panel/get-employee-info")
private EmployeeData getEmployeeInfo(@RequestParam("employee-login") String employeeLogin) { private EmployeeDataDto getEmployeeInfo(@RequestParam("employee-login") String employeeLogin) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String login = authentication.getName(); String login = authentication.getName();
return adminService.getEmployeeInfo(employeeLogin, login); return adminService.getEmployeeInfo(employeeLogin, login);
@ -38,7 +40,7 @@ public class AdminController {
} }
@PostMapping("/panel/get-employee-entry-list") @PostMapping("/panel/get-employee-entry-list")
private List<Entry> getEmployeeEntryList(@RequestParam("employee-login") String employeeLogin) { private List<EntryDto> getEmployeeEntryList(@RequestParam("employee-login") String employeeLogin) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String login = authentication.getName(); String login = authentication.getName();
return adminService.getEmployeeEntryList(employeeLogin, login); return adminService.getEmployeeEntryList(employeeLogin, login);

View File

@ -1,5 +1,7 @@
package com.example.nto.controller; package com.example.nto.controller;
import com.example.nto.dto.EmployeeDataDto;
import com.example.nto.dto.EntryDto;
import com.example.nto.entity.Code; import com.example.nto.entity.Code;
import com.example.nto.entity.Employee; import com.example.nto.entity.Employee;
import com.example.nto.entity.EmployeeData; import com.example.nto.entity.EmployeeData;
@ -25,7 +27,7 @@ public class EmployeeController {
private void auth() {} private void auth() {}
@PostMapping("/info") @PostMapping("/info")
private EmployeeData info() { private EmployeeDataDto info() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String login = authentication.getName(); String login = authentication.getName();
return employeeService.info(login); return employeeService.info(login);
@ -39,7 +41,7 @@ public class EmployeeController {
} }
@PostMapping("/get-entry-list") @PostMapping("/get-entry-list")
private List<Entry> getEntryList() { private List<EntryDto> getEntryList() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String login = authentication.getName(); String login = authentication.getName();
return employeeService.getEntryList(login); return employeeService.getEntryList(login);

View File

@ -0,0 +1,19 @@
package com.example.nto.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class EmployeeDataDto {
private String name;
private String photo;
private String employeePosition;
private LocalDateTime lastVisit;
}

View File

@ -0,0 +1,18 @@
package com.example.nto.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class EntryDto {
private long codeId;
private LocalDateTime entryTime;
private boolean isCard;
}

View File

@ -0,0 +1,17 @@
package com.example.nto.dto.mapper;
import com.example.nto.dto.EmployeeDataDto;
import com.example.nto.entity.EmployeeData;
import lombok.experimental.UtilityClass;
@UtilityClass
public class EmployeeDataMapper {
public static EmployeeDataDto toEmployeeDataDto(EmployeeData employeeData) {
return EmployeeDataDto.builder()
.name(employeeData.getName())
.photo(employeeData.getPhoto())
.employeePosition(employeeData.getEmployeePosition())
.lastVisit(employeeData.getLastVisit())
.build();
}
}

View File

@ -0,0 +1,16 @@
package com.example.nto.dto.mapper;
import com.example.nto.dto.EntryDto;
import com.example.nto.entity.Entry;
import lombok.experimental.UtilityClass;
@UtilityClass
public class EntryMapper {
public static EntryDto toEntryDto(Entry entry) {
return EntryDto.builder()
.codeId(entry.getId())
.entryTime(entry.getEntryTime())
.isCard(entry.isCard())
.build();
}
}

View File

@ -15,7 +15,7 @@ import java.util.Optional;
@Repository @Repository
public interface EmployeeDataRepository extends JpaRepository<EmployeeData, Long> { public interface EmployeeDataRepository extends JpaRepository<EmployeeData, Long> {
Optional<EmployeeData> findByOwnerId(long ownerId); Optional<EmployeeData> findByOwnerId(long ownerId);
@Query(value = "select e.id from employee_data e where owner_id = :owner_id", nativeQuery = true) @Query("select e.id from EmployeeData e where e.ownerId = :owner_id")
Optional<Long> findIdByOwnerId(@Param("owner_id") long ownerId); Optional<Long> findIdByOwnerId(@Param("owner_id") long ownerId);
@Modifying @Modifying

View File

@ -13,12 +13,12 @@ import java.util.Optional;
@Repository @Repository
public interface EmployeeRepository extends JpaRepository<Employee, Long> { public interface EmployeeRepository extends JpaRepository<Employee, Long> {
@Query(value = "select e.id from Employee e where e.login = :login") @Query("select e.id from Employee e where e.login = :login")
Optional<Long> findIdByLogin(@Param("login") String login); Optional<Long> findIdByLogin(@Param("login") String login);
Optional<Employee> findByLogin(String login); Optional<Employee> findByLogin(String login);
@Modifying @Modifying
@Query(value = "update Employee e set e.is_block = :value where e.id = :id", nativeQuery = true) @Query("update Employee set isBlock = :value where id = :id")
void updateBlockCondition(@Param("id") long id, @Param("value") boolean value); void updateBlockCondition(@Param("id") long id, @Param("value") boolean value);
} }

View File

@ -13,7 +13,7 @@ import java.util.List;
public interface EntryRepository extends JpaRepository<Entry, Long> { public interface EntryRepository extends JpaRepository<Entry, Long> {
@Modifying @Modifying
@Query(value = "insert into Entry(employee_id, code_id, entry_time, is_card) values (:employeeId, :codeId, :entryTime, false)", nativeQuery = true) @Query(value = "insert into entry(employee_id, code_id, entry_time, is_card) values (:employeeId, :codeId, :entryTime, false)", nativeQuery = true)
void insert(@Param("employeeId") long employeeId, @Param("codeId") long codeId, @Param("entryTime") LocalDateTime entryTime); void insert(@Param("employeeId") long employeeId, @Param("codeId") long codeId, @Param("entryTime") LocalDateTime entryTime);
List<Entry> findAllByEmployeeId(Long employeeId); List<Entry> findAllByEmployeeId(Long employeeId);

View File

@ -1,12 +1,14 @@
package com.example.nto.service; package com.example.nto.service;
import com.example.nto.dto.EmployeeDataDto;
import com.example.nto.dto.EntryDto;
import com.example.nto.entity.EmployeeData; import com.example.nto.entity.EmployeeData;
import com.example.nto.entity.Entry; import com.example.nto.entity.Entry;
import java.util.List; import java.util.List;
public interface AdminService { public interface AdminService {
EmployeeData getEmployeeInfo(String employeeLogin, String selfLogin); EmployeeDataDto getEmployeeInfo(String employeeLogin, String selfLogin);
void setBlockCondition(String employeeLogin, boolean blockCondition, String selfLogin); void setBlockCondition(String employeeLogin, boolean blockCondition, String selfLogin);
List<Entry> getEmployeeEntryList(String employeeLogin, String selfLogin); List<EntryDto> getEmployeeEntryList(String employeeLogin, String selfLogin);
} }

View File

@ -1,5 +1,7 @@
package com.example.nto.service; package com.example.nto.service;
import com.example.nto.dto.EmployeeDataDto;
import com.example.nto.dto.EntryDto;
import com.example.nto.entity.Code; import com.example.nto.entity.Code;
import com.example.nto.entity.Employee; import com.example.nto.entity.Employee;
import com.example.nto.entity.EmployeeData; import com.example.nto.entity.EmployeeData;
@ -11,11 +13,11 @@ import java.time.LocalDateTime;
import java.util.List; import java.util.List;
public interface EmployeeService { public interface EmployeeService {
EmployeeData info(String login); EmployeeDataDto info(String login);
void open(String login, long value); void open(String login, long value);
List<Entry> getEntryList(String login); List<EntryDto> getEntryList(String login);
boolean amIBlocked(String login); boolean amIBlocked(String login);
} }

View File

@ -1,7 +1,10 @@
package com.example.nto.service.impl; package com.example.nto.service.impl;
import com.example.nto.dto.EmployeeDataDto;
import com.example.nto.dto.EntryDto;
import com.example.nto.dto.mapper.EmployeeDataMapper;
import com.example.nto.dto.mapper.EntryMapper;
import com.example.nto.entity.EmployeeData; import com.example.nto.entity.EmployeeData;
import com.example.nto.entity.Entry;
import com.example.nto.exception.EmployeeDataNotFoundException; import com.example.nto.exception.EmployeeDataNotFoundException;
import com.example.nto.exception.EmployeeNotFoundException; import com.example.nto.exception.EmployeeNotFoundException;
import com.example.nto.exception.SelfChangeException; import com.example.nto.exception.SelfChangeException;
@ -15,6 +18,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors;
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
@ -24,7 +28,7 @@ public class AdminServiceImpl implements AdminService {
private final EntryRepository entryRepository; private final EntryRepository entryRepository;
@Override @Override
public EmployeeData getEmployeeInfo(String employeeLogin, String selfLogin) { public EmployeeDataDto getEmployeeInfo(String employeeLogin, String selfLogin) {
if (employeeLogin.equals(selfLogin)) { if (employeeLogin.equals(selfLogin)) {
throw new SelfChangeException("Self View"); throw new SelfChangeException("Self View");
} }
@ -39,7 +43,7 @@ public class AdminServiceImpl implements AdminService {
throw new EmployeeDataNotFoundException("Employee Data Not Found"); throw new EmployeeDataNotFoundException("Employee Data Not Found");
} }
return employeeData.get(); return EmployeeDataMapper.toEmployeeDataDto(employeeData.get());
} }
@Transactional @Transactional
@ -58,7 +62,7 @@ public class AdminServiceImpl implements AdminService {
} }
@Override @Override
public List<Entry> getEmployeeEntryList(String employeeLogin, String selfLogin) { public List<EntryDto> getEmployeeEntryList(String employeeLogin, String selfLogin) {
if (employeeLogin.equals(selfLogin)) { if (employeeLogin.equals(selfLogin)) {
throw new SelfChangeException("Self View"); throw new SelfChangeException("Self View");
} }
@ -68,6 +72,8 @@ public class AdminServiceImpl implements AdminService {
throw new EmployeeNotFoundException("Employee Not Found"); throw new EmployeeNotFoundException("Employee Not Found");
} }
return entryRepository.findAllByEmployeeId(employee.get()); return entryRepository.findAllByEmployeeId(employee.get()).stream()
.map(EntryMapper::toEntryDto)
.collect(Collectors.toList());
} }
} }

View File

@ -1,5 +1,9 @@
package com.example.nto.service.impl; package com.example.nto.service.impl;
import com.example.nto.dto.EmployeeDataDto;
import com.example.nto.dto.EntryDto;
import com.example.nto.dto.mapper.EmployeeDataMapper;
import com.example.nto.dto.mapper.EntryMapper;
import com.example.nto.entity.Code; import com.example.nto.entity.Code;
import com.example.nto.entity.Employee; import com.example.nto.entity.Employee;
import com.example.nto.entity.EmployeeData; import com.example.nto.entity.EmployeeData;
@ -20,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors;
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
@ -30,7 +35,7 @@ public class EmployeeServiceImpl implements EmployeeService {
private final EntryRepository entryRepository; private final EntryRepository entryRepository;
@Override @Override
public EmployeeData info(String login) { public EmployeeDataDto info(String login) {
Optional<Long> employee = employeeRepository.findIdByLogin(login); Optional<Long> employee = employeeRepository.findIdByLogin(login);
if (employee.isEmpty()) { if (employee.isEmpty()) {
throw new EmployeeNotFoundException("Employee Not Found"); throw new EmployeeNotFoundException("Employee Not Found");
@ -41,7 +46,7 @@ public class EmployeeServiceImpl implements EmployeeService {
throw new EmployeeDataNotFoundException("Employee Data Not Found"); throw new EmployeeDataNotFoundException("Employee Data Not Found");
} }
return employeeData.get(); return EmployeeDataMapper.toEmployeeDataDto(employeeData.get());
} }
@Transactional @Transactional
@ -72,13 +77,15 @@ public class EmployeeServiceImpl implements EmployeeService {
} }
@Override @Override
public List<Entry> getEntryList(String login) { public List<EntryDto> getEntryList(String login) {
Optional<Long> employee = employeeRepository.findIdByLogin(login); Optional<Long> employee = employeeRepository.findIdByLogin(login);
if (employee.isEmpty()) { if (employee.isEmpty()) {
throw new EmployeeNotFoundException("Employee Not Found"); throw new EmployeeNotFoundException("Employee Not Found");
} }
return entryRepository.findAllByEmployeeId(employee.get()); return entryRepository.findAllByEmployeeId(employee.get()).stream()
.map(EntryMapper::toEntryDto)
.collect(Collectors.toList());
} }
@Override @Override