diff --git a/jobis-application/src/main/java/team/retum/jobis/common/dto/response/TotalPageCountResponse.java b/jobis-application/src/main/java/team/retum/jobis/common/dto/response/TotalPageCountResponse.java index 3ad6575d2..e28457765 100644 --- a/jobis-application/src/main/java/team/retum/jobis/common/dto/response/TotalPageCountResponse.java +++ b/jobis-application/src/main/java/team/retum/jobis/common/dto/response/TotalPageCountResponse.java @@ -2,8 +2,10 @@ import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.NoArgsConstructor; @Getter +@NoArgsConstructor(force = true) @AllArgsConstructor public class TotalPageCountResponse { diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/application/dto/response/AttachmentResponse.java b/jobis-application/src/main/java/team/retum/jobis/domain/application/dto/response/AttachmentResponse.java index 627df1f0b..a0fb32990 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/application/dto/response/AttachmentResponse.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/application/dto/response/AttachmentResponse.java @@ -2,10 +2,12 @@ import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.NoArgsConstructor; import team.retum.jobis.domain.application.model.ApplicationAttachment; import team.retum.jobis.domain.application.model.AttachmentType; @Getter +@NoArgsConstructor @AllArgsConstructor public class AttachmentResponse { private String url; diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/application/dto/response/QueryEmploymentCountResponse.java b/jobis-application/src/main/java/team/retum/jobis/domain/application/dto/response/QueryEmploymentCountResponse.java index 8a5388018..7cc84cb06 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/application/dto/response/QueryEmploymentCountResponse.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/application/dto/response/QueryEmploymentCountResponse.java @@ -1,9 +1,13 @@ package team.retum.jobis.domain.application.dto.response; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; @Getter +@NoArgsConstructor(force = true) +@AllArgsConstructor @Builder public class QueryEmploymentCountResponse { diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/application/dto/response/QueryPassedApplicationStudentsResponse.java b/jobis-application/src/main/java/team/retum/jobis/domain/application/dto/response/QueryPassedApplicationStudentsResponse.java index dae4945d9..3b0b53036 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/application/dto/response/QueryPassedApplicationStudentsResponse.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/application/dto/response/QueryPassedApplicationStudentsResponse.java @@ -3,12 +3,14 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; import team.retum.jobis.domain.application.spi.vo.PassedApplicationStudentsVO; import team.retum.jobis.domain.student.model.SchoolNumber; import java.util.List; @Getter +@NoArgsConstructor(force = true) @AllArgsConstructor public class QueryPassedApplicationStudentsResponse { @@ -29,6 +31,8 @@ public static QueryPassedApplicationStudentResponse of(PassedApplicationStudents } @Getter + @NoArgsConstructor(force = true) + @AllArgsConstructor @Builder public static class QueryPassedApplicationStudentResponse { diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/application/dto/response/QueryRejectionReasonResponse.java b/jobis-application/src/main/java/team/retum/jobis/domain/application/dto/response/QueryRejectionReasonResponse.java index 44f288c12..64089b8bb 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/application/dto/response/QueryRejectionReasonResponse.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/application/dto/response/QueryRejectionReasonResponse.java @@ -2,8 +2,10 @@ import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.NoArgsConstructor; @Getter +@NoArgsConstructor(force = true) @AllArgsConstructor public class QueryRejectionReasonResponse { diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/application/dto/response/TeacherQueryApplicationsResponse.java b/jobis-application/src/main/java/team/retum/jobis/domain/application/dto/response/TeacherQueryApplicationsResponse.java index 9102fd723..a33eea78b 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/application/dto/response/TeacherQueryApplicationsResponse.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/application/dto/response/TeacherQueryApplicationsResponse.java @@ -3,18 +3,22 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; import team.retum.jobis.domain.application.model.ApplicationStatus; import java.time.LocalDate; import java.util.List; @Getter +@NoArgsConstructor(force = true) @AllArgsConstructor public class TeacherQueryApplicationsResponse { private final List applications; @Getter + @NoArgsConstructor(force = true) + @AllArgsConstructor @Builder public static class TeacherQueryApplicationResponse { private final Long applicationId; diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/code/dto/response/CodesResponse.java b/jobis-application/src/main/java/team/retum/jobis/domain/code/dto/response/CodesResponse.java index 049000110..3ffcf3a92 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/code/dto/response/CodesResponse.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/code/dto/response/CodesResponse.java @@ -3,12 +3,14 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; import team.retum.jobis.domain.code.model.Code; import team.retum.jobis.domain.code.model.JobType; import java.util.List; @Getter +@NoArgsConstructor(force = true) @AllArgsConstructor public class CodesResponse { @@ -23,6 +25,8 @@ public static CodeResponse of(Code code) { } @Getter + @NoArgsConstructor(force = true) + @AllArgsConstructor @Builder public static class CodeResponse { diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/company/dto/response/QueryCompanyDetailsResponse.java b/jobis-application/src/main/java/team/retum/jobis/domain/company/dto/response/QueryCompanyDetailsResponse.java index 049c983b7..797b6f8af 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/company/dto/response/QueryCompanyDetailsResponse.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/company/dto/response/QueryCompanyDetailsResponse.java @@ -1,12 +1,16 @@ package team.retum.jobis.domain.company.dto.response; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; import java.time.LocalDate; import java.util.List; @Getter +@NoArgsConstructor(force = true) +@AllArgsConstructor @Builder public class QueryCompanyDetailsResponse { diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/company/dto/response/StudentQueryCompaniesResponse.java b/jobis-application/src/main/java/team/retum/jobis/domain/company/dto/response/StudentQueryCompaniesResponse.java index 87923c82c..3296a94c1 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/company/dto/response/StudentQueryCompaniesResponse.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/company/dto/response/StudentQueryCompaniesResponse.java @@ -2,11 +2,13 @@ import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.NoArgsConstructor; import team.retum.jobis.domain.company.spi.vo.StudentCompaniesVO; import java.util.List; @Getter +@NoArgsConstructor(force = true) @AllArgsConstructor public class StudentQueryCompaniesResponse { private final List companies; diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/company/dto/response/TeacherQueryCompaniesResponse.java b/jobis-application/src/main/java/team/retum/jobis/domain/company/dto/response/TeacherQueryCompaniesResponse.java index 183fcb911..d45c5b09c 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/company/dto/response/TeacherQueryCompaniesResponse.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/company/dto/response/TeacherQueryCompaniesResponse.java @@ -3,17 +3,21 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; import team.retum.jobis.domain.company.model.CompanyType; import java.util.List; @Getter +@NoArgsConstructor(force = true) @AllArgsConstructor public class TeacherQueryCompaniesResponse { private final List companies; @Getter + @NoArgsConstructor(force = true) + @AllArgsConstructor @Builder public static class TeacherQueryCompanyResponse { private final Long companyId; diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/company/dto/response/TeacherQueryEmployCompaniesResponse.java b/jobis-application/src/main/java/team/retum/jobis/domain/company/dto/response/TeacherQueryEmployCompaniesResponse.java index bbe39e0f4..da2771dc1 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/company/dto/response/TeacherQueryEmployCompaniesResponse.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/company/dto/response/TeacherQueryEmployCompaniesResponse.java @@ -2,11 +2,13 @@ import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.NoArgsConstructor; import team.retum.jobis.domain.company.spi.vo.TeacherEmployCompaniesVO; import java.util.List; @Getter +@NoArgsConstructor(force = true) @AllArgsConstructor public class TeacherQueryEmployCompaniesResponse { diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/company/spi/vo/StudentCompaniesVO.java b/jobis-application/src/main/java/team/retum/jobis/domain/company/spi/vo/StudentCompaniesVO.java index df1240427..13f203375 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/company/spi/vo/StudentCompaniesVO.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/company/spi/vo/StudentCompaniesVO.java @@ -2,8 +2,10 @@ import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.NoArgsConstructor; @Getter +@NoArgsConstructor(force = true) @AllArgsConstructor public class StudentCompaniesVO { diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/company/spi/vo/TeacherEmployCompaniesVO.java b/jobis-application/src/main/java/team/retum/jobis/domain/company/spi/vo/TeacherEmployCompaniesVO.java index ca43ccd55..8f0175cbd 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/company/spi/vo/TeacherEmployCompaniesVO.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/company/spi/vo/TeacherEmployCompaniesVO.java @@ -2,8 +2,10 @@ import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.NoArgsConstructor; @Getter +@NoArgsConstructor(force = true) @AllArgsConstructor public class TeacherEmployCompaniesVO { diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/recruitment/dto/response/QueryRecruitmentDetailResponse.java b/jobis-application/src/main/java/team/retum/jobis/domain/recruitment/dto/response/QueryRecruitmentDetailResponse.java index 570fd4f9e..1ccded771 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/recruitment/dto/response/QueryRecruitmentDetailResponse.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/recruitment/dto/response/QueryRecruitmentDetailResponse.java @@ -1,7 +1,9 @@ package team.retum.jobis.domain.recruitment.dto.response; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; import team.retum.jobis.domain.recruitment.model.ProgressType; import team.retum.jobis.domain.recruitment.spi.vo.RecruitmentDetailVO; @@ -10,6 +12,8 @@ import java.util.List; @Getter +@NoArgsConstructor(force = true) +@AllArgsConstructor @Builder public class QueryRecruitmentDetailResponse { diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/recruitment/dto/response/RecruitAreaResponse.java b/jobis-application/src/main/java/team/retum/jobis/domain/recruitment/dto/response/RecruitAreaResponse.java index 29b10e968..abcfff928 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/recruitment/dto/response/RecruitAreaResponse.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/recruitment/dto/response/RecruitAreaResponse.java @@ -3,10 +3,12 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; import java.util.List; @Getter +@NoArgsConstructor(force = true) @AllArgsConstructor @Builder public class RecruitAreaResponse { diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/recruitment/dto/response/StudentQueryRecruitmentsResponse.java b/jobis-application/src/main/java/team/retum/jobis/domain/recruitment/dto/response/StudentQueryRecruitmentsResponse.java index 47fed7a87..14823c7f5 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/recruitment/dto/response/StudentQueryRecruitmentsResponse.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/recruitment/dto/response/StudentQueryRecruitmentsResponse.java @@ -3,16 +3,20 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; import java.util.List; @Getter +@NoArgsConstructor(force = true) @AllArgsConstructor public class StudentQueryRecruitmentsResponse { private final List recruitments; @Getter + @NoArgsConstructor(force = true) + @AllArgsConstructor @Builder public static class StudentRecruitmentResponse { private long id; diff --git a/jobis-application/src/main/java/team/retum/jobis/domain/recruitment/dto/response/TeacherQueryRecruitmentsResponse.java b/jobis-application/src/main/java/team/retum/jobis/domain/recruitment/dto/response/TeacherQueryRecruitmentsResponse.java index ab02789ab..a34e77e30 100644 --- a/jobis-application/src/main/java/team/retum/jobis/domain/recruitment/dto/response/TeacherQueryRecruitmentsResponse.java +++ b/jobis-application/src/main/java/team/retum/jobis/domain/recruitment/dto/response/TeacherQueryRecruitmentsResponse.java @@ -3,6 +3,7 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; import team.retum.jobis.domain.company.model.CompanyType; import team.retum.jobis.domain.recruitment.model.RecruitStatus; @@ -10,12 +11,15 @@ import java.util.List; @Getter +@NoArgsConstructor(force = true) @AllArgsConstructor public class TeacherQueryRecruitmentsResponse { private final List recruitments; @Getter + @NoArgsConstructor(force = true) + @AllArgsConstructor @Builder public static class TeacherRecruitmentResponse { private long id; diff --git a/jobis-infrastructure/build.gradle b/jobis-infrastructure/build.gradle index 76c708edc..5159f9a5d 100644 --- a/jobis-infrastructure/build.gradle +++ b/jobis-infrastructure/build.gradle @@ -54,6 +54,9 @@ dependencies { // jaxb implementation 'javax.xml.bind:jaxb-api:2.3.0' + // cache + implementation 'org.springframework.boot:spring-boot-starter-cache' + } test.useJUnitPlatform() diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/acceptance/presentation/AcceptanceWebAdapter.java b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/acceptance/presentation/AcceptanceWebAdapter.java index e02d058ae..dcc2bdf99 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/acceptance/presentation/AcceptanceWebAdapter.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/acceptance/presentation/AcceptanceWebAdapter.java @@ -2,6 +2,10 @@ import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.cache.annotation.Caching; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; @@ -23,6 +27,11 @@ import team.retum.jobis.domain.acceptance.usecase.RegisterFieldTraineeUseCase; import team.retum.jobis.domain.acceptance.usecase.TeacherQueryFieldTraineesAndContractWorkersUseCase; +import static team.retum.jobis.global.config.cache.CacheName.ACCEPTANCE; +import static team.retum.jobis.global.config.cache.CacheName.APPLICATION; +import static team.retum.jobis.global.config.cache.CacheName.COMPANY; + +@CacheConfig(cacheNames = ACCEPTANCE) @RequiredArgsConstructor @RequestMapping("/acceptances") @RestController @@ -34,6 +43,7 @@ public class AcceptanceWebAdapter { private final RegisterEmploymentContractUseCase registerEmploymentContractUseCase; private final CancelFieldTraineesUseCase cancelFieldTraineesUseCase; + @Cacheable @GetMapping("/{company-id}") public TeacherQueryFieldTraineesAndContractWorkersResponse teacherQueryFieldTraineesAndContractWorkers( @PathVariable(name = "company-id") Long companyId @@ -41,6 +51,12 @@ public TeacherQueryFieldTraineesAndContractWorkersResponse teacherQueryFieldTrai return teacherQueryFieldTraineesAndContractWorkersUseCase.execute(companyId); } + @Caching( + evict = { + @CacheEvict(cacheNames = APPLICATION, allEntries = true), + @CacheEvict(cacheNames = COMPANY, allEntries = true) + } + ) @ResponseStatus(HttpStatus.NO_CONTENT) @PatchMapping("/field-train") public void registerFieldTrainee( @@ -49,18 +65,32 @@ public void registerFieldTrainee( registerFieldTraineeUseCase.execute(request.toDomainRequest()); } + @CacheEvict(allEntries = true) @ResponseStatus(HttpStatus.NO_CONTENT) @PatchMapping("/contract-date") public void changeWorkContractDate(@RequestBody @Valid ChangeContractDateWebRequest request) { changeContractDateUseCase.execute(request.toDomainRequest()); } + @Caching( + evict = { + @CacheEvict(cacheNames = ACCEPTANCE, allEntries = true), + @CacheEvict(cacheNames = APPLICATION, allEntries = true), + @CacheEvict(cacheNames = COMPANY, allEntries = true) + } + ) @ResponseStatus(HttpStatus.CREATED) @PostMapping("/employment") public void registerEmploymentContract(@RequestBody @Valid RegisterEmploymentContractWebRequest request) { registerEmploymentContractUseCase.execute(request.toDomainRequest()); } + @Caching( + evict = { + @CacheEvict(cacheNames = APPLICATION, allEntries = true), + @CacheEvict(cacheNames = COMPANY, allEntries = true) + } + ) @ResponseStatus(HttpStatus.NO_CONTENT) @DeleteMapping public void cancelFieldTrainees(@RequestBody @Valid CancelFieldTraineesWebRequest request) { diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/application/presentation/ApplicationWebAdapter.java b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/application/presentation/ApplicationWebAdapter.java index d937f30d3..26426bd1e 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/application/presentation/ApplicationWebAdapter.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/application/presentation/ApplicationWebAdapter.java @@ -2,6 +2,10 @@ import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.cache.annotation.Caching; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; @@ -39,6 +43,10 @@ import team.retum.jobis.domain.application.usecase.RejectApplicationUseCase; import team.retum.jobis.domain.application.usecase.TeacherQueryApplicationsUseCase; +import static team.retum.jobis.global.config.cache.CacheName.APPLICATION; +import static team.retum.jobis.global.config.cache.CacheName.COMPANY; + +@CacheConfig(cacheNames = APPLICATION) @RequiredArgsConstructor @RequestMapping("/applications") @RestController @@ -57,6 +65,12 @@ public class ApplicationWebAdapter { private final ReapplyUseCase reapplyUseCase; private final QueryRejectionReasonUseCase queryRejectionReasonUseCase; + @Caching( + evict = { + @CacheEvict(cacheNames = APPLICATION, allEntries = true), + @CacheEvict(cacheNames = COMPANY, allEntries = true) + } + ) @ResponseStatus(HttpStatus.CREATED) @PostMapping("/{recruitment-id}") public void createApplication( @@ -66,12 +80,19 @@ public void createApplication( createApplicationUseCase.execute(request.toDomainRequest(), recruitmentId); } + @Caching( + evict = { + @CacheEvict(cacheNames = APPLICATION, allEntries = true), + @CacheEvict(cacheNames = COMPANY, allEntries = true) + } + ) @ResponseStatus(HttpStatus.NO_CONTENT) @DeleteMapping("/{application-id}") public void deleteApplication(@PathVariable("application-id") Long applicationId) { deleteApplicationUseCase.execute(applicationId); } + @Cacheable @GetMapping public TeacherQueryApplicationsResponse queryTeacherApplicationList( @RequestParam(value = "application_status", required = false) ApplicationStatus applicationStatus, @@ -81,6 +102,7 @@ public TeacherQueryApplicationsResponse queryTeacherApplicationList( return queryApplicationListService.execute(applicationStatus, studentName, recruitmentId); } + @Cacheable @GetMapping("/count") public TotalPageCountResponse queryApplicationCount( @RequestParam(value = "application_status", required = false) ApplicationStatus applicationStatus, @@ -99,6 +121,12 @@ public QueryMyApplicationsResponse queryMyApplications() { return queryMyApplicationsUseCase.execute(); } + @Caching( + evict = { + @CacheEvict(cacheNames = APPLICATION, allEntries = true), + @CacheEvict(cacheNames = COMPANY, allEntries = true) + } + ) @ResponseStatus(HttpStatus.NO_CONTENT) @PatchMapping("/status") public void changeApplicationsStatus(@RequestBody @Valid ChangeApplicationsStatusWebRequest request) { @@ -108,12 +136,14 @@ public void changeApplicationsStatus(@RequestBody @Valid ChangeApplicationsStatu ); } + @CacheEvict(allEntries = true) @ResponseStatus(HttpStatus.NO_CONTENT) @PatchMapping("/train-date") public void changeFieldTrainDate(@RequestBody @Valid ChangeFieldTrainDateWebRequest request) { changeFieldTrainDateUseCase.execute(request.toDomainRequest()); } + @CacheEvict(allEntries = true) @ResponseStatus(HttpStatus.NO_CONTENT) @PatchMapping("/rejection/{application-id}") public void rejectApplication( @@ -123,11 +153,13 @@ public void rejectApplication( rejectApplicationUseCase.execute(applicationId, request.getReason()); } + @Cacheable @GetMapping("/employment/count") public QueryEmploymentCountResponse queryEmploymentCount() { return queryEmploymentCountUseCase.execute(); } + @Cacheable @GetMapping("/pass/{company-id}") public QueryPassedApplicationStudentsResponse queryFieldTrainApplication( @PathVariable("company-id") Long companyId @@ -135,6 +167,7 @@ public QueryPassedApplicationStudentsResponse queryFieldTrainApplication( return queryPassedApplicationStudentsUseCase.execute(companyId); } + @CacheEvict(allEntries = true) @ResponseStatus(HttpStatus.NO_CONTENT) @PutMapping("/{application-id}") public void reapply( @@ -144,6 +177,7 @@ public void reapply( reapplyUseCase.execute(applicationId, request.toDomainRequest()); } + @Cacheable @GetMapping("/rejection/{application-id}") public QueryRejectionReasonResponse queryRejectionReason(@PathVariable("application-id") Long applicationId) { return queryRejectionReasonUseCase.execute(applicationId); diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/code/presentation/CodeWebAdapter.java b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/code/presentation/CodeWebAdapter.java index 92f625ad0..1941f9f1e 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/code/presentation/CodeWebAdapter.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/code/presentation/CodeWebAdapter.java @@ -1,6 +1,8 @@ package team.retum.jobis.domain.code.presentation; import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.Cacheable; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -9,13 +11,17 @@ import team.retum.jobis.domain.code.model.CodeType; import team.retum.jobis.domain.code.usecase.QueryCodesService; -@RestController +import static team.retum.jobis.global.config.cache.CacheName.CODE; + +@CacheConfig(cacheNames = CODE) @RequiredArgsConstructor @RequestMapping("/codes") +@RestController public class CodeWebAdapter { private final QueryCodesService codesService; + @Cacheable @GetMapping public CodesResponse getCodes( @RequestParam(value = "type") CodeType codeType, diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/company/persistence/repository/vo/QueryTeacherEmployCompaniesVO.java b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/company/persistence/repository/vo/QueryTeacherEmployCompaniesVO.java index de9322777..41ffb9a2a 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/company/persistence/repository/vo/QueryTeacherEmployCompaniesVO.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/company/persistence/repository/vo/QueryTeacherEmployCompaniesVO.java @@ -2,9 +2,11 @@ import com.querydsl.core.annotations.QueryProjection; import lombok.Getter; +import lombok.NoArgsConstructor; import team.retum.jobis.domain.company.spi.vo.TeacherEmployCompaniesVO; @Getter +@NoArgsConstructor public class QueryTeacherEmployCompaniesVO extends TeacherEmployCompaniesVO { @QueryProjection diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/company/persistence/repository/vo/StudentQueryCompaniesVO.java b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/company/persistence/repository/vo/StudentQueryCompaniesVO.java index 979558b4a..aec56ffc6 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/company/persistence/repository/vo/StudentQueryCompaniesVO.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/company/persistence/repository/vo/StudentQueryCompaniesVO.java @@ -2,9 +2,11 @@ import com.querydsl.core.annotations.QueryProjection; import lombok.Getter; +import lombok.NoArgsConstructor; import team.retum.jobis.domain.company.spi.vo.StudentCompaniesVO; @Getter +@NoArgsConstructor public class StudentQueryCompaniesVO extends StudentCompaniesVO { @QueryProjection diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/company/presentation/CompanyWebAdapter.java b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/company/presentation/CompanyWebAdapter.java index c32ef21c1..0cff53971 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/company/presentation/CompanyWebAdapter.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/company/presentation/CompanyWebAdapter.java @@ -3,6 +3,10 @@ import jakarta.validation.Valid; import jakarta.validation.constraints.Positive; import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.cache.annotation.Caching; import org.springframework.http.HttpStatus; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; @@ -40,8 +44,12 @@ import team.retum.jobis.domain.company.usecase.UpdateCompanyTypeUseCase; import team.retum.jobis.domain.company.usecase.UpdateMouUseCase; -@RequiredArgsConstructor +import static team.retum.jobis.global.config.cache.CacheName.COMPANY; +import static team.retum.jobis.global.config.cache.CacheName.COMPANY_USER; + +@CacheConfig(cacheNames = COMPANY) @Validated +@RequiredArgsConstructor @RequestMapping("/companies") @RestController public class CompanyWebAdapter { @@ -58,6 +66,7 @@ public class CompanyWebAdapter { private final UpdateMouUseCase updateMouUseCase; private final QueryReviewAvailableCompaniesUseCase queryReviewAvailableCompaniesUseCase; + @CacheEvict(allEntries = true) @ResponseStatus(HttpStatus.CREATED) @PostMapping public TokenResponse register(@RequestBody @Valid RegisterCompanyWebRequest request) { @@ -69,6 +78,12 @@ public CheckCompanyExistsResponse companyExists(@PathVariable("business-number") return checkCompanyExistsUseCase.execute(businessNumber); } + @Caching( + evict = { + @CacheEvict(cacheNames = COMPANY, allEntries = true), + @CacheEvict(cacheNames = COMPANY_USER, allEntries = true) + } + ) @ResponseStatus(HttpStatus.NO_CONTENT) @PatchMapping("/{company-id}") public void updateDetails( @@ -78,6 +93,7 @@ public void updateDetails( updateCompanyDetailsUseCase.execute(request.toDomainRequest(), companyId); } + @Cacheable @GetMapping("/student") public StudentQueryCompaniesResponse studentQueryCompanies( @RequestParam(value = "page", required = false, defaultValue = "1") @Positive Long page, @@ -86,6 +102,7 @@ public StudentQueryCompaniesResponse studentQueryCompanies( return studentQueryCompaniesUseCase.execute(page - 1, name); } + @Cacheable @GetMapping("/student/count") public TotalPageCountResponse studentQueryCompanyCount( @RequestParam(value = "name", required = false) String name @@ -93,6 +110,7 @@ public TotalPageCountResponse studentQueryCompanyCount( return studentQueryCompaniesUseCase.getTotalPageCount(name); } + @Cacheable @GetMapping("/{company-id}") public QueryCompanyDetailsResponse getCompanyDetails(@PathVariable("company-id") Long companyId) { return queryCompanyDetailsUseCase.execute(companyId); @@ -103,12 +121,14 @@ public CompanyMyPageResponse queryMyPage() { return companyMyPageUseCase.execute(); } + @CacheEvict(allEntries = true) @ResponseStatus(HttpStatus.NO_CONTENT) @PatchMapping("/type") public void updateCompanyType(@RequestBody @Valid UpdateCompanyTypeWebRequest request) { updateCompanyTypeUseCase.execute(request.toDomainRequest()); } + @Cacheable @GetMapping("/employment") public TeacherQueryEmployCompaniesResponse queryEmployCompanies( @RequestParam(value = "company_name", required = false) String companyName, @@ -119,6 +139,7 @@ public TeacherQueryEmployCompaniesResponse queryEmployCompanies( return teacherQueryEmployCompaniesUseCase.execute(companyName, type, year, page - 1); } + @Cacheable @GetMapping("/employment/count") public TotalPageCountResponse queryEmployCompaniesCount( @RequestParam(value = "company_name", required = false) String companyName, @@ -128,6 +149,7 @@ public TotalPageCountResponse queryEmployCompaniesCount( return teacherQueryEmployCompaniesUseCase.getTotalPageCount(companyName, type, year); } + @Cacheable @GetMapping("/teacher") public TeacherQueryCompaniesResponse queryCompanies( @RequestParam(value = "type", required = false) CompanyType type, @@ -139,6 +161,7 @@ public TeacherQueryCompaniesResponse queryCompanies( return teacherQueryCompaniesUseCase.execute(type, companyName, region, businessArea, page - 1); } + @Cacheable @GetMapping("/teacher/count") public TotalPageCountResponse queryCompanyCount( @RequestParam(value = "type", required = false) CompanyType type, @@ -149,6 +172,7 @@ public TotalPageCountResponse queryCompanyCount( return teacherQueryCompaniesUseCase.getTotalPageCount(type, companyName, region, businessArea); } + @CacheEvict(allEntries = true) @ResponseStatus(HttpStatus.NO_CONTENT) @PatchMapping("/mou") public void updateMou(@RequestBody @Valid UpdateMouWebRequest request) { diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/recruitment/presentation/RecruitmentWebAdapter.java b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/recruitment/presentation/RecruitmentWebAdapter.java index e1c9b5da9..c8a822ba8 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/recruitment/presentation/RecruitmentWebAdapter.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/recruitment/presentation/RecruitmentWebAdapter.java @@ -3,6 +3,9 @@ import jakarta.validation.Valid; import jakarta.validation.constraints.Positive; import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.http.HttpStatus; import org.springframework.validation.annotation.Validated; @@ -44,10 +47,13 @@ import java.util.ArrayList; import java.util.List; -@RestController +import static team.retum.jobis.global.config.cache.CacheName.RECRUITMENT; + +@CacheConfig(cacheNames = RECRUITMENT) @Validated @RequiredArgsConstructor @RequestMapping("/recruitments") +@RestController public class RecruitmentWebAdapter { private final ApplyRecruitmentUseCase applyRecruitmentUseCase; @@ -62,12 +68,14 @@ public class RecruitmentWebAdapter { private final DeleteRecruitmentUseCase deleteRecruitmentUseCase; private final DeleteRecruitAreaUseCase deleteRecruitAreaUseCase; + @CacheEvict(allEntries = true) @ResponseStatus(HttpStatus.CREATED) @PostMapping public void applyRecruitment(@RequestBody @Valid ApplyRecruitmentWebRequest webRequest) { applyRecruitmentUseCase.execute(webRequest.toDomainRequest()); } + @CacheEvict(allEntries = true) @ResponseStatus(HttpStatus.NO_CONTENT) @PatchMapping("/{recruitment-id}") public void updateRecruitment( @@ -77,6 +85,7 @@ public void updateRecruitment( updateRecruitmentService.execute(webRequest.toDomainRequest(), recruitmentId); } + @CacheEvict(allEntries = true) @ResponseStatus(HttpStatus.NO_CONTENT) @PatchMapping("/area/{recruit-area-id}") public void updateRecruitArea( @@ -86,6 +95,7 @@ public void updateRecruitArea( updateRecruitAreaService.execute(webRequest.toDomainRequest(), recruitAreaId); } + @CacheEvict(allEntries = true) @ResponseStatus(HttpStatus.CREATED) @PostMapping("/{recruitment-id}/area") public void createRecruitArea( @@ -95,6 +105,7 @@ public void createRecruitArea( createRecruitAreaUseCase.execute(webRequest.toDomainRequest(), recruitmentId); } + @Cacheable @GetMapping("/student") public StudentQueryRecruitmentsResponse studentQueryRecruitments( @RequestParam(value = "name", required = false) String companyName, @@ -111,6 +122,7 @@ public StudentQueryRecruitmentsResponse studentQueryRecruitments( ); } + @Cacheable @GetMapping("/student/count") public TotalPageCountResponse studentQueryRecruitmentCount( @RequestParam(value = "name", required = false) String companyName, @@ -125,6 +137,7 @@ public TotalPageCountResponse studentQueryRecruitmentCount( ); } + @Cacheable @GetMapping("/teacher") public TeacherQueryRecruitmentsResponse queryRecruitmentList( @RequestParam(value = "company_name", required = false) String companyName, @@ -138,6 +151,7 @@ public TeacherQueryRecruitmentsResponse queryRecruitmentList( return teacherQueryRecruitmentsUseCase.execute(companyName, start, end, year, status, page - 1, winterIntern); } + @Cacheable @GetMapping("/teacher/count") public TotalPageCountResponse queryRecruitmentCount( @RequestParam(value = "company_name", required = false) String companyName, @@ -150,6 +164,7 @@ public TotalPageCountResponse queryRecruitmentCount( return teacherQueryRecruitmentsUseCase.getTotalPageCount(companyName, start, end, year, status, winterIntern); } + @CacheEvict(allEntries = true) @ResponseStatus(HttpStatus.NO_CONTENT) @PatchMapping("/status") public void changeRecruitStatus(@RequestBody @Valid ChangeRecruitmentStatusWebRequest webRequest) { @@ -157,6 +172,7 @@ public void changeRecruitStatus(@RequestBody @Valid ChangeRecruitmentStatusWebRe } + @Cacheable @GetMapping("/{recruitment-id}") public QueryRecruitmentDetailResponse queryRecruitmentDetail( @PathVariable("recruitment-id") Long recruitmentId @@ -169,12 +185,14 @@ public QueryMyRecruitmentResponse queryMyRecruitment() { return queryMyRecruitmentUseCase.execute(); } + @CacheEvict(allEntries = true) @ResponseStatus(HttpStatus.NO_CONTENT) @DeleteMapping("/{recruitment-id}") public void deleteRecruitment(@PathVariable("recruitment-id") Long recruitmentId) { deleteRecruitmentUseCase.execute(recruitmentId); } + @CacheEvict(allEntries = true) @ResponseStatus(HttpStatus.NO_CONTENT) @DeleteMapping("/area/{recruit-area-id}") public void deleteRecruitArea(@PathVariable("recruit-area-id") Long recruitAreaId) { @@ -183,7 +201,7 @@ public void deleteRecruitArea(@PathVariable("recruit-area-id") Long recruitAreaI private List parseCodes(String jobCode, String techCodes) { List codes = new ArrayList<>(StringUtil.divideString(techCodes, ",")); - if (jobCode!= null && !jobCode.isBlank()) codes.add(jobCode); + if (jobCode != null && !jobCode.isBlank()) codes.add(jobCode); try { return codes.stream() diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/student/presentation/StudentWebAdapter.java b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/student/presentation/StudentWebAdapter.java index 249fb7069..f665f2c81 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/domain/student/presentation/StudentWebAdapter.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/domain/student/presentation/StudentWebAdapter.java @@ -2,6 +2,7 @@ import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.CacheEvict; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; @@ -25,6 +26,8 @@ import team.retum.jobis.domain.student.usecase.UpdateStudentProfileUseCase; import team.retum.jobis.domain.student.usecase.VerifyStudentUseCase; +import static team.retum.jobis.global.config.cache.CacheName.STUDENT_USER; + @RequiredArgsConstructor @RequestMapping("/students") @RestController @@ -63,6 +66,7 @@ public void checkStudentExists( verifyStudentUseCase.execute(gcn, name); } + @CacheEvict(cacheNames = STUDENT_USER, allEntries = true) @ResponseStatus(HttpStatus.NO_CONTENT) @PatchMapping("/profile") public void updateStudentProfile(@RequestBody @Valid UpdateStudentProfileWebRequest request) { diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/global/config/cache/CacheConfig.java b/jobis-infrastructure/src/main/java/team/retum/jobis/global/config/cache/CacheConfig.java new file mode 100644 index 000000000..dbfa19c75 --- /dev/null +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/global/config/cache/CacheConfig.java @@ -0,0 +1,74 @@ +package team.retum.jobis.global.config.cache; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.jsontype.BasicPolymorphicTypeValidator; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import org.springframework.boot.autoconfigure.cache.RedisCacheManagerBuilderCustomizer; +import org.springframework.cache.CacheManager; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.cache.RedisCacheConfiguration; +import org.springframework.data.redis.cache.RedisCacheManager; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.RedisSerializationContext; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +import java.time.Duration; + +import static team.retum.jobis.global.config.cache.CacheName.CODE; +import static team.retum.jobis.global.config.cache.CacheName.COMPANY_USER; +import static team.retum.jobis.global.config.cache.CacheName.STUDENT_USER; +import static team.retum.jobis.global.config.cache.CacheName.TEACHER_USER; + +@Configuration +@EnableCaching +public class CacheConfig { + + @Bean + public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) { + BasicPolymorphicTypeValidator typeValidator = BasicPolymorphicTypeValidator.builder() + .allowIfSubType(Object.class) + .build(); + + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.registerModule(new JavaTimeModule()); + objectMapper.activateDefaultTyping(typeValidator, ObjectMapper.DefaultTyping.NON_FINAL); + + GenericJackson2JsonRedisSerializer redisSerializer = new GenericJackson2JsonRedisSerializer(objectMapper); + + RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig() + .entryTtl(Duration.ofMinutes(30)) + .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())) + .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer)); + + return RedisCacheManager.RedisCacheManagerBuilder + .fromConnectionFactory(redisConnectionFactory) + .cacheDefaults(redisCacheConfiguration) + .build(); + } + + @Bean + public RedisCacheManagerBuilderCustomizer redisCacheManagerBuilderCustomizer() { + return builder -> builder + .withCacheConfiguration(CODE, RedisCacheConfiguration.defaultCacheConfig() + .entryTtl(Duration.ofMinutes(10)) + .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())) + .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer())) + ) + .withCacheConfiguration(COMPANY_USER, RedisCacheConfiguration.defaultCacheConfig() + .entryTtl(Duration.ofMinutes(10)) + .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())) + .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer())) + ).withCacheConfiguration(STUDENT_USER, RedisCacheConfiguration.defaultCacheConfig() + .entryTtl(Duration.ofMinutes(10)) + .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())) + .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer())) + ).withCacheConfiguration(TEACHER_USER, RedisCacheConfiguration.defaultCacheConfig() + .entryTtl(Duration.ofMinutes(10)) + .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())) + .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer())) + ); + } +} diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/global/config/cache/CacheName.java b/jobis-infrastructure/src/main/java/team/retum/jobis/global/config/cache/CacheName.java new file mode 100644 index 000000000..7f6d51fbe --- /dev/null +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/global/config/cache/CacheName.java @@ -0,0 +1,16 @@ +package team.retum.jobis.global.config.cache; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class CacheName { + public static final String ACCEPTANCE = "Acceptance"; + public static final String APPLICATION = "application"; + public static final String CODE = "code"; + public static final String COMPANY = "company"; + public static final String RECRUITMENT = "recruitment"; + public static final String COMPANY_USER = "company_user"; + public static final String STUDENT_USER = "student_user"; + public static final String TEACHER_USER = "teacher_user"; +} diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/global/config/cache/CustomKeyGenerator.java b/jobis-infrastructure/src/main/java/team/retum/jobis/global/config/cache/CustomKeyGenerator.java new file mode 100644 index 000000000..0fe956f6f --- /dev/null +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/global/config/cache/CustomKeyGenerator.java @@ -0,0 +1,22 @@ +package team.retum.jobis.global.config.cache; + +import org.springframework.cache.interceptor.KeyGenerator; +import org.springframework.cache.interceptor.SimpleKeyGenerator; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.lang.reflect.Method; + +@Configuration +public class CustomKeyGenerator implements KeyGenerator { + + @Override + public Object generate(Object target, Method method, Object... params) { + return method.getName() + SimpleKeyGenerator.generateKey(params); + } + + @Bean + public KeyGenerator keyGenerator() { + return new CustomKeyGenerator(); + } +} diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/auth/company/CompanyDetails.java b/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/auth/company/CompanyDetails.java index 60591ce5d..f758e4291 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/auth/company/CompanyDetails.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/auth/company/CompanyDetails.java @@ -1,6 +1,8 @@ package team.retum.jobis.global.security.auth.company; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.RequiredArgsConstructor; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; @@ -12,41 +14,49 @@ import java.util.Collections; @Getter +@NoArgsConstructor(force = true) @RequiredArgsConstructor public class CompanyDetails implements UserDetails { private final transient CompanyEntity company; - + + @JsonIgnore @Override public Collection getAuthorities() { return Collections.singleton(new SimpleGrantedAuthority(Authority.COMPANY.name())); } + @JsonIgnore @Override public String getPassword() { return null; } + @JsonIgnore @Override public String getUsername() { return company.getId().toString(); } + @JsonIgnore @Override public boolean isAccountNonExpired() { return true; } + @JsonIgnore @Override public boolean isAccountNonLocked() { return true; } + @JsonIgnore @Override public boolean isCredentialsNonExpired() { return true; } + @JsonIgnore @Override public boolean isEnabled() { return true; diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/auth/company/CompanyDetailsService.java b/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/auth/company/CompanyDetailsService.java index 14122e995..1a79dda53 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/auth/company/CompanyDetailsService.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/auth/company/CompanyDetailsService.java @@ -1,6 +1,8 @@ package team.retum.jobis.global.security.auth.company; import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.Cacheable; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; @@ -9,12 +11,16 @@ import team.retum.jobis.domain.company.persistence.repository.CompanyJpaRepository; import team.retum.jobis.global.exception.InvalidTokenException; +import static team.retum.jobis.global.config.cache.CacheName.COMPANY_USER; + +@CacheConfig(cacheNames = COMPANY_USER) @Component @RequiredArgsConstructor public class CompanyDetailsService implements UserDetailsService { private final CompanyJpaRepository companyJpaRepository; + @Cacheable @Override public UserDetails loadUserByUsername(String companyId) throws UsernameNotFoundException { CompanyEntity company = companyJpaRepository.findById( diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/auth/student/StudentDetails.java b/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/auth/student/StudentDetails.java index 23c26d139..44ab6c164 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/auth/student/StudentDetails.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/auth/student/StudentDetails.java @@ -1,6 +1,8 @@ package team.retum.jobis.global.security.auth.student; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.RequiredArgsConstructor; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; @@ -12,41 +14,49 @@ import java.util.Collections; @Getter +@NoArgsConstructor(force = true) @RequiredArgsConstructor public class StudentDetails implements UserDetails { private final transient StudentEntity student; + @JsonIgnore @Override public Collection getAuthorities() { return Collections.singletonList(new SimpleGrantedAuthority(Authority.STUDENT.name())); } + @JsonIgnore @Override public String getPassword() { return null; } + @JsonIgnore @Override public String getUsername() { return student.getId().toString(); } + @JsonIgnore @Override public boolean isAccountNonExpired() { return true; } + @JsonIgnore @Override public boolean isAccountNonLocked() { return true; } + @JsonIgnore @Override public boolean isCredentialsNonExpired() { return true; } + @JsonIgnore @Override public boolean isEnabled() { return true; diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/auth/student/StudentDetailsService.java b/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/auth/student/StudentDetailsService.java index 207a696b3..3c4e330bc 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/auth/student/StudentDetailsService.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/auth/student/StudentDetailsService.java @@ -1,6 +1,8 @@ package team.retum.jobis.global.security.auth.student; import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.Cacheable; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; @@ -9,12 +11,16 @@ import team.retum.jobis.domain.student.persistence.repository.StudentJpaRepository; import team.retum.jobis.global.exception.InvalidTokenException; +import static team.retum.jobis.global.config.cache.CacheName.STUDENT_USER; + +@CacheConfig(cacheNames = STUDENT_USER) @Component @RequiredArgsConstructor public class StudentDetailsService implements UserDetailsService { private final StudentJpaRepository studentJpaRepository; + @Cacheable @Override public UserDetails loadUserByUsername(String studentId) throws UsernameNotFoundException { StudentEntity studentEntity = studentJpaRepository.findById( diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/auth/teacher/TeacherDetails.java b/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/auth/teacher/TeacherDetails.java index c905549e4..356ad8bc5 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/auth/teacher/TeacherDetails.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/auth/teacher/TeacherDetails.java @@ -1,6 +1,8 @@ package team.retum.jobis.global.security.auth.teacher; import lombok.Getter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import lombok.NoArgsConstructor; import lombok.RequiredArgsConstructor; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; @@ -12,41 +14,49 @@ import java.util.Collections; @Getter +@NoArgsConstructor(force = true) @RequiredArgsConstructor public class TeacherDetails implements UserDetails { private final transient TeacherEntity teacher; + @JsonIgnore @Override public Collection getAuthorities() { return Collections.singletonList(new SimpleGrantedAuthority(Authority.TEACHER.name())); } + @JsonIgnore @Override public String getPassword() { return null; } + @JsonIgnore @Override public String getUsername() { return teacher.getId().toString(); } + @JsonIgnore @Override public boolean isAccountNonExpired() { return true; } + @JsonIgnore @Override public boolean isAccountNonLocked() { return true; } + @JsonIgnore @Override public boolean isCredentialsNonExpired() { return true; } + @JsonIgnore @Override public boolean isEnabled() { return true; diff --git a/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/auth/teacher/TeacherDetailsService.java b/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/auth/teacher/TeacherDetailsService.java index e055fedb2..b250c231e 100644 --- a/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/auth/teacher/TeacherDetailsService.java +++ b/jobis-infrastructure/src/main/java/team/retum/jobis/global/security/auth/teacher/TeacherDetailsService.java @@ -1,6 +1,8 @@ package team.retum.jobis.global.security.auth.teacher; import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.Cacheable; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; @@ -9,12 +11,16 @@ import team.retum.jobis.domain.teacher.persistence.repository.TeacherJpaRepository; import team.retum.jobis.global.exception.InvalidTokenException; +import static team.retum.jobis.global.config.cache.CacheName.TEACHER_USER; + +@CacheConfig(cacheNames = TEACHER_USER) @Component @RequiredArgsConstructor public class TeacherDetailsService implements UserDetailsService { private final TeacherJpaRepository teacherJpaRepository; + @Cacheable @Override public UserDetails loadUserByUsername(String teacherId) throws UsernameNotFoundException { TeacherEntity teacherEntity = teacherJpaRepository.findById( diff --git a/jobis-infrastructure/src/main/resources/application.yml b/jobis-infrastructure/src/main/resources/application.yml index c4bfe2bf5..a7770ffa9 100644 --- a/jobis-infrastructure/src/main/resources/application.yml +++ b/jobis-infrastructure/src/main/resources/application.yml @@ -14,6 +14,8 @@ spring: show_sql: ${SHOW_SQL:true} jdbc: batch_size: 200 + open-in-view: false + jackson: property-naming-strategy: SNAKE_CASE