-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #302 from Team-Smeme/sohyeon_#301
[REFACTOR] 회원의 방문 이력 테이블 추가
- Loading branch information
Showing
10 changed files
with
183 additions
and
59 deletions.
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(Visit.builder().member(member).build()); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
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,32 @@ | ||
package com.smeem.domain.visit.model; | ||
|
||
import com.smeem.domain.member.model.Member; | ||
import jakarta.persistence.*; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
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; | ||
|
||
@Builder | ||
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); | ||
} |