Skip to content

Commit

Permalink
feat: admin
Browse files Browse the repository at this point in the history
  • Loading branch information
jbj338033 committed Aug 5, 2024
1 parent fedcb49 commit 2651c3e
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 207 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,20 @@ import com.open3r.openmusic.domain.admin.album.service.AdminAlbumService
import com.open3r.openmusic.global.common.dto.response.BaseResponse
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.data.domain.Pageable
import org.springframework.data.web.PageableDefault
import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.web.bind.annotation.*
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@Tag(name = "어드민: 앨범", description = "Admin: Album")
@RestController
@RequestMapping("/admin/albums")
class AdminAlbumController(
private val adminAlbumService: AdminAlbumService
) {
@Operation(summary = "대기 중인 앨범 목록 조회", description = "대기 중인 앨범 목록을 조회합니다.")
@GetMapping("/pending")
@Operation(summary = "앨범 삭제", description = "앨범을 삭제합니다.")
@PreAuthorize("hasRole('ADMIN')")
fun getPendingAlbums(@PageableDefault pageable: Pageable) =
BaseResponse(adminAlbumService.getPendingAlbums(pageable), 200).toEntity()

@Operation(summary = "승인된 앨범 목록 조회", description = "승인된 앨범 목록을 조회합니다.")
@GetMapping("/approved")
@PreAuthorize("hasRole('ADMIN')")
fun getApprovedAlbums(@PageableDefault pageable: Pageable) =
BaseResponse(adminAlbumService.getApprovedAlbums(pageable), 200).toEntity()

@Operation(summary = "거부된 앨범 목록 조회", description = "거부된 앨범 목록을 조회합니다.")
@GetMapping("/rejected")
@PreAuthorize("hasRole('ADMIN')")
fun getRejectedAlbums(@PageableDefault pageable: Pageable) =
BaseResponse(adminAlbumService.getRejectedAlbums(pageable), 200).toEntity()

@Operation(summary = "삭제된 앨범 목록 조회", description = "삭제된 앨범 목록을 조회합니다.")
@GetMapping("/deleted")
@PreAuthorize("hasRole('ADMIN')")
fun getDeletedAlbums(@PageableDefault pageable: Pageable) =
BaseResponse(adminAlbumService.getDeletedAlbums(pageable), 200).toEntity()

@Operation(summary = "앨범 승인", description = "앨범을 승인합니다.")
@PostMapping("/approve")
@PreAuthorize("hasRole('ADMIN')")
fun approveAlbum(@RequestParam albumId: Long) =
BaseResponse(adminAlbumService.approveAlbum(albumId), 200).toEntity()

@Operation(summary = "앨범 거부", description = "앨범을 거부합니다.")
@PostMapping("/reject")
@PreAuthorize("hasRole('ADMIN')")
fun rejectAlbum(@RequestParam albumId: Long) = BaseResponse(adminAlbumService.rejectAlbum(albumId), 200).toEntity()
@DeleteMapping("/{albumId}")
fun deleteAlbum(@PathVariable albumId: Long) = BaseResponse(adminAlbumService.deleteAlbum(albumId), 204).toEntity()
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
package com.open3r.openmusic.domain.admin.album.service

import com.open3r.openmusic.domain.album.dto.response.AlbumResponse
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable

interface AdminAlbumService {
fun getPendingAlbums(pageable: Pageable): Page<AlbumResponse>
fun getApprovedAlbums(pageable: Pageable): Page<AlbumResponse>
fun getRejectedAlbums(pageable: Pageable): Page<AlbumResponse>
fun getDeletedAlbums(pageable: Pageable): Page<AlbumResponse>

fun approveAlbum(albumId: Long)
fun rejectAlbum(albumId: Long)

fun deleteAlbum(albumId: Long)
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package com.open3r.openmusic.domain.admin.album.service.impl

import com.open3r.openmusic.domain.admin.album.repository.AdminAlbumQueryRepository
import com.open3r.openmusic.domain.admin.album.service.AdminAlbumService
import com.open3r.openmusic.domain.album.domain.enums.AlbumStatus
import com.open3r.openmusic.domain.album.dto.response.AlbumResponse
import com.open3r.openmusic.domain.album.repository.AlbumRepository
import com.open3r.openmusic.global.error.CustomException
import com.open3r.openmusic.global.error.ErrorCode
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
Expand All @@ -17,52 +13,7 @@ import org.springframework.transaction.annotation.Transactional
@Transactional
class AdminAlbumServiceImpl(
private val albumRepository: AlbumRepository,
private val adminAlbumQueryRepository: AdminAlbumQueryRepository
) : AdminAlbumService {
override fun getPendingAlbums(pageable: Pageable): Page<AlbumResponse> {
return adminAlbumQueryRepository.getPendingAlbums(pageable).map { AlbumResponse.of(it) }
}

override fun getApprovedAlbums(pageable: Pageable): Page<AlbumResponse> {
return adminAlbumQueryRepository.getApprovedAlbums(pageable).map { AlbumResponse.of(it) }
}

override fun getRejectedAlbums(pageable: Pageable): Page<AlbumResponse> {
return adminAlbumQueryRepository.getRejectedAlbums(pageable).map { AlbumResponse.of(it) }
}

override fun getDeletedAlbums(pageable: Pageable): Page<AlbumResponse> {
return adminAlbumQueryRepository.getDeletedAlbums(pageable).map { AlbumResponse.of(it) }
}

override fun approveAlbum(albumId: Long) {
val album = albumRepository.findByIdOrNull(albumId) ?: throw CustomException(ErrorCode.ALBUM_NOT_FOUND)

if (album.status != AlbumStatus.PENDING) {
throw CustomException(ErrorCode.ALBUM_STATUS_INVALID)
}

album.status = AlbumStatus.APPROVED

album.songs.forEach { it.song.status = AlbumStatus.APPROVED }

albumRepository.save(album)
}

override fun rejectAlbum(albumId: Long) {
val album = albumRepository.findByIdOrNull(albumId) ?: throw CustomException(ErrorCode.ALBUM_NOT_FOUND)

if (album.status != AlbumStatus.PENDING) {
throw CustomException(ErrorCode.ALBUM_STATUS_INVALID)
}

album.status = AlbumStatus.REJECTED

album.songs.forEach { it.song.status = AlbumStatus.REJECTED }

albumRepository.save(album)
}

override fun deleteAlbum(albumId: Long) {
val album = albumRepository.findByIdOrNull(albumId) ?: throw CustomException(ErrorCode.ALBUM_NOT_FOUND)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.open3r.openmusic.domain.song.repository.SongRepository
import com.open3r.openmusic.global.error.CustomException
import com.open3r.openmusic.global.error.ErrorCode
import com.open3r.openmusic.global.security.UserSecurity
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

Expand All @@ -19,7 +20,7 @@ class AdminSongServiceImpl(

@Transactional
override fun deleteSong(songId: Long) {
val song = songRepository.findById(songId).orElseThrow { throw CustomException(ErrorCode.SONG_NOT_FOUND) }
val song = songRepository.findByIdOrNull(songId) ?: throw CustomException(ErrorCode.SONG_NOT_FOUND)

songRepository.delete(song)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AlbumEntity(
var coverUrl: String,

@Column(name = "status", nullable = true)
var status: AlbumStatus,
var status: AlbumStatus = AlbumStatus.ACTIVE,

@Enumerated(EnumType.STRING)
@Column(name = "scope", nullable = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.open3r.openmusic.domain.album.domain.enums

enum class AlbumStatus {
PENDING,
APPROVED,
REJECTED,
ACTIVE,
DELETED
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.open3r.openmusic.domain.album.service.impl
import com.open3r.openmusic.domain.album.domain.entity.AlbumEntity
import com.open3r.openmusic.domain.album.domain.entity.AlbumLikeEntity
import com.open3r.openmusic.domain.album.domain.entity.AlbumSongEntity
import com.open3r.openmusic.domain.album.domain.enums.AlbumStatus
import com.open3r.openmusic.domain.album.dto.request.AlbumCreateRequest
import com.open3r.openmusic.domain.album.dto.request.AlbumUpdateRequest
import com.open3r.openmusic.domain.album.dto.response.AlbumResponse
Expand Down Expand Up @@ -57,7 +56,6 @@ class AlbumServiceImpl(
artist = user,
genre = request.genre,
scope = request.scope,
status = AlbumStatus.PENDING
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import com.open3r.openmusic.domain.album.domain.enums.AlbumStatus
import com.open3r.openmusic.domain.song.domain.enums.SongGenre
import com.open3r.openmusic.domain.user.domain.entity.UserEntity
import com.open3r.openmusic.global.common.domain.entity.BaseEntity
import com.open3r.openmusic.global.error.CustomException
import com.open3r.openmusic.global.error.ErrorCode
import jakarta.persistence.*

@Entity
Expand Down
Loading

0 comments on commit 2651c3e

Please sign in to comment.