Skip to content

Commit

Permalink
Merge pull request #108 from ghdcksgml1/dev
Browse files Browse the repository at this point in the history
Merge dev branch
  • Loading branch information
ghdcksgml1 authored Nov 7, 2023
2 parents 426f87d + d1d4ca9 commit ca673a5
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 0 deletions.
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);
}
}
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;
}
}
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();
}
}
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());

}
}

0 comments on commit ca673a5

Please sign in to comment.