-
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.
[SWM-412] Feat : develop member jpa repository impl
- Loading branch information
Showing
14 changed files
with
169 additions
and
0 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
3 changes: 3 additions & 0 deletions
3
src/main/java/com/m9d/sroom/common/entity/jpa/embedded/ContentInfo.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
3 changes: 3 additions & 0 deletions
3
src/main/java/com/m9d/sroom/common/entity/jpa/embedded/Feedback.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
2 changes: 2 additions & 0 deletions
2
src/main/java/com/m9d/sroom/common/entity/jpa/embedded/Grading.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
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
3 changes: 3 additions & 0 deletions
3
src/main/java/com/m9d/sroom/common/entity/jpa/embedded/MemberStats.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
3 changes: 3 additions & 0 deletions
3
src/main/java/com/m9d/sroom/common/entity/jpa/embedded/Review.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
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
3 changes: 3 additions & 0 deletions
3
src/main/java/com/m9d/sroom/common/entity/jpa/embedded/Sequence.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
40 changes: 40 additions & 0 deletions
40
src/main/java/com/m9d/sroom/common/repository/member/MemberJpaRepositoryImpl.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,40 @@ | ||
package com.m9d.sroom.common.repository.member; | ||
|
||
import com.m9d.sroom.common.entity.jpa.MemberEntity; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import javax.persistence.EntityManager; | ||
import javax.persistence.PersistenceContext; | ||
import java.util.Optional; | ||
|
||
@Repository | ||
public class MemberJpaRepositoryImpl { | ||
|
||
@PersistenceContext | ||
EntityManager em; | ||
|
||
public MemberEntity save(MemberEntity member) { | ||
em.persist(member); | ||
return member; | ||
} | ||
|
||
public MemberEntity getById(Long memberId) { | ||
return em.find(MemberEntity.class, memberId); | ||
} | ||
|
||
public MemberEntity getByCode(String memberCode) { | ||
return em.createQuery("select m from MemberEntity m where m.memberCode = :memberCode", | ||
MemberEntity.class) | ||
.setParameter("memberCode", memberCode) | ||
.getSingleResult(); | ||
} | ||
|
||
public Optional<MemberEntity> findById(Long memberId) { | ||
return Optional.ofNullable(getById(memberId)); | ||
} | ||
|
||
public Optional<MemberEntity> findByCode(String memberCode) { | ||
return Optional.ofNullable(getByCode(memberCode)); | ||
} | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
src/test/java/com/m9d/sroom/member/MemberRepositoryTest.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,67 @@ | ||
package com.m9d.sroom.member; | ||
|
||
import com.m9d.sroom.common.entity.jpa.MemberEntity; | ||
import com.m9d.sroom.common.repository.member.MemberJpaRepositoryImpl; | ||
import com.m9d.sroom.util.SroomTest; | ||
import com.m9d.sroom.util.TestConstant; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import java.util.Optional; | ||
|
||
public class MemberRepositoryTest extends SroomTest { | ||
|
||
@Autowired | ||
private MemberJpaRepositoryImpl memberJpaRepository; | ||
|
||
@Test | ||
@DisplayName("저장되지 않은 member는 Optional.isEmpty() = true 입니다.") | ||
void nullIfNotSavedMember() { | ||
//given | ||
Optional<MemberEntity> memberEntityOptional = memberJpaRepository.findById(1L); | ||
|
||
//when | ||
|
||
|
||
//then | ||
Assertions.assertEquals(Optional.empty(), memberEntityOptional); | ||
} | ||
|
||
@Test | ||
@DisplayName("저장된 member는 조회에 성공합니다.") | ||
void getMemberIfSaved() { | ||
MemberEntity memberEntity = MemberEntity.builder() | ||
.memberCode(TestConstant.MEMBER_CODE) | ||
.memberName(TestConstant.MEMBER_PROFILE) | ||
.build(); | ||
memberJpaRepository.save(memberEntity); | ||
|
||
//when | ||
Optional<MemberEntity> memberEntityOptional = memberJpaRepository.findById(1L); | ||
|
||
//then | ||
Assertions.assertNotEquals(memberEntityOptional, Optional.empty()); | ||
Assertions.assertEquals(memberEntityOptional.get().getMemberName(), TestConstant.MEMBER_PROFILE); | ||
} | ||
|
||
@Test | ||
@DisplayName("jpa 사용하면 멤버 이름을 수정하기만 해도 db 에 반영됩니다.") | ||
void updateMemberName() { | ||
//given | ||
MemberEntity memberEntity = MemberEntity.builder() | ||
.memberCode(TestConstant.MEMBER_CODE) | ||
.memberName(TestConstant.MEMBER_PROFILE) | ||
.build(); | ||
memberJpaRepository.save(memberEntity); | ||
|
||
//when | ||
String newName = "수정될 이름임 ㅇㅇ"; | ||
memberEntity.updateName(newName); | ||
|
||
//then | ||
MemberEntity member = memberJpaRepository.getById(1L); | ||
Assertions.assertEquals(member.getMemberName(), newName); | ||
} | ||
} |
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