Skip to content

Commit

Permalink
Merge pull request #197 from ITZipProject/feature/resume
Browse files Browse the repository at this point in the history
✨ 새 기능 : 이력서 스크랩 기능 추가 완료
  • Loading branch information
hanseu9839 authored Dec 24, 2024
2 parents 331253c + e675138 commit 1d852cb
Show file tree
Hide file tree
Showing 78 changed files with 1,055 additions and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class JobInfoScrapRedisReadRepositoryImpl implements JobInfoScrapRedisRea
@Override
public boolean hasSameJobInfoScrap(Long jobInfoId, String userEmail) {
String redisKey = JobInfoScrap.makeRedisKey(jobInfoId, userEmail);
return redisTemplate.hasKey(redisKey);
return Boolean.TRUE.equals(redisTemplate.hasKey(redisKey));
}

@Override
Expand All @@ -32,11 +32,7 @@ public boolean isJobInfoScrapStatus(Long jobInfoId, String userEmail) {
return false;
}

if(scrapStatus.equals(JobInfoScrapType.UN_SCRAP.name())) {
return false;
}

return true;
return !scrapStatus.equals(JobInfoScrapType.UN_SCRAP.name());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ private void syncJobInfoScrapToDatabase(String userEmail, Long jobInfoId) {
JobInfo jobInfo = jobInfoService.getById(jobInfoId);

JobInfoScrap jobInfoScrap = JobInfoScrap.createScrap(user.convertToEntity(), jobInfo);
JobInfoScrap scrapDatabase = jobInfoService.findByJobInfoId(jobInfoId, userEmail);
JobInfoScrap databaseScrap = jobInfoService.findByJobInfoId(jobInfoId, userEmail);

if (JobInfoScrapType.isUnScrapEqual(jobInfoScrapRedisService.getJobInfoStatusFromRedis(jobInfoId, userEmail)) && scrapDatabase != null) {
jobInfoService.delete(scrapDatabase);
if (JobInfoScrapType.isUnScrapEqual(jobInfoScrapRedisService.getJobInfoStatusFromRedis(jobInfoId, userEmail)) && databaseScrap != null) {
jobInfoService.delete(databaseScrap);
updateScrapCount(jobInfoId, jobInfo);
jobInfoScrapRedisService.jobInfoScrapDeleteToRedis(jobInfoId, userEmail);
log.info("=== jobInfoScrap delete ===");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ public String jobInfoScrapToRedis(JobInfoScrapRequest request) {
Long id = request.getId();
String email = request.getEmail();

if (jobInfoScrapRedisReadRepository.hasSameJobInfoScrap(id, email) || jobInfoScrapRedisReadRepository.isJobInfoScrapStatus(id, email)) {
if (jobInfoScrapRedisReadRepository.hasSameJobInfoScrap(id, email) && jobInfoScrapRedisReadRepository.isJobInfoScrapStatus(id, email)) {
jobInfoScrapRedisCommandRepository.unScrapInfoFromRedis(id, email);
jobInfoScrapRedisCommandRepository.decrementScrapCountFromRedis(id);
return "채용정보 스크랩을 취소하였습니다.";
}

Optional<JobInfoScrap> optionalData = jobInfoScrapRepository.findByJobInfoId(id, email);
if (optionalData.isPresent()) {
jobInfoScrapRedisCommandRepository.notCacheUnScrapInfoToRedis(request.getId(), request.getEmail());
jobInfoScrapRedisCommandRepository.notCacheUnScrapInfoToRedis(id, email);
jobInfoScrapRedisCommandRepository.decrementScrapCountFromRedis(id);
return "채용정보 스크랩을 취소하였습니다.";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import darkoverload.itzip.feature.jwt.infrastructure.CustomUserDetails;
import darkoverload.itzip.feature.resume.controller.request.CreateResumeRequest;
import darkoverload.itzip.feature.resume.controller.request.ResumeInfoScrapRequest;
import darkoverload.itzip.feature.resume.controller.request.UpdateResumeRequest;
import darkoverload.itzip.feature.resume.controller.response.CreateResumeResponse;
import darkoverload.itzip.feature.resume.controller.response.GetResumeDetailsResponse;
import darkoverload.itzip.feature.resume.controller.response.SearchResumeResponse;
import darkoverload.itzip.feature.resume.controller.response.UpdateResumeResponse;
import darkoverload.itzip.feature.resume.service.resume.ResumeReadService;
import darkoverload.itzip.feature.resume.service.resume.ResumeService;
import darkoverload.itzip.feature.resume.service.resume.ResumeCommandService;
import darkoverload.itzip.feature.resume.service.resume.redis.ResumeScrapRedisService;
import darkoverload.itzip.global.config.response.code.CommonExceptionCode;
import darkoverload.itzip.global.config.response.code.CommonResponseCode;
import darkoverload.itzip.global.config.swagger.ExceptionCodeAnnotations;
Expand Down Expand Up @@ -38,8 +40,9 @@
@RequiredArgsConstructor
public class ResumeController {

private final ResumeService service;
private final ResumeCommandService service;
private final ResumeReadService resumeReadService;
private final ResumeScrapRedisService resumeScrapRedisService;

@Operation(
summary = "이력서 생성",
Expand Down Expand Up @@ -103,4 +106,16 @@ public String deleteResume(@Parameter(description = "이력서 아이디", examp
return "성공";
}

@Operation(
summary = "이력서 스크랩",
description = "이력서 스크랩 기능 추가"
)
@ResponseCodeAnnotation(CommonResponseCode.SUCCESS)
@ExceptionCodeAnnotations({CommonExceptionCode.NOT_FOUND})
@PostMapping("/scrap")
public String scrapResumeInfo(@SwaggerRequestBody(description = "이력서 스크랩에 대한 정보", required = true, content = @Content(schema = @Schema(implementation = ResumeInfoScrapRequest.class)
)) @RequestBody ResumeInfoScrapRequest request) {
return resumeScrapRedisService.resumeScrapToRedis(request);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package darkoverload.itzip.feature.resume.controller.request;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;

@ToString
@Getter
@AllArgsConstructor
public class ResumeInfoScrapRequest {

@NotBlank(message = "이력서 id는 필수 입니다.")
@Schema(description = "이력서 id")
Long id;

@NotBlank(message="유저 이메일은 필수 값입니다.")
String email;
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package darkoverload.itzip.feature.resume.controller.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import darkoverload.itzip.feature.resume.code.PublicOnOff;
import darkoverload.itzip.feature.resume.domain.resume.ProfileInfo;
import darkoverload.itzip.feature.resume.domain.resume.ResumeBasicInfo;
import darkoverload.itzip.feature.resume.domain.resume.Resume;
import darkoverload.itzip.feature.resume.entity.ResumeEntity;
import lombok.Builder;

@JsonInclude(JsonInclude.Include.NON_NULL)
public record SearchResumeResponse(Long resumeId, ProfileInfo profileInfo, String imageUrl, Long userId, String workLongTerm) {
public record SearchResumeResponse(Long resumeId, ResumeBasicInfo resumeBasicInfo, String imageUrl, Long userId, String workLongTerm) {


@Builder
Expand All @@ -19,7 +17,7 @@ public record SearchResumeResponse(Long resumeId, ProfileInfo profileInfo, Strin
public static SearchResumeResponse from(Resume resume) {
return SearchResumeResponse.builder()
.resumeId(resume.getResumeId())
.profileInfo(resume.getProfileInfo())
.resumeBasicInfo(resume.getResumeBasicInfo())
.imageUrl(resume.getImageUrl())
.workLongTerm(resume.getWorkLongTerm())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
import darkoverload.itzip.feature.resume.domain.resume.Resume;
import darkoverload.itzip.feature.resume.dto.achievement.AchievementDto;
import darkoverload.itzip.feature.resume.entity.AchievementEntity;
import darkoverload.itzip.feature.resume.entity.ResumeEntity;
import lombok.*;

import java.time.LocalDateTime;
import java.util.Objects;

@Setter
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import darkoverload.itzip.feature.resume.domain.resume.Resume;
import darkoverload.itzip.feature.resume.dto.language.LanguageDto;
import darkoverload.itzip.feature.resume.entity.LanguageEntity;
import darkoverload.itzip.feature.resume.entity.ResumeEntity;
import lombok.*;

import java.time.LocalDateTime;
import java.util.Objects;

@Setter
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import darkoverload.itzip.feature.resume.code.PublicOnOff;
import darkoverload.itzip.feature.resume.dto.resume.ResumeDto;
import darkoverload.itzip.feature.resume.entity.ResumeEntity;
import darkoverload.itzip.feature.resume.entity.resume.ResumeEntity;
import darkoverload.itzip.global.config.response.code.CommonExceptionCode;
import darkoverload.itzip.global.config.response.exception.RestApiException;
import lombok.*;
Expand All @@ -16,9 +16,10 @@
@EqualsAndHashCode
public class Resume {
public static final String FEATURE_DIR = "resume";
private static final String MAP_RESUME_SCARP_COUNT_KEY = "resumeScrapCount:";

// 이메일
private ProfileInfo profileInfo;
private ResumeBasicInfo resumeBasicInfo;

// 링크
private List<String> links;
Expand All @@ -38,32 +39,36 @@ public class Resume {
// url
private List<String> fileUrls;

private int scrapCount;

public Resume() {
}

public Resume(String email, String phone, String subject, String introduction, PublicOnOff publicOnOff, List<String> links, String imageUrl, Long userId, Long resumeId, String workLongTerm, List<String> fileUrls) {
this.profileInfo = new ProfileInfo(email, phone, subject, introduction, publicOnOff);
public Resume(String email, String phone, String subject, String introduction, PublicOnOff publicOnOff, List<String> links, String imageUrl, Long userId, Long resumeId, String workLongTerm, List<String> fileUrls, int scrapCount) {
this.resumeBasicInfo = new ResumeBasicInfo(email, phone, subject, introduction, publicOnOff);
this.links = links;
this.imageUrl = imageUrl;
this.userId = userId;
this.resumeId = resumeId;
this.workLongTerm = workLongTerm;
this.fileUrls = fileUrls;
this.scrapCount = scrapCount;
}

@Builder
public Resume(ProfileInfo profileInfo, List<String> links, String imageUrl, Long userId, Long resumeId, String workLongTerm, List<String> fileUrls) {
this.profileInfo = profileInfo;
public Resume(ResumeBasicInfo resumeBasicInfo, List<String> links, String imageUrl, Long userId, Long resumeId, String workLongTerm, List<String> fileUrls, int scrapCount) {
this.resumeBasicInfo = resumeBasicInfo;
this.links = links;
this.imageUrl = imageUrl;
this.userId = userId;
this.resumeId = resumeId;
this.workLongTerm = workLongTerm;
this.fileUrls = fileUrls;
this.scrapCount = scrapCount;
}

public static Resume create(ResumeDto resume, Long userId) {
ProfileInfo profileInfo = ProfileInfo.builder()
ResumeBasicInfo resumeBasicInfo = ResumeBasicInfo.builder()
.email(resume.getEmail())
.phone(resume.getPhone())
.subject(resume.getSubject())
Expand All @@ -72,16 +77,17 @@ public static Resume create(ResumeDto resume, Long userId) {
.build();

return Resume.builder()
.profileInfo(profileInfo)
.resumeBasicInfo(resumeBasicInfo)
.links(resume.getLinks())
.imageUrl(resume.getImageUrl())
.userId(userId)
.fileUrls(resume.getFileUrls())
.scrapCount(resume.getScrapCount())
.build();
}

public static Resume update(ResumeDto resume, long resumeId, long userId) {
ProfileInfo profileInfo = ProfileInfo.builder()
ResumeBasicInfo resumeBasicInfo = ResumeBasicInfo.builder()
.email(resume.getEmail())
.phone(resume.getPhone())
.subject(resume.getSubject())
Expand All @@ -90,37 +96,40 @@ public static Resume update(ResumeDto resume, long resumeId, long userId) {
.build();

return Resume.builder()
.profileInfo(profileInfo)
.resumeBasicInfo(resumeBasicInfo)
.links(resume.getLinks())
.imageUrl(resume.getImageUrl())
.resumeId(resumeId)
.userId(userId)
.fileUrls(resume.getFileUrls())
.scrapCount(resume.getScrapCount())
.build();
}

public static Resume searchResume(Resume resume, String workLongTerm) {

return Resume.builder()
.resumeId(resume.getResumeId())
.profileInfo(resume.getProfileInfo())
.resumeBasicInfo(resume.getResumeBasicInfo())
.links(resume.getLinks())
.imageUrl(resume.getImageUrl())
.userId(resume.getUserId())
.workLongTerm(workLongTerm)
.fileUrls(resume.getFileUrls())
.scrapCount(resume.getScrapCount())
.build();
}

public ResumeEntity toEntity() {
return ResumeEntity.builder()
.userId(this.userId)
.imageUrl(this.imageUrl)
.profileInfo(this.profileInfo.toEntity())
.basicInfo(this.resumeBasicInfo.toEntity())
.links(this.links)
.userId(this.userId)
.id(this.resumeId)
.fileUrls(this.fileUrls)
.scrapCount(this.scrapCount)
.build();
}

Expand All @@ -143,4 +152,15 @@ public List<String> notExistFileUrls(List<String> dataFileUrls) {
.collect(Collectors.toList());
}

public static String makeScrapCountRedisKey(Long jobInfoId) {
StringBuilder sb = new StringBuilder();
return sb.append(MAP_RESUME_SCARP_COUNT_KEY)
.append(jobInfoId).toString();
}

public int updateScrapCount(int scrapCount) {
this.scrapCount += scrapCount;
return this.scrapCount;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package darkoverload.itzip.feature.resume.domain.resume;

import darkoverload.itzip.feature.resume.code.PublicOnOff;
import darkoverload.itzip.feature.resume.entity.ProfileInfoEntity;
import darkoverload.itzip.feature.resume.entity.ResumeBasicInfoEntity;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -10,7 +10,7 @@
@Getter
@ToString
@EqualsAndHashCode
public class ProfileInfo {
public class ResumeBasicInfo {
// 이메일
private final String email;

Expand All @@ -28,16 +28,16 @@ public class ProfileInfo {


@Builder
public ProfileInfo(String email, String phone, String subject, String introduction, PublicOnOff publicOnOff) {
public ResumeBasicInfo(String email, String phone, String subject, String introduction, PublicOnOff publicOnOff) {
this.email = email;
this.phone = phone;
this.subject = subject;
this.introduction = introduction;
this.publicOnOff = publicOnOff;
}

public ProfileInfoEntity toEntity() {
return ProfileInfoEntity.builder()
public ResumeBasicInfoEntity toEntity() {
return ResumeBasicInfoEntity.builder()
.email(this.email)
.introduction(this.introduction)
.phone(this.phone)
Expand Down
Loading

0 comments on commit 1d852cb

Please sign in to comment.