Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] 그룹 이름 조회 API 추가 #68

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum SuccessStatus implements BaseStatus {
GET_IMAGE_SUCCESS(HttpStatus.OK, "IMAGE_200", "이미지가 성공적으로 조회되었습니다"),

GROUP_CREATED(HttpStatus.CREATED, "GROUP_201", "그룹이 성공적으로 생성되었습니다"),
GROUPS_FOUND(HttpStatus.OK, "GROUP_200", "그룹이 성공적으로 조회되었습니다."),
GROUP_DELETED(HttpStatus.NO_CONTENT, "GROUP_204", "그룹이 성공적으로 삭제되었습니다"),
GROUP_UPDATED(HttpStatus.OK, "GROUP_200", "그룹 이름 변경이 성공적으로 처리되었습니다."),
GROUP_RECEIVER_ADDED(HttpStatus.CREATED, "GR_RC_201", "그룹 멤버 추가가 성공적으로 처리되었습니다."),
Expand Down
28 changes: 21 additions & 7 deletions src/main/java/com/pictalk/group/controller/GroupController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@
import com.pictalk.group.domain.Group;
import com.pictalk.group.dto.GroupRequestDto.CreateGroupRequest;
import com.pictalk.group.dto.GroupRequestDto.UpdateGroupRequest;
import com.pictalk.group.dto.GroupResponseDto;
import com.pictalk.group.dto.GroupResponseDto.CreateGroupResponse;
import com.pictalk.group.service.GroupService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequiredArgsConstructor
Expand Down Expand Up @@ -51,4 +49,20 @@ public CommonResponse<Object> updateGroup(@PathVariable("group_id") Long groupId
groupService.updateGroup(groupId, updateGroupRequest);
return CommonResponse.of(SuccessStatus.GROUP_UPDATED, null);
}

@Operation(summary = "그룹 조회")
@GetMapping
public CommonResponse<List<GroupResponseDto.SearchGroupResponse>> getGroups(@AuthenticationPrincipal UserDetails authenticatedPrincipal) {
String userEmail = authenticatedPrincipal.getUsername();
List<Group> groups = groupService.getAllGroupsByUser(userEmail);

List<GroupResponseDto.SearchGroupResponse> response = groups.stream()
.map(group -> GroupResponseDto.SearchGroupResponse.builder()
.groupId(group.getId())
.groupName(group.getName())
.build())
.collect(Collectors.toList());

return CommonResponse.of(SuccessStatus.GROUPS_FOUND, response);
}
}
3 changes: 1 addition & 2 deletions src/main/java/com/pictalk/group/service/GroupService.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public void deleteGroup(Long groupId) {
group.softDelete();
}


public List<Group> getAllGroupByUser(String userEmail) {
public List<Group> getAllGroupsByUser(String userEmail) {
User user = userRepository.findByEmail(userEmail)
.orElseThrow(() -> new GeneralException(ErrorStatus.USER_NOT_FOUND));
return groupRepository.findAllByUser(user);
Expand Down