-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
294 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/kotlin/com/open3r/openmusic/domain/admin/album/controller/AdminAlbumController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.open3r.openmusic.domain.admin.album.controller | ||
|
||
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.* | ||
|
||
@Tag(name = "어드민: 앨범", description = "Admin: Album") | ||
@RestController | ||
@RequestMapping("/admin/albums") | ||
class AdminAlbumController( | ||
private val adminAlbumService: AdminAlbumService | ||
) { | ||
@Operation(summary = "대기 중인 앨범 목록 조회", description = "대기 중인 앨범 목록을 조회합니다.") | ||
@GetMapping("/pending") | ||
@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() | ||
} |
12 changes: 12 additions & 0 deletions
12
...in/kotlin/com/open3r/openmusic/domain/admin/album/repository/AdminAlbumQueryRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.open3r.openmusic.domain.admin.album.repository | ||
|
||
import com.open3r.openmusic.domain.album.domain.entity.AlbumEntity | ||
import org.springframework.data.domain.Page | ||
import org.springframework.data.domain.Pageable | ||
|
||
interface AdminAlbumQueryRepository { | ||
fun getPendingAlbums(pageable: Pageable): Page<AlbumEntity> | ||
fun getApprovedAlbums(pageable: Pageable): Page<AlbumEntity> | ||
fun getRejectedAlbums(pageable: Pageable): Page<AlbumEntity> | ||
fun getDeletedAlbums(pageable: Pageable): Page<AlbumEntity> | ||
} |
77 changes: 77 additions & 0 deletions
77
.../com/open3r/openmusic/domain/admin/album/repository/impl/AdminAlbumQueryRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.open3r.openmusic.domain.admin.album.repository.impl | ||
|
||
import com.open3r.openmusic.domain.admin.album.repository.AdminAlbumQueryRepository | ||
import com.open3r.openmusic.domain.album.domain.entity.AlbumEntity | ||
import com.open3r.openmusic.domain.album.domain.entity.QAlbumEntity.albumEntity | ||
import com.open3r.openmusic.domain.album.domain.enums.AlbumStatus | ||
import com.open3r.openmusic.global.util.paginate | ||
import com.querydsl.jpa.impl.JPAQueryFactory | ||
import org.springframework.data.domain.Page | ||
import org.springframework.data.domain.PageImpl | ||
import org.springframework.data.domain.Pageable | ||
import org.springframework.stereotype.Repository | ||
|
||
@Repository | ||
class AdminAlbumQueryRepositoryImpl( | ||
private val jpaQueryFactory: JPAQueryFactory | ||
) : AdminAlbumQueryRepository { | ||
override fun getPendingAlbums(pageable: Pageable): Page<AlbumEntity> { | ||
val count = jpaQueryFactory.select(albumEntity.count()) | ||
.from(albumEntity) | ||
.where(albumEntity.status.eq(AlbumStatus.PENDING)) | ||
.fetchOne() ?: 0 | ||
|
||
val albums = jpaQueryFactory.selectFrom(albumEntity) | ||
.where(albumEntity.status.eq(AlbumStatus.PENDING)) | ||
.paginate(pageable) | ||
.orderBy(albumEntity.createdAt.desc()) | ||
.fetch() | ||
|
||
return PageImpl(albums, pageable, count) | ||
} | ||
|
||
override fun getApprovedAlbums(pageable: Pageable): Page<AlbumEntity> { | ||
val count = jpaQueryFactory.select(albumEntity.count()) | ||
.from(albumEntity) | ||
.where(albumEntity.status.eq(AlbumStatus.APPROVED)) | ||
.fetchOne() ?: 0 | ||
|
||
val albums = jpaQueryFactory.selectFrom(albumEntity) | ||
.where(albumEntity.status.eq(AlbumStatus.APPROVED)) | ||
.paginate(pageable) | ||
.orderBy(albumEntity.createdAt.desc()) | ||
.fetch() | ||
|
||
return PageImpl(albums, pageable, count) | ||
} | ||
|
||
override fun getRejectedAlbums(pageable: Pageable): Page<AlbumEntity> { | ||
val count = jpaQueryFactory.select(albumEntity.count()) | ||
.from(albumEntity) | ||
.where(albumEntity.status.eq(AlbumStatus.REJECTED)) | ||
.fetchOne() ?: 0 | ||
|
||
val albums = jpaQueryFactory.selectFrom(albumEntity) | ||
.where(albumEntity.status.eq(AlbumStatus.REJECTED)) | ||
.paginate(pageable) | ||
.orderBy(albumEntity.createdAt.desc()) | ||
.fetch() | ||
|
||
return PageImpl(albums, pageable, count) | ||
} | ||
|
||
override fun getDeletedAlbums(pageable: Pageable): Page<AlbumEntity> { | ||
val count = jpaQueryFactory.select(albumEntity.count()) | ||
.from(albumEntity) | ||
.where(albumEntity.status.eq(AlbumStatus.DELETED)) | ||
.fetchOne() ?: 0 | ||
|
||
val albums = jpaQueryFactory.selectFrom(albumEntity) | ||
.where(albumEntity.status.eq(AlbumStatus.DELETED)) | ||
.paginate(pageable) | ||
.orderBy(albumEntity.createdAt.desc()) | ||
.fetch() | ||
|
||
return PageImpl(albums, pageable, count) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/kotlin/com/open3r/openmusic/domain/admin/album/service/AdminAlbumService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
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) | ||
} |
75 changes: 75 additions & 0 deletions
75
...main/kotlin/com/open3r/openmusic/domain/admin/album/service/impl/AdminAlbumServiceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
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 | ||
|
||
@Service | ||
@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) | ||
|
||
album.status = AlbumStatus.DELETED | ||
|
||
album.songs.forEach { it.song.status = AlbumStatus.DELETED } | ||
|
||
albumRepository.save(album) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
...main/kotlin/com/open3r/openmusic/domain/admin/song/repository/AdminSongQueryRepository.kt
This file was deleted.
Oops, something went wrong.
42 changes: 0 additions & 42 deletions
42
...in/com/open3r/openmusic/domain/admin/song/repository/impl/AdminSongQueryRepositoryImpl.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.