Skip to content

Commit 29b9a7a

Browse files
authored
feat: 그룹 이름 조회 API 추가 (#68)
1 parent 8b078c6 commit 29b9a7a

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

src/main/java/com/pictalk/global/payload/status/SuccessStatus.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public enum SuccessStatus implements BaseStatus {
1717
GET_IMAGE_SUCCESS(HttpStatus.OK, "IMAGE_200", "이미지가 성공적으로 조회되었습니다"),
1818

1919
GROUP_CREATED(HttpStatus.CREATED, "GROUP_201", "그룹이 성공적으로 생성되었습니다"),
20+
GROUPS_FOUND(HttpStatus.OK, "GROUP_200", "그룹이 성공적으로 조회되었습니다."),
2021
GROUP_DELETED(HttpStatus.NO_CONTENT, "GROUP_204", "그룹이 성공적으로 삭제되었습니다"),
2122
GROUP_UPDATED(HttpStatus.OK, "GROUP_200", "그룹 이름 변경이 성공적으로 처리되었습니다."),
2223
GROUP_RECEIVER_ADDED(HttpStatus.CREATED, "GR_RC_201", "그룹 멤버 추가가 성공적으로 처리되었습니다."),

src/main/java/com/pictalk/group/controller/GroupController.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@
55
import com.pictalk.group.domain.Group;
66
import com.pictalk.group.dto.GroupRequestDto.CreateGroupRequest;
77
import com.pictalk.group.dto.GroupRequestDto.UpdateGroupRequest;
8+
import com.pictalk.group.dto.GroupResponseDto;
89
import com.pictalk.group.dto.GroupResponseDto.CreateGroupResponse;
910
import com.pictalk.group.service.GroupService;
1011
import io.swagger.v3.oas.annotations.Operation;
1112
import lombok.RequiredArgsConstructor;
1213
import org.springframework.security.core.annotation.AuthenticationPrincipal;
1314
import org.springframework.security.core.userdetails.UserDetails;
14-
import org.springframework.web.bind.annotation.DeleteMapping;
15-
import org.springframework.web.bind.annotation.PatchMapping;
16-
import org.springframework.web.bind.annotation.PathVariable;
17-
import org.springframework.web.bind.annotation.PostMapping;
18-
import org.springframework.web.bind.annotation.RequestBody;
19-
import org.springframework.web.bind.annotation.RequestMapping;
20-
import org.springframework.web.bind.annotation.RestController;
15+
import org.springframework.web.bind.annotation.*;
16+
17+
import java.util.List;
18+
import java.util.stream.Collectors;
2119

2220
@RestController
2321
@RequiredArgsConstructor
@@ -51,4 +49,20 @@ public CommonResponse<Object> updateGroup(@PathVariable("group_id") Long groupId
5149
groupService.updateGroup(groupId, updateGroupRequest);
5250
return CommonResponse.of(SuccessStatus.GROUP_UPDATED, null);
5351
}
52+
53+
@Operation(summary = "그룹 조회")
54+
@GetMapping
55+
public CommonResponse<List<GroupResponseDto.SearchGroupResponse>> getGroups(@AuthenticationPrincipal UserDetails authenticatedPrincipal) {
56+
String userEmail = authenticatedPrincipal.getUsername();
57+
List<Group> groups = groupService.getAllGroupsByUser(userEmail);
58+
59+
List<GroupResponseDto.SearchGroupResponse> response = groups.stream()
60+
.map(group -> GroupResponseDto.SearchGroupResponse.builder()
61+
.groupId(group.getId())
62+
.groupName(group.getName())
63+
.build())
64+
.collect(Collectors.toList());
65+
66+
return CommonResponse.of(SuccessStatus.GROUPS_FOUND, response);
67+
}
5468
}

src/main/java/com/pictalk/group/service/GroupService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ public void deleteGroup(Long groupId) {
4040
group.softDelete();
4141
}
4242

43-
44-
public List<Group> getAllGroupByUser(String userEmail) {
43+
public List<Group> getAllGroupsByUser(String userEmail) {
4544
User user = userRepository.findByEmail(userEmail)
4645
.orElseThrow(() -> new GeneralException(ErrorStatus.USER_NOT_FOUND));
4746
return groupRepository.findAllByUser(user);

0 commit comments

Comments
 (0)