|
5 | 5 | import com.pictalk.group.domain.Group;
|
6 | 6 | import com.pictalk.group.dto.GroupRequestDto.CreateGroupRequest;
|
7 | 7 | import com.pictalk.group.dto.GroupRequestDto.UpdateGroupRequest;
|
| 8 | +import com.pictalk.group.dto.GroupResponseDto; |
8 | 9 | import com.pictalk.group.dto.GroupResponseDto.CreateGroupResponse;
|
9 | 10 | import com.pictalk.group.service.GroupService;
|
10 | 11 | import io.swagger.v3.oas.annotations.Operation;
|
11 | 12 | import lombok.RequiredArgsConstructor;
|
12 | 13 | import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
13 | 14 | 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; |
21 | 19 |
|
22 | 20 | @RestController
|
23 | 21 | @RequiredArgsConstructor
|
@@ -51,4 +49,20 @@ public CommonResponse<Object> updateGroup(@PathVariable("group_id") Long groupId
|
51 | 49 | groupService.updateGroup(groupId, updateGroupRequest);
|
52 | 50 | return CommonResponse.of(SuccessStatus.GROUP_UPDATED, null);
|
53 | 51 | }
|
| 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 | + } |
54 | 68 | }
|
0 commit comments