Skip to content

Commit

Permalink
feat: 그룹 삭제 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
SangWoon123 committed May 8, 2024
1 parent 2c1b013 commit fd290d2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import com.tukorea.planding.common.CommonResponse;
import com.tukorea.planding.common.CommonUtils;
import com.tukorea.planding.domain.group.dto.GroupCreateRequest;
import com.tukorea.planding.domain.group.dto.GroupUpdateRequest;
import com.tukorea.planding.domain.group.dto.GroupResponse;
import com.tukorea.planding.domain.group.dto.request.GroupCreateRequest;
import com.tukorea.planding.domain.group.dto.request.GroupUpdateRequest;
import com.tukorea.planding.domain.group.dto.response.GroupResponse;
import com.tukorea.planding.domain.group.dto.response.GroupUserResponse;
import com.tukorea.planding.domain.group.service.GroupRoomService;
import com.tukorea.planding.domain.user.dto.UserInfo;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -20,23 +21,38 @@
@RequiredArgsConstructor
@RequestMapping("/api/v1/group")
public class GroupRoomController {

private final GroupRoomService groupRoomService;

@Operation(summary = "스케줄 그룹 생성")
@Operation(summary = "그룹에 속한 유저 조회")
@GetMapping("/{groupId}")
public CommonResponse<?> getUserByGroup(@PathVariable Long groupId) {
List<GroupUserResponse> responses = groupRoomService.getGroupUsers(groupId);
return CommonUtils.success(responses);
}

@Operation(summary = "그룹 생성")
@PostMapping()
public CommonResponse<GroupResponse> createGroupRoom(@AuthenticationPrincipal UserInfo userInfo, @RequestBody GroupCreateRequest createGroupRoom) {
GroupResponse groupResponse = groupRoomService.createGroupRoom(userInfo, createGroupRoom);
return CommonUtils.success(groupResponse);
}

@Operation(summary = "그룹 이름,설명 변경")
@Operation(summary = "그룹 정보 수정")
@PatchMapping()
public CommonResponse<GroupResponse> updateGroupNameOrDescription(@AuthenticationPrincipal UserInfo userInfo, @RequestBody GroupUpdateRequest groupUpdateRequest) {
GroupResponse groupResponses = groupRoomService.updateGroupNameOrDescription(userInfo, groupUpdateRequest);
return CommonUtils.success(groupResponses);
}

@Operation(summary = "유저가 속한 그룹 가져오기")
@Operation(summary = "그룹 삭제")
@DeleteMapping("/{groupId}")
public CommonResponse<?> deleteGroup(@AuthenticationPrincipal UserInfo userInfo, @PathVariable Long groupId) {
groupRoomService.deleteGroup(userInfo, groupId);
return CommonUtils.success("그룹삭제 완료.");
}

@Operation(summary = "내 그룹 가져오기")
@GetMapping("/myGroup")
public CommonResponse<List<GroupResponse>> getAllGroupRoomByUser(@AuthenticationPrincipal UserInfo userInfo) {
List<GroupResponse> groupResponses = groupRoomService.getAllGroupRoomByUser(userInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import com.tukorea.planding.domain.group.entity.GroupRoom;
import com.tukorea.planding.domain.user.entity.User;

import java.util.List;

public interface GroupFavoriteRepositoryCustom {
Long countMyFavoriteGroup(String userCode);

Boolean existsByUserAndGroupRoom(String userCode);
GroupFavorite findByUserAndGroupRoom(User user, GroupRoom groupRoom);
List<GroupFavorite> findByUserFavorite(Long userId);
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
package com.tukorea.planding.domain.group.service;

import com.tukorea.planding.domain.group.dto.request.GroupCreateRequest;
import com.tukorea.planding.domain.group.dto.response.GroupResponse;
import com.tukorea.planding.domain.group.dto.request.GroupUpdateRequest;
import com.tukorea.planding.domain.group.dto.response.GroupResponse;
import com.tukorea.planding.domain.group.dto.response.GroupUserResponse;
import com.tukorea.planding.domain.group.entity.GroupRoom;
import com.tukorea.planding.domain.group.entity.UserGroup;
import com.tukorea.planding.domain.group.repository.GroupRoomRepository;
import com.tukorea.planding.domain.group.service.query.GroupQueryService;
import com.tukorea.planding.domain.user.dto.UserInfo;
import com.tukorea.planding.domain.user.entity.User;
import com.tukorea.planding.domain.user.service.UserQueryService;
import com.tukorea.planding.global.error.BusinessException;
import com.tukorea.planding.global.error.ErrorCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

@Service
@Slf4j
@RequiredArgsConstructor
public class GroupRoomService {

Expand Down Expand Up @@ -59,6 +62,17 @@ public GroupResponse updateGroupNameOrDescription(UserInfo userInfo, GroupUpdate
return toGroupResponse(groupRoom);
}

public void deleteGroup(UserInfo userInfo, Long groupId) {
User user = userQueryService.getByUserInfo(userInfo.getUserCode());
GroupRoom groupRoom = groupQueryService.getGroupById(groupId);

if (!groupRoom.getOwner().equals(user.getUserCode())) {
throw new BusinessException(ErrorCode.ACCESS_DENIED);
}

groupQueryService.delete(groupRoom);
}

// 유저가 속한 그룹룸 가져오기
public List<GroupResponse> getAllGroupRoomByUser(UserInfo userInfo) {
User user = userQueryService.getUserByUserCode(userInfo);
Expand All @@ -81,5 +95,4 @@ public List<GroupUserResponse> getGroupUsers(Long groupId) {
private GroupResponse toGroupResponse(GroupRoom groupRoom) {
return GroupResponse.from(groupRoom);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public GroupRoom getGroupById(Long groupId) {
.orElseThrow(() -> new BusinessException(ErrorCode.GROUP_ROOM_NOT_FOUND));
}

public void delete(GroupRoom groupRoom) {
groupRoomRepository.delete(groupRoom);
}

public List<User> getGroupUsers(Long groupId) {
return groupRoomRepositoryCustom.getGroupUsers(groupId);
}
Expand Down

0 comments on commit fd290d2

Please sign in to comment.