-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
이력서 조회순 정렬 기능 추가 #281
이력서 조회순 정렬 기능 추가 #281
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.OneToMany; | ||
import jakarta.persistence.OneToOne; | ||
import jakarta.persistence.PrePersist; | ||
import jakarta.persistence.Table; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
@@ -58,6 +59,10 @@ public class Resume extends BaseEntity { | |
// 이후 버전(더 최신 버전) | ||
private Long laterResumeId; | ||
|
||
// 조회수 | ||
@Column(name = "view_count") | ||
private Long viewCount; | ||
|
||
@Builder.Default | ||
@OneToMany(mappedBy = "resume", cascade = CascadeType.ALL) | ||
private List<ResumeTechStack> resumeTechStacks = new ArrayList<>(); | ||
|
@@ -77,6 +82,14 @@ public Resume(User user, String name, int career, Position position, ResumePdf r | |
this.career = career; | ||
this.position = position; | ||
this.resumePdf = resumePdf; | ||
this.viewCount = 0L; | ||
} | ||
|
||
@PrePersist | ||
public void prePersist() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Entity를 build할때 항상 viewCount는 0인데 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 빌드할 때 0으로 설정하긴 했는데, 이후에 조회했을 때 DB 계속 0이 아니라 null로 저장이 되더라고 그래서 null값 허용 안하게 하려고 이렇게 했어 |
||
if (this.viewCount == null) { | ||
this.viewCount = 0L; | ||
} | ||
} | ||
|
||
public void addResumeTechStack(ResumeTechStack resumeTechStack) { | ||
|
@@ -94,4 +107,8 @@ public void addResumePdf(ResumePdf resumePdf) { | |
public void updateLaterResumeId(Long id) { | ||
this.laterResumeId = id; | ||
} | ||
|
||
public void increaseViewCount() { | ||
this.viewCount++; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,6 +4,7 @@ | |||||
import com.techeer.backend.api.user.domain.User; | ||||||
import java.util.List; | ||||||
import java.util.Optional; | ||||||
import org.springframework.data.domain.Pageable; | ||||||
import org.springframework.data.domain.Slice; | ||||||
import org.springframework.data.jpa.repository.JpaRepository; | ||||||
import org.springframework.data.jpa.repository.Query; | ||||||
|
@@ -24,4 +25,6 @@ public interface ResumeRepository extends JpaRepository<Resume, Long>, ResumeRep | |||||
Resume findFirstByUserOrderByCreatedAtDesc(User user); | ||||||
|
||||||
Slice<Resume> findResumeByUser(User user); | ||||||
|
||||||
Slice<Resume> findResumesByDeletedAtIsNull(Pageable pageable); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider adding view count sorting capability. While the method correctly implements pagination for non-deleted resumes, it doesn't support the PR's objective of sorting resumes by view count. Consider adding a method that includes ordering by view count. Here's a suggested implementation: - Slice<Resume> findResumesByDeletedAtIsNull(Pageable pageable);
+ Slice<Resume> findResumesByDeletedAtIsNullOrderByViewCountDesc(Pageable pageable); Alternatively, you could use a custom query to have more control over the sorting: + @Query("SELECT r FROM Resume r WHERE r.deletedAt IS NULL ORDER BY r.viewCount DESC")
Slice<Resume> findResumesByDeletedAtIsNull(Pageable pageable); 📝 Committable suggestion
Suggested change
|
||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove duplicate resumeName field.
The
resumeName
field is set twice in the builder. Remove the duplicate line to avoid confusion and potential issues.Apply this diff to fix the duplication:
.viewCount(resume.getViewCount()) - .resumeName(resume.getName()) .position(resume.getPosition().getValue())
📝 Committable suggestion