-
Notifications
You must be signed in to change notification settings - Fork 0
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: 회원 상세 정보 저장 및 조회 구현 #9
Changes from 225 commits
7d1e91a
4117809
208fd0e
0d8e60b
226ad3a
bbd7b66
4a84e31
5e7cd52
02a0cea
f439212
7b2af53
9fc8b60
d01bc01
741d8aa
b206757
6fd0553
18123be
4e3d4d1
db4e702
d7f3f93
5ee2eba
1a7a8ff
8481b08
8cb873b
0b7d094
e615cd4
a77c05f
014751a
7e29a6d
504e59d
d3b3ea9
a5705eb
fb28387
47fa1a0
f6e5215
07f60d0
fdfb4d2
28e0570
1f61cf0
be7ce4d
d7d79ab
9f7904d
7a63627
a2ef0d9
d9a5089
f66f1f4
18db8df
e58e6b2
7e62fb8
5b70292
1e58309
00da0ba
ec7cde9
c8c05a7
f35e9c6
d1c3cb1
153bcb1
8e53aef
381d8b5
f0fa2a9
d1a4d0c
e0370d7
5d70f1a
aabc021
050ce6c
1cc1470
9e7c033
4bde570
cb9188d
8310c83
dd7cd0b
91465b0
34817bb
5ca32b2
9dd50e9
c39a9f2
abeb3ef
b5e945b
88777a5
5194b38
cf4c7e6
79c79c5
c16341a
84f3006
41e30f7
d6e166e
b460eeb
31209e6
e017194
b9d475a
67ef079
570f2f4
dfed61b
976e410
f39669b
4eda5dd
2d84172
551f0e3
2d961ce
56354cb
bd9fa81
d4fa067
1d733d6
439b19c
5f8aaa0
8263a1e
8cd2391
3884a88
0fcd5f4
9864d37
e46c0ce
a84e8f9
e59e03c
f532a38
ae46225
24d33b6
43e3aca
6bbdcb2
737c4cb
9ee676d
e5b20de
66ef872
c483c34
007cffc
b4c00f6
869dabf
e3e3967
bc7a3fd
ba3cc01
bcc9e29
d2965cf
00929b1
c3dbae3
6a06503
c940570
f755d7f
6d99997
3869917
7e65680
bca409a
8582f6e
4a46263
5b4bc02
fced5f3
8a2b93b
b27b398
9901c37
0f4ee57
756fd8c
6a1d0ea
b7f5894
8dfcf4d
5cba3d3
8f66dae
616c472
f1e6f8f
d69db5c
84c2e61
57303b2
9c369dc
fca4ffb
e916d1b
a9597b8
89b38c5
e2bc9bc
18b2041
73107c3
3612110
9494c63
af7d92c
9a4eee7
50612de
83241e1
77dcc60
989fffa
8495097
3f77b04
a961677
9db6534
2ff647c
5804df5
ccf0e67
6e6998a
6bb85db
cef5341
b53a6d1
90d982f
4c393ed
517401b
64049be
35d1ec1
e1db46e
cfff6cc
6e8bd28
1e41618
1efb1f6
654235e
d6eacb3
c6b7147
34f4d3f
9b12d09
6ad6749
920fad8
3cf519b
c9aae30
087c304
dff9f00
b4777a8
9be88b7
a0a1eff
32a3fe7
0c8d4cf
1308dc4
10e2808
40e8796
d64c1c2
7fad512
0217c19
b5cb745
a5cde12
1b23328
ded8bd8
b0433e0
26513b3
972ede0
7201923
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,37 @@ | ||
:toc: left | ||
:source-highlighter: highlightjs | ||
:sectlinks: | ||
:toclevels: 2 | ||
:sectlinks: | ||
:sectnums: | ||
|
||
== Info | ||
|
||
=== 회원 정보 작성 | ||
|
||
==== 요청 | ||
include::{snippets}/info-controller-web-mvc-test/write_info/http-request.adoc[] | ||
include::{snippets}/info-controller-web-mvc-test/write_info/request-headers.adoc[] | ||
include::{snippets}/info-controller-web-mvc-test/write_info/request-fields.adoc[] | ||
|
||
==== 응답 | ||
include::{snippets}/info-controller-web-mvc-test/write_info/http-response.adoc[] | ||
|
||
=== 회원 정보 수정 | ||
|
||
==== 요청 | ||
include::{snippets}/info-controller-web-mvc-test/update_info/http-request.adoc[] | ||
include::{snippets}/info-controller-web-mvc-test/update_info/request-headers.adoc[] | ||
include::{snippets}/info-controller-web-mvc-test/update_info/request-fields.adoc[] | ||
|
||
==== 응답 | ||
include::{snippets}/info-controller-web-mvc-test/update_info/http-response.adoc[] | ||
|
||
=== 회원 정보 조회 | ||
|
||
==== 요청 | ||
include::{snippets}/info-controller-web-mvc-test/search_info/http-request.adoc[] | ||
include::{snippets}/info-controller-web-mvc-test/search_info/request-headers.adoc[] | ||
==== 응답 | ||
include::{snippets}/info-controller-web-mvc-test/search_info/http-response.adoc[] | ||
include::{snippets}/info-controller-web-mvc-test/search_info/response-fields.adoc[] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.atwoz.member.application.info; | ||
|
||
import com.atwoz.global.event.Events; | ||
import com.atwoz.member.application.info.hobby.event.HobbyUpdatedEvent; | ||
import com.atwoz.member.application.info.hobby.event.HobbyWroteEvent; | ||
import com.atwoz.member.application.info.option.event.OptionUpdatedEvent; | ||
import com.atwoz.member.application.info.option.event.OptionWroteEvent; | ||
import com.atwoz.member.application.info.profile.event.ProfileUpdatedEvent; | ||
import com.atwoz.member.application.info.profile.event.ProfileWroteEvent; | ||
import com.atwoz.member.application.info.style.event.StyleUpdatedEvent; | ||
import com.atwoz.member.application.info.style.event.StyleWroteEvent; | ||
import com.atwoz.member.application.info.hobby.dto.HobbyUpdateRequest; | ||
import com.atwoz.member.application.info.hobby.dto.HobbyWriteRequest; | ||
import com.atwoz.member.application.info.dto.InfoUpdateRequest; | ||
import com.atwoz.member.application.info.dto.InfoWriteRequest; | ||
import com.atwoz.member.application.info.style.dto.StyleUpdateRequest; | ||
import com.atwoz.member.application.info.style.dto.StyleWriteRequest; | ||
import com.atwoz.member.domain.info.InfoRepository; | ||
import com.atwoz.member.exception.exceptions.info.InfoNotFoundException; | ||
import com.atwoz.member.infrastructure.info.dto.InfoSearchResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
@Service | ||
public class InfoService { | ||
|
||
private final InfoRepository infoRepository; | ||
|
||
@Transactional | ||
public void writeInfo(final Long memberId, final InfoWriteRequest request) { | ||
List<String> hobbyCodes = extractHobbyNamesFromInfoWriteRequest(request); | ||
List<String> styleCodes = extractStyleNamesFromInfoWriteRequest(request); | ||
|
||
Events.raise(new ProfileWroteEvent(memberId, request.profile())); | ||
Events.raise(new OptionWroteEvent(memberId, request.option())); | ||
|
||
Events.raise(new HobbyWroteEvent(memberId, hobbyCodes)); | ||
Events.raise(new StyleWroteEvent(memberId, styleCodes)); | ||
} | ||
|
||
private List<String> extractHobbyNamesFromInfoWriteRequest(final InfoWriteRequest request) { | ||
return request.hobbies() | ||
.stream() | ||
.map(HobbyWriteRequest::hobby) | ||
.toList(); | ||
} | ||
|
||
private List<String> extractStyleNamesFromInfoWriteRequest(final InfoWriteRequest request) { | ||
return request.styles() | ||
.stream() | ||
.map(StyleWriteRequest::style) | ||
.toList(); | ||
} | ||
|
||
@Transactional | ||
public void updateInfo(final Long memberId, final InfoUpdateRequest request) { | ||
List<String> hobbyCodes = extractHobbyNamesFromInfoUpdateRequest(request); | ||
List<String> styleCodes = extractStyleNamesFromInfoUpdateRequest(request); | ||
|
||
Events.raise(new ProfileUpdatedEvent(memberId, request.profile())); | ||
Events.raise(new OptionUpdatedEvent(memberId, request.option())); | ||
|
||
Events.raise(new HobbyUpdatedEvent(memberId, hobbyCodes)); | ||
Events.raise(new StyleUpdatedEvent(memberId, styleCodes)); | ||
} | ||
|
||
private List<String> extractHobbyNamesFromInfoUpdateRequest(final InfoUpdateRequest request) { | ||
return request.hobbies() | ||
.stream() | ||
.map(HobbyUpdateRequest::hobby) | ||
.toList(); | ||
} | ||
|
||
private List<String> extractStyleNamesFromInfoUpdateRequest(final InfoUpdateRequest request) { | ||
return request.styles() | ||
.stream() | ||
.map(StyleUpdateRequest::style) | ||
.toList(); | ||
} | ||
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. 이것도 request 값 꺼내서 넘겨주세요~ 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. 수정하였습니다 :) |
||
|
||
public InfoSearchResponse findInfo(final Long memberId) { | ||
return infoRepository.findByMemberId(memberId) | ||
.orElseThrow(InfoNotFoundException::new); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.atwoz.member.application.info.dto; | ||
|
||
import com.atwoz.member.application.info.hobby.dto.HobbyUpdateRequest; | ||
import com.atwoz.member.application.info.option.dto.OptionUpdateRequest; | ||
import com.atwoz.member.application.info.profile.dto.ProfileUpdateRequest; | ||
import com.atwoz.member.application.info.style.dto.StyleUpdateRequest; | ||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.NotNull; | ||
import java.util.List; | ||
|
||
public record InfoUpdateRequest( | ||
@Valid | ||
@NotNull(message = "profile 요청이 있어야 합니다.") | ||
ProfileUpdateRequest profile, | ||
|
||
@Valid | ||
@NotNull(message = "option 요청이 있어야 합니다.") | ||
OptionUpdateRequest option, | ||
|
||
@Valid | ||
@NotNull(message = "취미 요청이 있어야 합니다.") | ||
List<HobbyUpdateRequest> hobbies, | ||
|
||
@Valid | ||
@NotNull(message = "스타일 요청이 있어야 합니다.") | ||
List<StyleUpdateRequest> styles | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.atwoz.member.application.info.dto; | ||
|
||
import com.atwoz.member.application.info.hobby.dto.HobbyWriteRequest; | ||
import com.atwoz.member.application.info.option.dto.OptionWriteRequest; | ||
import com.atwoz.member.application.info.profile.dto.ProfileWriteRequest; | ||
import com.atwoz.member.application.info.style.dto.StyleWriteRequest; | ||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.NotNull; | ||
import java.util.List; | ||
|
||
public record InfoWriteRequest( | ||
@Valid | ||
@NotNull(message = "profile 요청이 있어야 합니다.") | ||
ProfileWriteRequest profile, | ||
|
||
@Valid | ||
@NotNull(message = "option 요청이 있어야 합니다.") | ||
OptionWriteRequest option, | ||
|
||
@Valid | ||
@NotNull(message = "취미 요청이 있어야 합니다.") | ||
List<HobbyWriteRequest> hobbies, | ||
|
||
@Valid | ||
@NotNull(message = "스타일 요청이 있어야 합니다.") | ||
List<StyleWriteRequest> styles | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.atwoz.member.application.info.hobby; | ||
|
||
import com.atwoz.member.application.info.hobby.event.HobbyUpdatedEvent; | ||
import com.atwoz.member.application.info.hobby.event.HobbyWroteEvent; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.stereotype.Component; | ||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class HobbyEventHandler { | ||
|
||
private final MemberHobbyService memberHobbyService; | ||
|
||
@EventListener | ||
public void writeHobbies(final HobbyWroteEvent event) { | ||
Long memberId = event.getMemberId(); | ||
List<String> hobbyCodes = event.getHobbyCodes(); | ||
|
||
memberHobbyService.saveMemberHobbies(memberId, hobbyCodes); | ||
} | ||
|
||
@EventListener | ||
public void updateHobbies(final HobbyUpdatedEvent event) { | ||
Long memberId = event.getMemberId(); | ||
List<String> hobbyCodes = event.getHobbyCodes(); | ||
|
||
memberHobbyService.updateMemberHobbies(memberId, hobbyCodes); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.atwoz.member.application.info.hobby; | ||
|
||
import com.atwoz.member.domain.info.hobby.Hobby; | ||
import com.atwoz.member.domain.info.hobby.MemberHobby; | ||
import com.atwoz.member.domain.info.hobby.MemberHobbyRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
@Service | ||
public class MemberHobbyService { | ||
|
||
private final MemberHobbyRepository memberHobbyRepository; | ||
|
||
@Transactional | ||
public void saveMemberHobbies(final Long memberId, final List<String> hobbyCodes) { | ||
saveMemberHobbiesByHobbyCodes(memberId, hobbyCodes); | ||
} | ||
|
||
private void saveMemberHobbiesByHobbyCodes(final Long memberId, final List<String> hobbyCodes) { | ||
List<MemberHobby> memberHobbies = Hobby.findAllByCodes(hobbyCodes) | ||
.stream() | ||
.map(hobby -> new MemberHobby(memberId, hobby)) | ||
.toList(); | ||
|
||
memberHobbyRepository.saveAll(memberHobbies); | ||
} | ||
|
||
@Transactional | ||
public void updateMemberHobbies(final Long memberId, final List<String> hobbyCodes) { | ||
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. 이것과 관련해서는 고민점이 있습니다.
|
||
memberHobbyRepository.deleteHobbiesByMemberId(memberId); | ||
|
||
saveMemberHobbiesByHobbyCodes(memberId, hobbyCodes); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.atwoz.member.application.info.hobby.dto; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
|
||
public record HobbyUpdateRequest( | ||
@NotBlank(message = "취미가 작성되어야 합니다.") | ||
String hobby | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.atwoz.member.application.info.hobby.dto; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
|
||
public record HobbyWriteRequest( | ||
@NotBlank(message = "취미가 작성되어야 합니다.") | ||
String hobby | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.atwoz.member.application.info.hobby.event; | ||
|
||
import com.atwoz.global.event.Event; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import java.util.List; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class HobbyUpdatedEvent extends Event { | ||
|
||
private final Long memberId; | ||
private final List<String> hobbyCodes; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.atwoz.member.application.info.hobby.event; | ||
|
||
import com.atwoz.global.event.Event; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import java.util.List; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class HobbyWroteEvent extends Event { | ||
|
||
private final Long memberId; | ||
private final List<String> hobbyCodes; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.atwoz.member.application.info.option; | ||
|
||
import com.atwoz.member.application.info.option.event.OptionUpdatedEvent; | ||
import com.atwoz.member.application.info.option.event.OptionWroteEvent; | ||
import com.atwoz.member.application.info.option.dto.OptionUpdateRequest; | ||
import com.atwoz.member.application.info.option.dto.OptionWriteRequest; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.stereotype.Component; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class OptionEventHandler { | ||
|
||
private final OptionService optionService; | ||
|
||
@EventListener | ||
public void writeOption(final OptionWroteEvent event) { | ||
Long memberId = event.getMemberId(); | ||
OptionWriteRequest request = event.getRequest(); | ||
|
||
optionService.writeOption(memberId, request); | ||
} | ||
|
||
@EventListener | ||
public void updateOption(final OptionUpdatedEvent event) { | ||
Long memberId = event.getMemberId(); | ||
OptionUpdateRequest request = event.getRequest(); | ||
|
||
optionService.updateOption(memberId, request); | ||
} | ||
} |
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.
request.styles().stream(), request.hobbies().stream()이 한 맥락인데 매개변수를 InfoWriteRequest로 받는 이유가 있나요?
한 줄에 체이닝을 한번 사용하기 위해 일부러 분리한 것 처럼 보이네요
request를 넘기지 말고 값을 꺼내서 넘기도록 수정해주세요~
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.
값을 한번 꺼내서 넘기면 불필요한 체이닝을 제거할 수 있겠군요..! 수정 완료하였습니다 :)