-
Notifications
You must be signed in to change notification settings - Fork 2
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
Feat : 회원 엔티티 추가 및 회원조회기능 추가 #8
Merged
+192
−3
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
49cb06a
Feat : 회원 엔티티 추가 및 회원조회기능 추가
Suhun0331 a80d69d
Test: 유저정보 저장 및 조회 테스트 오류 수정
Suhun0331 1adc8cc
Test: 유저정보 저장 및 조회 테스트 오류 수정2
Suhun0331 c252022
Test: 유저정보 저장 및 조회 테스트 오류 수정3
Suhun0331 63c50fc
Feat : 회원 엔티티 추가 및 회원조회기능 추가
Suhun0331 1a88453
Update : .gitignore & application.properties
Suhun0331 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,5 @@ out/ | |
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
|
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
13 changes: 13 additions & 0 deletions
13
src/main/java/umc/kkijuk/server/member/controller/MemberController.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 umc.kkijuk.server.member.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Controller; | ||
import umc.kkijuk.server.member.service.MemberService; | ||
|
||
@Controller | ||
@RequiredArgsConstructor | ||
public class MemberController { | ||
|
||
private final MemberService memberService; | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/umc/kkijuk/server/member/converter/StringListConverter.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,33 @@ | ||
package umc.kkijuk.server.member.converter; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import jakarta.persistence.AttributeConverter; | ||
import jakarta.persistence.Converter; | ||
|
||
import java.util.List; | ||
|
||
@Converter | ||
public class StringListConverter implements AttributeConverter<List<String>, String> { | ||
|
||
private final ObjectMapper mapper = new ObjectMapper(); | ||
|
||
|
||
@Override | ||
public String convertToDatabaseColumn(List<String> entityData) { | ||
try { | ||
return mapper.writeValueAsString(entityData); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public List<String> convertToEntityAttribute(String dbData) { | ||
try { | ||
return mapper.readValue(dbData, List.class); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
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,58 @@ | ||
package umc.kkijuk.server.member.domain; | ||
|
||
import jakarta.persistence.*; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.*; | ||
import umc.kkijuk.server.member.converter.StringListConverter; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
import java.util.ArrayList; | ||
|
||
@Entity | ||
@Builder | ||
@Getter @Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Member { | ||
|
||
@Id @GeneratedValue | ||
@Column(name = "member_id") | ||
private Long id; | ||
|
||
@NotNull | ||
private String email; | ||
|
||
@NotNull | ||
private String name; | ||
|
||
@NotNull | ||
private String phoneNumber; | ||
|
||
@NotNull | ||
private LocalDate birthDate; | ||
|
||
@NotNull | ||
private String password; | ||
|
||
@Convert(converter = StringListConverter.class) | ||
private List<String> field = new ArrayList<>(); | ||
|
||
@NotNull | ||
private Boolean marketingAgree; | ||
|
||
@NotNull | ||
@Enumerated(EnumType.STRING) | ||
private State userState; | ||
|
||
public Member(String email, String name, String phoneNumber, LocalDate birthDate, String password, Boolean marketingAgree, State userState) { | ||
this.email = email; | ||
this.name = name; | ||
this.phoneNumber = phoneNumber; | ||
this.birthDate = birthDate; | ||
this.password = password; | ||
this.marketingAgree = marketingAgree; | ||
this.userState = userState; | ||
} | ||
} | ||
|
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,6 @@ | ||
package umc.kkijuk.server.member.domain; | ||
|
||
public enum State { | ||
ACTIVATE , | ||
INACTIVATE | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/umc/kkijuk/server/member/repository/MemberJpaRepository.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,10 @@ | ||
package umc.kkijuk.server.member.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import umc.kkijuk.server.member.domain.Member; | ||
|
||
import java.util.Optional; | ||
|
||
public interface MemberJpaRepository extends JpaRepository<Member, Long>{ | ||
Optional<Member> findById(Long id); | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/umc/kkijuk/server/member/service/MemberService.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,28 @@ | ||
package umc.kkijuk.server.member.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import umc.kkijuk.server.member.domain.Member; | ||
import umc.kkijuk.server.member.repository.MemberJpaRepository; | ||
import umc.kkijuk.server.recruit.domain.Recruit; | ||
import umc.kkijuk.server.recruit.infrastructure.RecruitEntity; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class MemberService { | ||
private final MemberJpaRepository memberJpaRepository; | ||
|
||
public Member findOne(Long memberId) { | ||
return memberJpaRepository.findById(memberId).get(); | ||
} | ||
|
||
|
||
//아직 인터페이스 구현 x, 추후에 구현 후 MemberService -> MemberServiceImpl로 수정 예정. | ||
public Long join(Member member) { | ||
memberJpaRepository.save(member); | ||
return member.getId(); | ||
} | ||
|
||
} |
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
39 changes: 39 additions & 0 deletions
39
src/test/java/umc/kkijuk/server/member/service/MemberServiceTest.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,39 @@ | ||
package umc.kkijuk.server.member.service; | ||
|
||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import umc.kkijuk.server.member.domain.Member; | ||
import umc.kkijuk.server.member.domain.State; | ||
import umc.kkijuk.server.member.repository.MemberJpaRepository; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
|
||
@SpringBootTest | ||
@Transactional | ||
public class MemberServiceTest { | ||
|
||
@Autowired MemberService memberService; | ||
@Autowired | ||
MemberJpaRepository memberJpaRepository; | ||
|
||
@Test | ||
public void 유저정보db저장및조회() throws Exception { | ||
//given | ||
Member member1 = new Member("[email protected]", "홍길동", "010-7444-1768", LocalDate.now(), "passwordTest", Boolean.TRUE, State.ACTIVATE); | ||
//when | ||
Long savedId = memberService.join(member1); | ||
Optional<Member> member2 = memberJpaRepository.findById(savedId); | ||
//then | ||
assertEquals(member1, member2.get()); | ||
} | ||
} |
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.
src/main/java/umc/kkujuk/server/common/converter에 동일한 동작을 하는 StringListToStringConverter가 존재하니 혹여나 동일한 동작을 한다면 수정해주세요!
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.
엇 확인 못하고 만든거였는데 확인 했습니다!