-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from Princess-in-silvertown/feat/15
Feat: 그룹 내 전체 유저 조회
- Loading branch information
Showing
4 changed files
with
59 additions
and
20 deletions.
There are no files selected for viewing
48 changes: 33 additions & 15 deletions
48
src/main/java/slvtwn/khu/toyouserver/application/GroupService.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 |
---|---|---|
@@ -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 | ||
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()); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/slvtwn/khu/toyouserver/domain/MemberRepository.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 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); | ||
} |
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
4 changes: 4 additions & 0 deletions
4
src/main/java/slvtwn/khu/toyouserver/presentation/GroupMemberResponse.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,4 @@ | ||
package slvtwn.khu.toyouserver.presentation; | ||
|
||
public record GroupMemberResponse(Long id, Long userId, String name, String profilePicture) { | ||
} |