diff --git a/src/main/java/ga/backend/BackendApplication.java b/src/main/java/ga/backend/BackendApplication.java index 01de8ac..510e518 100644 --- a/src/main/java/ga/backend/BackendApplication.java +++ b/src/main/java/ga/backend/BackendApplication.java @@ -3,6 +3,7 @@ import org.joda.time.DateTime; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cache.annotation.EnableCaching; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; import org.springframework.scheduling.annotation.EnableScheduling; @@ -12,6 +13,7 @@ @SpringBootApplication @EnableJpaAuditing @EnableScheduling +@EnableCaching public class BackendApplication { @PostConstruct diff --git a/src/main/java/ga/backend/employee/controller/EmployeeController.java b/src/main/java/ga/backend/employee/controller/EmployeeController.java index 7ae6565..4ce6c21 100644 --- a/src/main/java/ga/backend/employee/controller/EmployeeController.java +++ b/src/main/java/ga/backend/employee/controller/EmployeeController.java @@ -11,6 +11,9 @@ import ga.backend.team.repository.TeamRepository; import ga.backend.util.Version; import lombok.AllArgsConstructor; +import org.springframework.cache.Cache; +import org.springframework.cache.CacheManager; +import org.springframework.cache.annotation.Cacheable; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; @@ -73,11 +76,17 @@ public ResponseEntity getEmployee(@Positive @PathVariable("employee-pk") long em // 토큰으로 employee 정보 조회하기 @GetMapping +// @Cacheable(value = "employeeCache") public ResponseEntity getEmployee() { Employee employee = employeeService.findEmployeeByToken(); - EmployeeResponseDto.Response response = employeeMapper.employeeToEmployeeResponseDto(employee); - TeamResponseDto.Response teamResponse = teamMapper.teamToTeamResponseDto(employee.getTeam(), employee.getCompany().getPk()); - response.setTeamResponseDto(teamResponse); + EmployeeResponseDto.SimpleResponse response = employeeMapper.employeeToEmployeeSimpleResponseDto(employee); + + // ResponseDto.Response 반환 +// EmployeeResponseDto.Response response = employeeMapper.employeeToEmployeeSimpleResponseDto(employee); +// if(employee.getTeam() != null) { +// TeamResponseDto.Response teamResponse = teamMapper.teamToTeamResponseDto(employee.getTeam(), employee.getCompany().getPk()); +// response.setTeamResponseDto(teamResponse); +// } return new ResponseEntity<>(response, HttpStatus.OK); } diff --git a/src/main/java/ga/backend/employee/dto/EmployeeResponseDto.java b/src/main/java/ga/backend/employee/dto/EmployeeResponseDto.java index b47ab66..83a2f1a 100644 --- a/src/main/java/ga/backend/employee/dto/EmployeeResponseDto.java +++ b/src/main/java/ga/backend/employee/dto/EmployeeResponseDto.java @@ -26,6 +26,19 @@ public static class Response { private LocalDateTime modifiedAt; } + @AllArgsConstructor + @Setter + @Getter + public static class SimpleResponse { + private Long pk; + private String id; // 사번 + private Long KakaoId; // 카카오톡 ID + private String email; + private String name; // 이름 + private Long year; // 연차 + private boolean regiYn; + } + @AllArgsConstructor @Setter @Getter diff --git a/src/main/java/ga/backend/employee/entity/Employee.java b/src/main/java/ga/backend/employee/entity/Employee.java index 77fce80..9aad927 100644 --- a/src/main/java/ga/backend/employee/entity/Employee.java +++ b/src/main/java/ga/backend/employee/entity/Employee.java @@ -1,6 +1,5 @@ package ga.backend.employee.entity; -//import ga.backend.analysis.entity.Analysis; import ga.backend.analysis.entity.Analysis; import ga.backend.auditable.Auditable; import ga.backend.company.entity.Company; @@ -24,6 +23,7 @@ @Getter @Setter @NoArgsConstructor +@Cacheable public class Employee extends Auditable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -71,7 +71,7 @@ public class Employee extends Auditable { @JoinColumn(name = "company_pk") private Company company; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "team_pk") private Team team; diff --git a/src/main/java/ga/backend/employee/mapper/EmployeeMapper.java b/src/main/java/ga/backend/employee/mapper/EmployeeMapper.java index 91fe849..a358e02 100644 --- a/src/main/java/ga/backend/employee/mapper/EmployeeMapper.java +++ b/src/main/java/ga/backend/employee/mapper/EmployeeMapper.java @@ -17,6 +17,7 @@ public interface EmployeeMapper { Employee employeePatchDtoToEmployee(EmployeeRequestDto.Patch patch); Employee employeeChangePasswordToEmployee(EmployeeRequestDto.ChangePassword changePassword); EmployeeResponseDto.Response employeeToEmployeeResponseDto(Employee employee); + EmployeeResponseDto.SimpleResponse employeeToEmployeeSimpleResponseDto(Employee employee); List employeeToEmployeeListResponseDto(List employees); } \ No newline at end of file diff --git a/src/main/java/ga/backend/employee/repository/EmployeeRepository.java b/src/main/java/ga/backend/employee/repository/EmployeeRepository.java index 9865c48..a9da7a1 100644 --- a/src/main/java/ga/backend/employee/repository/EmployeeRepository.java +++ b/src/main/java/ga/backend/employee/repository/EmployeeRepository.java @@ -2,6 +2,8 @@ import ga.backend.employee.entity.Employee; import ga.backend.team.entity.Team; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.data.jpa.repository.EntityGraph; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -10,6 +12,8 @@ @Repository public interface EmployeeRepository extends JpaRepository { + @Cacheable(value = "employees", key = "#email") + @EntityGraph(attributePaths = {"company", "roles"}) Optional findByEmailAndDelYnFalse(String email); List findFistByIdAndDelYnFalse(String id); Optional findByPkAndDelYnFalse(long pk); diff --git a/src/main/java/ga/backend/employee/service/EmployeeService.java b/src/main/java/ga/backend/employee/service/EmployeeService.java index 2871b01..9ba484e 100644 --- a/src/main/java/ga/backend/employee/service/EmployeeService.java +++ b/src/main/java/ga/backend/employee/service/EmployeeService.java @@ -12,12 +12,18 @@ import ga.backend.team.service.TeamService; import ga.backend.util.FindEmployee; import lombok.AllArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.Cache; +import org.springframework.cache.CacheManager; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.cache.concurrent.ConcurrentMapCache; import org.springframework.context.ApplicationEventPublisher; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import java.util.List; import java.util.Optional; +import java.util.concurrent.ConcurrentMap; @Service @AllArgsConstructor @@ -112,9 +118,7 @@ public Employee findEmployeeByPk(long employeePk) { // 토큰으로 직원 조회 public Employee findEmployeeByToken() { - Employee employee = findEmployee.getLoginEmployeeByToken(); - - return employee; + return findEmployee.getLoginEmployeeByToken(); } // UPDATE