Skip to content

Commit

Permalink
채널 삭제 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
EOTAEGYU committed Nov 13, 2024
1 parent 26037fe commit 00c740d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ucd.keynote.domain.channel.controller;

import com.ucd.keynote.common.dto.NoDataApiResponseDTO;
import com.ucd.keynote.domain.channel.dto.ChannelUpdateRequestDTO;
import com.ucd.keynote.domain.channel.dto.ChannelRequestDTO;
import com.ucd.keynote.domain.channel.dto.ChannelResponseDTO;
Expand Down Expand Up @@ -73,4 +74,17 @@ public ResponseEntity<ApiResponseDTO<ChannelResponseDTO>> updateChannel (
return ResponseEntity.ok(response);
}

// 채널 삭제
@DeleteMapping("/organizationsg/{organizationId}/channels/{channelId}")
public ResponseEntity<NoDataApiResponseDTO> deleteChannel(@PathVariable Long organizationId, @PathVariable Long channelId) {
channelService.deleteChannel(organizationId, channelId);

NoDataApiResponseDTO response = NoDataApiResponseDTO.builder()
.code(200)
.message("Channel deleted successfully")
.build();

return ResponseEntity.ok(response);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.ucd.keynote.domain.organization.repository.OrganizationRepository;
import com.ucd.keynote.domain.organization.repository.UserOrganizationRepository;
import com.ucd.keynote.domain.user.entity.UserEntity;
import jakarta.transaction.Transactional;
import lombok.AllArgsConstructor;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -122,4 +123,26 @@ public ChannelResponseDTO updateChannelName(Long channelId, ChannelUpdateRequest
.build();
}

// 채널 삭제 메서드
@Transactional
public void deleteChannel(Long organizationId, Long channelId) {
// 현재 로그인한 사용자 정보 가져오기
UserEntity user = authService.getAuthenticatedUser();

// 조직 내 admin 권한 확인
UserOrganization userOrganization = userOrganizationRepository
.findByOrganization_OrganizationIdAndUser_UserId(organizationId, user.getUserId())
.orElseThrow(() -> new AccessDeniedException("이 조직에서 권한이 없습니다."));

if (!"admin".equals(userOrganization.getRole())) {
throw new AccessDeniedException("admin 권한이 있어야 채널을 삭제할 수 있습니다.");
}

// 채널 조회 및 삭제
Channel channel = channelRepository.findById(channelId)
.orElseThrow(() -> new IllegalArgumentException("채널을 찾을 수 없습니다."));

channelRepository.delete(channel);
}

}

0 comments on commit 00c740d

Please sign in to comment.