-
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
[REFACTOR] 회원의 방문 이력 테이블 추가 #302
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
smeem-api/src/test/java/com/smeem/member/service/MemberServiceIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.smeem.member.service; | ||
|
||
import com.smeem.api.member.service.MemberService; | ||
import com.smeem.api.member.service.dto.request.MemberVisitUpdateRequest; | ||
import com.smeem.domain.member.model.Member; | ||
import com.smeem.domain.member.repository.MemberRepository; | ||
import com.smeem.domain.visit.adapter.VisitCounter; | ||
import com.smeem.domain.visit.repository.VisitRepository; | ||
import com.smeem.support.ServiceIntegrationTest; | ||
import com.smeem.support.fixture.MemberFixture; | ||
import jakarta.transaction.Transactional; | ||
import lombok.val; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
public class MemberServiceIntegrationTest extends ServiceIntegrationTest { | ||
|
||
@Autowired | ||
private MemberService memberService; | ||
|
||
@Autowired | ||
private MemberRepository memberRepository; | ||
@Autowired | ||
private VisitRepository visitRepository; | ||
|
||
@Autowired | ||
private VisitCounter visitCounter; | ||
|
||
@Nested | ||
@DisplayName("회원 방문 체크") | ||
class MemberVisitTest { | ||
|
||
private Member member; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
memberRepository.deleteAllInBatch(); | ||
visitRepository.deleteAllInBatch(); | ||
member = memberRepository.save(MemberFixture.member().build()); | ||
} | ||
|
||
@Test | ||
@Transactional | ||
@DisplayName("[성공] 회원이 방문하면 하루에 한 번 이력이 남는다.") | ||
void createMemberVisitedHistoryTodayAtOnce() { | ||
// given | ||
val request = new MemberVisitUpdateRequest(member.getId()); | ||
|
||
int initCount = visitCounter.countByMember(member); | ||
assertThat(initCount).isEqualTo(0); | ||
|
||
// when | ||
memberService.updateMemberVisit(request); | ||
memberService.updateMemberVisit(request); | ||
|
||
// then | ||
int visitCount = visitCounter.countByMember(member); | ||
assertThat(visitCount).isEqualTo(1); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 0 additions & 33 deletions
33
smeem-domain/src/main/java/com/smeem/domain/member/model/MemberVisitInfo.java
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
smeem-domain/src/main/java/com/smeem/domain/visit/adapter/VisitCounter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.smeem.domain.visit.adapter; | ||
|
||
import com.smeem.domain.member.model.Member; | ||
import com.smeem.domain.support.RepositoryAdapter; | ||
import com.smeem.domain.visit.repository.VisitRepository; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RepositoryAdapter | ||
@RequiredArgsConstructor | ||
public class VisitCounter { | ||
|
||
private final VisitRepository visitRepository; | ||
|
||
public int countByMember(Member member) { | ||
return visitRepository.countByMember(member); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
smeem-domain/src/main/java/com/smeem/domain/visit/adapter/VisitFinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.smeem.domain.visit.adapter; | ||
|
||
import com.smeem.domain.member.model.Member; | ||
import com.smeem.domain.support.RepositoryAdapter; | ||
import com.smeem.domain.visit.repository.VisitRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.val; | ||
|
||
import java.time.LocalDate; | ||
|
||
@RepositoryAdapter | ||
@RequiredArgsConstructor | ||
public class VisitFinder { | ||
|
||
private final VisitRepository visitRepository; | ||
|
||
public boolean isVisitedToday(Member member) { | ||
val today = LocalDate.now().atStartOfDay(); | ||
val tomorrow = today.plusDays(1); | ||
return visitRepository.existsByMemberAndVisitedAtBetween(member, today, tomorrow); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
smeem-domain/src/main/java/com/smeem/domain/visit/adapter/VisitSaver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.smeem.domain.visit.adapter; | ||
|
||
import com.smeem.domain.member.model.Member; | ||
import com.smeem.domain.support.RepositoryAdapter; | ||
import com.smeem.domain.visit.model.Visit; | ||
import com.smeem.domain.visit.repository.VisitRepository; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RepositoryAdapter | ||
@RequiredArgsConstructor | ||
public class VisitSaver { | ||
|
||
private final VisitRepository visitRepository; | ||
|
||
public void saveByMember(Member member) { | ||
visitRepository.save(new Visit(member)); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
smeem-domain/src/main/java/com/smeem/domain/visit/model/Visit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.smeem.domain.visit.model; | ||
|
||
import com.smeem.domain.member.model.Member; | ||
import jakarta.persistence.*; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
public class Visit { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "member_id") | ||
private Member member; | ||
|
||
private LocalDateTime visitedAt; | ||
|
||
public Visit(Member member) { | ||
this.member = member; | ||
this.visitedAt = LocalDateTime.now(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
smeem-domain/src/main/java/com/smeem/domain/visit/repository/VisitRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.smeem.domain.visit.repository; | ||
|
||
import com.smeem.domain.member.model.Member; | ||
import com.smeem.domain.visit.model.Visit; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public interface VisitRepository extends JpaRepository<Visit, Long> { | ||
|
||
boolean existsByMemberAndVisitedAtBetween(Member member, LocalDateTime start, LocalDateTime end); | ||
int countByMember(Member member); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
로직에는 문제 없지만 생성자로 인스턴스 생성은 막아두고 static method나 builder로 인스턴스를 생성해도 괜찮을 것 같아요 ~ 큰 문제 없다고 판단되면 그대로 가셔도 좋습니다~