-
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: 그룹 내 전체 유저 조회 #22
Changes from all commits
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 |
---|---|---|
@@ -1,36 +1,54 @@ | ||
package slvtwn.khu.toyouserver.application; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import slvtwn.khu.toyouserver.common.ErrorType; | ||
import slvtwn.khu.toyouserver.domain.Group; | ||
import slvtwn.khu.toyouserver.domain.MemberRepository; | ||
import slvtwn.khu.toyouserver.domain.User; | ||
import slvtwn.khu.toyouserver.dto.GroupResponse; | ||
import slvtwn.khu.toyouserver.exception.ToyouException; | ||
import slvtwn.khu.toyouserver.persistance.GroupRepository; | ||
import slvtwn.khu.toyouserver.persistance.UserRepository; | ||
import slvtwn.khu.toyouserver.presentation.GroupMemberResponse; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
public class GroupService { | ||
|
||
private final GroupRepository groupRepository; | ||
private final UserRepository userRepository; | ||
private final GroupRepository groupRepository; | ||
private final UserRepository userRepository; | ||
private final MemberRepository memberRepository; | ||
|
||
public GroupService(GroupRepository groupRepository, UserRepository userRepository) { | ||
this.groupRepository = groupRepository; | ||
this.userRepository = userRepository; | ||
} | ||
public GroupService(GroupRepository groupRepository, UserRepository userRepository, | ||
MemberRepository memberRepository) { | ||
this.groupRepository = groupRepository; | ||
this.userRepository = userRepository; | ||
this.memberRepository = memberRepository; | ||
} | ||
|
||
@Transactional | ||
public GroupResponse registerUser(long groupId, long userId) { | ||
Group group = groupRepository.findById(groupId) | ||
.orElseThrow(() -> new ToyouException(ErrorType.GROUP_NOT_FOUND)); | ||
User user = userRepository.findById(userId) | ||
.orElseThrow(() -> new ToyouException(ErrorType.USER_NOT_FOUND)); | ||
@Transactional | ||
public GroupResponse registerUser(long groupId, long userId) { | ||
Group group = groupRepository.findById(groupId) | ||
.orElseThrow(() -> new ToyouException(ErrorType.GROUP_NOT_FOUND)); | ||
User user = userRepository.findById(userId) | ||
.orElseThrow(() -> new ToyouException(ErrorType.USER_NOT_FOUND)); | ||
|
||
// TODO : 그룹에 유저를 가입시킨다. 유저는 멤버로 등록된다. | ||
// TODO : 그룹에 유저를 가입시킨다. 유저는 멤버로 등록된다. | ||
// group.addMember(user); | ||
return new GroupResponse(group.getId(), group.getName()); | ||
} | ||
return new GroupResponse(group.getId(), group.getName()); | ||
} | ||
|
||
@Transactional | ||
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. readonly 클래스 레벨에서 걸려있으니 Transactional 빼도 됩니다! 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. #24 처럼 Group 생성하는 기능은 조회하는 메소드가 아니지만 |
||
public List<GroupMemberResponse> getRegisteredMembers(long groupId) { | ||
return memberRepository.findByGroupId(groupId).stream() | ||
.map(member -> new GroupMemberResponse( | ||
member.getId(), | ||
member.getUser().getId(), | ||
member.getUser().getName(), | ||
member.getUser().getProfilePicture())) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package slvtwn.khu.toyouserver.domain; | ||
|
||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface MemberRepository extends JpaRepository<Member, Long> { | ||
List<Member> findByGroupId(Long groupId); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package slvtwn.khu.toyouserver.presentation; | ||
|
||
public record GroupMemberResponse(Long id, Long userId, String name, String profilePicture) { | ||
} |
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.
주석은 공공의 적입니다 😕
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.
해당 브랜치에서 개발 안하던 부분이라 너무 거슬렸었는데 제가 써둔 거였네요 🤦🏻 추가 수정하겠습니다