-
Notifications
You must be signed in to change notification settings - Fork 1
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/31-withdraw-member #32
Changes from 9 commits
1c966f3
51cd836
cd36dd1
6f91d3e
f274901
8cdc068
34e9e94
7352975
0a7c1f5
2279e3e
49189c7
9e5ccae
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.sptp.backend.common.config; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import javax.persistence.EntityManager; | ||
|
||
@Configuration | ||
public class DBConfig { | ||
@Bean | ||
public JPAQueryFactory jpaQueryFactory(EntityManager entityManager) { | ||
return new JPAQueryFactory(entityManager); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.sptp.backend.memberkeyword.repository; | ||
|
||
public interface MemberKeywordCustomRepository { | ||
void deleteByMemberId(Long memberId); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.sptp.backend.memberkeyword.repository; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import static com.sptp.backend.memberkeyword.repository.QMemberKeyword.*; | ||
|
||
@RequiredArgsConstructor | ||
public class MemberKeywordCustomRepositoryImpl implements MemberKeywordCustomRepository { | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
@Override | ||
public void deleteByMemberId(Long memberId) { | ||
queryFactory.delete(memberKeyword) | ||
.where(memberKeyword.member.id.eq(memberId)) | ||
.execute(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.sptp.backend.memberkeyword.repository; | ||
|
||
import com.sptp.backend.common.config.DBConfig; | ||
import com.sptp.backend.common.config.PropertyConfig; | ||
import com.sptp.backend.member.repository.Member; | ||
import com.sptp.backend.memberkeyword.MemberKeywordMap; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
import org.springframework.context.annotation.Import; | ||
|
||
import javax.persistence.EntityManager; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
@DataJpaTest | ||
@Import({DBConfig.class, PropertyConfig.class}) | ||
class MemberKeywordRepositoryTest { | ||
|
||
@Autowired | ||
EntityManager entityManager; | ||
|
||
@Autowired | ||
MemberKeywordRepository memberKeywordRepository; | ||
|
||
@Nested | ||
class deleteByMemberIdTest { | ||
|
||
Member member = createMember(); | ||
|
||
@BeforeEach | ||
void init() { | ||
// ํ ์คํธ์ฉ ๋ฐ์ดํฐ ์ฝ์ | ||
entityManager.persist(member); | ||
for (int keywordId = 1; keywordId < 3; keywordId++) { | ||
entityManager.persist(createMemberKeyword(member, keywordId)); | ||
} | ||
} | ||
|
||
@Test | ||
void success() { | ||
//given | ||
long memberId = member.getId(); | ||
long count = memberKeywordRepository.count(); | ||
|
||
//when | ||
memberKeywordRepository.deleteByMemberId(memberId); | ||
long currentCount = memberKeywordRepository.count(); | ||
|
||
//then | ||
Assertions.assertThat(count).isNotEqualTo(currentCount); | ||
Assertions.assertThat(currentCount).isEqualTo(0L); | ||
} | ||
} | ||
|
||
private static MemberKeyword createMemberKeyword(Member member, int keywordId) { | ||
return MemberKeyword.builder() | ||
.member(member) | ||
.keywordId(keywordId) | ||
.build(); | ||
} | ||
|
||
private static Member createMember() { | ||
|
||
return Member.builder() | ||
.userId("test") | ||
.password("12345678") | ||
.build(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
spring: | ||
test: | ||
database: | ||
# replace: none // ์ธ๋ฉ๋ชจ๋ฆฌ DB๊ฐ ์๋ MySQL์ ์ฌ์ฉํ๊ธฐ ์ํ ์ค์ | ||
|
||
datasource: | ||
url: ${application.spring.datasource.url} | ||
username: ${application.spring.datasource.username} | ||
password: ${application.spring.datasource.password} | ||
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. ์ด๊ฑฐ test/resources์ env.propertiesํ์ผ ์ถ๊ฐํ์ ์ ์ ์ฉํ์ ๊ฑด๊ฐ์? ๊ทธ๋ ๋ค๋ฉด ํน์ ๊ธฐ์กด์ main/resources์ ์๋ env.properties์ ๋ณ์๋ช ๊ณผ ๊ฐ์๋ฐ ๋ฌธ์ ์๋์?? ์ env.propertiesํ์ผ์ ๋ณ์๊ฐ ํ๊ฒฝ๋ณ์๋ก ๋ฑ๋ก๋๋ ๊ฑธ๋ก ์๊ณ ์์ด์์! 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. ์ test/resources์ ํ์ผ ์๋ก ์์ฑํ๊ฑฐ ๋ง์ต๋๋ค! main์ ์๋ ํด๋์ ๋ค๋ฅธ ์ ์ url์ด h2๋ฅผ ๊ฐ๋ฅดํจ๋ค๋ ์ ์ด์์ฉ 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. main์ envํ์ผ์์ ํ๊ฒฝ๋ณ์๋ก ๋ฑ๋กํ ๊ฒ๊ณผ ๋ณ์๋ช ์ด ๊ฐ์๋ฐ ๊ด์ฐฎ๋์ฉ? application.spring.datasource.url ๋ณ์๋ช ์ ๋ค๋ฅด๊ฒ ํด์ผํ์ง ์๋ ์ถ์ด์์! ๋ ์ค ํ๋๋ ๊ฐ์ด ๋ฎ์ด ์์ด์ง์ง ์์๊น ์ถ์ด์ 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. ๋ณ์๋ช ์ ์ฌ์ค ์ด๋ค ๊ฑธ ์จ๋ ๋ฌด๋ฐฉํด์ ๊ธฐ์กด main์ envํ์ผ์์ ๋ฑ๋กํ๋ ํ๊ฒฝ๋ณ์๋ช ๊ณผ ๋ค๋ฅด๊ฒ ๋ค์ด๋ฐ ํด์ฃผ์๋ฉด ์ข์๊ฑฐ๊ฐ์์-! test.application.spring.datasource.url์ฒ๋ผ ์์ test๋ง ๋ถ์ฌ์ฃผ์ ๋ ๊ด์ฐฎ๊ตฌ์ฉ 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. ๋ฐ๊พผ๋ค๋ฉด url ๋ฟ๋ง ์๋๋ผ Oauth์ ๊ฐ์ ๊ฒ๋ค๋ ๋ชจ๋ test๋ฅผ ๋ถ์ธ ๋ณ์๋ช
์ผ๋ก ์์ ํ๋ ๊ฒ์ด ์ข๋ค๊ณ ์๊ฐํฉ๋๋ค. 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. 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. ๊ทธ๊ฒ๋ ๊ด์ฐฎ์ ๊ฑฐ ๊ฐ์์ฉ ๋น๋ฐ๋ฒํธ ์ ๋ ๊ฒ ์ ๋ ฅ ์ ํด์ค๋ ์์์ h2 ๊ตฌ๋์ด ๋๋๊ฑด๊ฐ์?? 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. ๋ต ๋ง์ต๋๋ค 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. ๊ทธ๋ผ h2๊ด๋ จ ๋ถ๋ถ์ ๋นผ๋ ๊ฑธ๋ก ํฉ์๋น 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. ์์ ํ๊ณ ๋ฐ๋ก ๋จธ์งํ ๊ป์ฅ |
||
driver-class-name: org.h2.Driver | ||
|
||
jpa: | ||
hibernate: | ||
ddl-auto: create | ||
properties: | ||
hibernate: | ||
format_sql: true |
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.
Member์ ์ฌ๋ฌ ํ๋ ์ค userId๋ passwordํ๋๋ฅผ ๋ฃ์ด์ฃผ์ ๊ฑด ์ถํ ํ ์คํธ๋ฅผ ์ํจ์ธ๊ฐ์?
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.
์ ๋ถ null๊ฐ์ ๊ฐ์ ธ๋ ๋์ง๋ง, userId์ password ์ ๋๋ง ์์๋ก ์ถ๊ฐํ์ต๋๋ค. ์ ๊ฑฐํด๋ ๋ฌด๋ฐฉํฉ๋๋น
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.
๋ต!