Skip to content
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

๐Ÿš€ 3๋‹จ๊ณ„ - ์ฆ๊ฒจ์ฐพ๊ธฐ ๊ธฐ๋Šฅ ๊ตฌํ˜„ #352

Open
wants to merge 16 commits into
base: epicarts
Choose a base branch
from

Conversation

epicarts
Copy link

@epicarts epicarts commented Sep 4, 2022

์•ˆ๋…•ํ•˜์„ธ์š”! ๊ธฐ๊ฐ„์ด ๋๋‚ฌ๋Š”๋ฐ๋„ ๋ถˆ๊ตฌํ•˜๊ณ  ๋ฆฌ๋ทฐํ•ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค :)
ATDD๊ฐ•์˜์˜ ๋งˆ์ง€๋ง‰ ๋ฆฌ๋ทฐ ์š”์ฒญ์ด๋„ค์š”..!

์‹œ๊ฐ„ ๋˜์‹ค๋•Œ ์ฒœ์ฒœํžˆ ํ•ด์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌ๋“œ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค. ๐Ÿ™‡

Copy link

@HyunSung-Na HyunSung-Na left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์•ˆ๋…•ํ•˜์„ธ์š” ์˜ํ˜ธ๋‹˜!

3๋‹จ๊ณ„ ๋ฏธ์…˜์„ ์ž˜ํ•ด์ฃผ์…จ๋„ค์š”! ๐Ÿ‘

๋ช‡๊ฐ€์ง€ ์ฝ”๋ฉ˜ํŠธ ๋‚จ๊ฒผ์œผ๋‹ˆ ํ™•์ธํ•ด์ฃผ์‹œ๊ณ  ๋‹ค์‹œ ๋ฆฌ๋ทฐ ์š”์ฒญ ์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค ๐Ÿ™‡
๋๊นŒ์ง€ ๋ฆฌ๋ทฐ ์š”์ฒญ ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ๐Ÿ˜Š

.orElseThrow(IllegalArgumentException::new);

Member member = memberService.findByEmail(loginMember.getEmail());
member.removeFavorite(favorite);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

member.removeFavorite(favorite); ํ•ด์ฃผ์…จ๋Š”๋ฐ์š”! ํ™•์ธํ•ด๋ณด๋‹ˆ favorites ์—์„œ ์˜ต์…˜์ด orphanRemoval = true ๋กœ ๋˜์–ด ์žˆ๋Š”๊ฑธ ๋ดค์Šต๋‹ˆ๋‹ค! ๊ณ ์•„๊ฐ์ฒด๊ฐ€ ๋œ favorite ๋„ ๊ฐ™์ด delete ๋  ๊ฒƒ์œผ๋กœ ์˜ˆ์ƒ ๋˜๋Š”๋ฐ์š”!
55 line ์˜ favoriteRepository.delete(favorite); ๋ถ€๋ถ„์ด ํ•„์š”ํ• ๊นŒ์š”? ๐Ÿง

import static nextstep.member.domain.exception.FavoriteException.SAME_SOURCE_AND_TARGET;

@Entity
public class Favorite {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ˜„์žฌ member ์— ๋Œ€ํ•œ ์ •๋ณด๋Š” Favorite ์—์„œ ์•Œ ์ˆ˜ ์—†๋‹ค๊ณ  ๋ณด๋Š”๋ฐ์š”!
JPA ์—์„œ ์™ธ๋ž˜ํ‚ค๊ฐ€ ์—†์ด๋„ OneToMany ์™€ ManyToOne ๊ด€๊ณ„๊ฐ€ ๋งบ์–ด์งˆ ์ˆ˜ ์žˆ๋Š”์ง€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค!
์ง์ ‘์ฐธ์กฐ๋‚˜ ๊ฐ„์ ‘์ฐธ์กฐ๋ฅผ ํ•˜์ง€ ์•Š์•„๋„ ๋ ๊นŒ์š”? ๐Ÿง

ํ…Œ์ŠคํŠธ์—์„œ ๋‚˜์˜ค๋Š” ์ฟผ๋ฆฌ๋ฅผ ํ™•์ธํ•ด๋ณธ ๊ฒฐ๊ณผ
update
favorite
set
member_id=?
where
id=?

๋กœ ์—…๋ฐ์ดํŠธ ์ฟผ๋ฆฌ๋ฅผ ๋‚ ๋ฆฌ๊ณ  ์žˆ๋Š”๋ฐ์š”. favorite ์—๋Š” memberId ๊ฐ€ ์—†์Œ์—๋„ ์ฟผ๋ฆฌ๋ฅผ ๋‚ ๋ฆฌ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค!
ํ•œ๋ฒˆ ํ™•์ธํ•ด๋ณด์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ๐Ÿ˜Š

}

public Favorite addFavorite(Station source, Station target) {
Favorite favorite = new Favorite(source, target);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

member domain ์—์„œ Favorite ์ƒ์„ฑ ์—ญํ• ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š”๊ฒŒ ๋งž์„๊นŒ์š”? ์–ด๋–ป๊ฒŒ ์ƒ๊ฐํ•˜์‹œ๋‚˜์š”? ๐Ÿ˜Š

@@ -0,0 +1,10 @@
package nextstep.member.domain.exception;

public class FavoriteException extends IllegalArgumentException {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Custom ์˜ˆ์™ธ ๐Ÿ‘

*/
@DisplayName("์œ ํšจํ•˜์ง€ ์•Š์€ ๋กœ๊ทธ์ธ ์ •๋ณด๋กœ ์‚ญ์ œํ•  ์ˆ˜ ์—†๋‹ค")
@Test
void ์œ ํšจํ•˜์ง€_์•Š์€_ํ† ํฐ์œผ๋กœ_๋กœ๊ทธ์ธ_์‚ญ์ œ_์š”์ฒญ() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์˜ˆ์™ธ ํ…Œ์ŠคํŠธ ๐Ÿ‘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants