-
Notifications
You must be signed in to change notification settings - Fork 1
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 #108 from ghdcksgml1/dev
Merge dev branch
- Loading branch information
Showing
4 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
...src/main/java/com/heachi/housework/api/controller/group/member/GroupMemberController.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,31 @@ | ||
package com.heachi.housework.api.controller.group.member; | ||
|
||
import com.heachi.admin.common.response.JsonResult; | ||
import com.heachi.housework.api.controller.group.member.response.GroupMemberResponse; | ||
import com.heachi.housework.api.service.auth.AuthExternalService; | ||
import com.heachi.housework.api.service.group.member.GroupMemberService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/group/member") | ||
public class GroupMemberController { | ||
private final AuthExternalService authExternalService; | ||
private final GroupMemberService groupMemberService; | ||
|
||
@GetMapping("/{groupId}") | ||
public JsonResult<?> groupMemberList(@RequestHeader(name = "Authorization") String authorization, | ||
@PathVariable(name = "groupId") Long groupId) { | ||
// 유저 인증 & 해당 그룹원인지 확인 | ||
authExternalService.userAuthenticateAndGroupMatch(authorization, groupId); | ||
|
||
List<GroupMemberResponse> groupMemberList = groupMemberService.selectGroupMember(groupId); | ||
|
||
return JsonResult.successOf(groupMemberList); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...n/java/com/heachi/housework/api/controller/group/member/response/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,16 @@ | ||
package com.heachi.housework.api.controller.group.member.response; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class GroupMemberResponse { | ||
private Long groupMemberId; | ||
private String username; | ||
|
||
@Builder | ||
private GroupMemberResponse(Long groupMemberId, String username) { | ||
this.groupMemberId = groupMemberId; | ||
this.username = username; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...k-api/src/main/java/com/heachi/housework/api/service/group/member/GroupMemberService.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,31 @@ | ||
package com.heachi.housework.api.service.group.member; | ||
|
||
import com.heachi.housework.api.controller.group.member.response.GroupMemberResponse; | ||
import com.heachi.mysql.define.group.member.repository.GroupMemberRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Slf4j | ||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class GroupMemberService { | ||
|
||
private final GroupMemberRepository groupMemberRepository; | ||
|
||
public List<GroupMemberResponse> selectGroupMember(Long groupId) { | ||
|
||
// groupId로 상태가 ACCEPT인 모든 그룹 멤버 조회 후 GroupMemberListResponse 리스트로 변환해서 반환 | ||
return groupMemberRepository.findGroupMemberByGroupId(groupId) | ||
.stream() | ||
.map(gm -> GroupMemberResponse.builder() | ||
.groupMemberId(gm.getId()) | ||
.username(gm.getUser().getName()) | ||
.build()) | ||
.toList(); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
...i/src/test/java/com/heachi/housework/api/service/group/member/GroupMemberServiceTest.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,79 @@ | ||
package com.heachi.housework.api.service.group.member; | ||
|
||
import com.heachi.admin.common.exception.ExceptionMessage; | ||
import com.heachi.admin.common.exception.group.member.GroupMemberException; | ||
import com.heachi.housework.TestConfig; | ||
import com.heachi.housework.api.controller.group.member.response.GroupMemberResponse; | ||
import com.heachi.mysql.define.group.info.GroupInfo; | ||
import com.heachi.mysql.define.group.info.repository.GroupInfoRepository; | ||
import com.heachi.mysql.define.group.member.GroupMember; | ||
import com.heachi.mysql.define.group.member.repository.GroupMemberRepository; | ||
import com.heachi.mysql.define.housework.category.repository.HouseworkCategoryRepository; | ||
import com.heachi.mysql.define.housework.info.repository.HouseworkInfoRepository; | ||
import com.heachi.mysql.define.housework.member.repository.HouseworkMemberRepository; | ||
import com.heachi.mysql.define.housework.todo.repository.HouseworkTodoRepository; | ||
import com.heachi.mysql.define.user.User; | ||
import com.heachi.mysql.define.user.repository.UserRepository; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
|
||
@SpringBootTest | ||
class GroupMemberServiceTest extends TestConfig { | ||
@Autowired | ||
private GroupMemberRepository groupMemberRepository; | ||
@Autowired | ||
private UserRepository userRepository; | ||
@Autowired | ||
private GroupInfoRepository groupInfoRepository; | ||
@Autowired | ||
private HouseworkCategoryRepository houseworkCategoryRepository; | ||
@Autowired | ||
private HouseworkInfoRepository houseworkInfoRepository; | ||
@Autowired | ||
private HouseworkTodoRepository houseworkTodoRepository; | ||
@Autowired | ||
private HouseworkMemberRepository houseworkMemberRepository; | ||
|
||
@Autowired | ||
private GroupMemberService groupMemberService; | ||
|
||
@AfterEach | ||
void tearDown() { | ||
houseworkTodoRepository.deleteAllInBatch(); | ||
houseworkMemberRepository.deleteAllInBatch(); | ||
houseworkInfoRepository.deleteAllInBatch(); | ||
houseworkCategoryRepository.deleteAllInBatch(); | ||
groupMemberRepository.deleteAllInBatch(); | ||
groupInfoRepository.deleteAllInBatch(); | ||
userRepository.deleteAllInBatch(); | ||
} | ||
|
||
@Test | ||
@DisplayName(" groupMemberList API 호출시 GroupMemberListResponse 리스트가 잘 반환된다.\n") | ||
void selectGroupMemberListSuccessTest() { | ||
// given | ||
User user = userRepository.save(generateUser()); // 그룹장 | ||
User user2 = userRepository.save(generateCustomUser("[email protected]", "010-1111-1111")); | ||
GroupInfo groupInfo = groupInfoRepository.save(generateGroupInfo(user)); | ||
GroupMember groupMember = groupMemberRepository.save(generateGroupMember(user, groupInfo)); | ||
GroupMember groupMember2 = groupMemberRepository.save(generateGroupMember(user2, groupInfo)); | ||
|
||
// when | ||
List<GroupMemberResponse> groupMemberRespons = groupMemberService.selectGroupMember(groupInfo.getId()); | ||
|
||
// then | ||
assertThat(groupMemberRespons.size()).isEqualTo(2); | ||
assertThat(groupMemberRespons.get(0).getGroupMemberId()).isEqualTo(groupMember.getId()); | ||
assertThat(groupMemberRespons.get(1).getGroupMemberId()).isEqualTo(groupMember2.getId()); | ||
|
||
} | ||
} |