-
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
16 changed files
with
197 additions
and
5 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/main/kotlin/com/open3r/openmusic/domain/admin/banner/controller/AdminBannerController.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,28 @@ | ||
package com.open3r.openmusic.domain.admin.banner.controller | ||
|
||
import com.open3r.openmusic.domain.admin.banner.dto.request.BannerCreateRequest | ||
import com.open3r.openmusic.domain.admin.banner.service.AdminBannerService | ||
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.security.access.prepost.PreAuthorize | ||
import org.springframework.web.bind.annotation.* | ||
|
||
@Tag(name = "관리자: 배너", description = "Admin: Banner") | ||
@RestController | ||
@RequestMapping("/admin/banners") | ||
class AdminBannerController( | ||
private val adminBannerService: AdminBannerService | ||
) { | ||
@Operation(summary = "배너 생성") | ||
@PostMapping | ||
@PreAuthorize("hasRole('ADMIN')") | ||
fun createBanner(@RequestBody request: BannerCreateRequest) = | ||
BaseResponse(adminBannerService.createBanner(request), 201).toEntity() | ||
|
||
@Operation(summary = "배너 삭제") | ||
@DeleteMapping("/{bannerId}") | ||
@PreAuthorize("hasRole('ADMIN')") | ||
fun deleteBanner(@PathVariable bannerId: Long) = | ||
BaseResponse(adminBannerService.deleteBanner(bannerId), 204).toEntity() | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/kotlin/com/open3r/openmusic/domain/admin/banner/dto/request/BannerCreateRequest.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,13 @@ | ||
package com.open3r.openmusic.domain.admin.banner.dto.request | ||
|
||
import jakarta.validation.constraints.NotBlank | ||
import org.hibernate.validator.constraints.URL | ||
|
||
data class BannerCreateRequest( | ||
@field:NotBlank | ||
@field:URL | ||
val url: String, | ||
@field:NotBlank | ||
@field:URL | ||
val imageUrl: String, | ||
) |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/com/open3r/openmusic/domain/admin/banner/service/AdminBannerService.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,9 @@ | ||
package com.open3r.openmusic.domain.admin.banner.service | ||
|
||
import com.open3r.openmusic.domain.admin.banner.dto.request.BannerCreateRequest | ||
import com.open3r.openmusic.domain.banner.dto.response.BannerResponse | ||
|
||
interface AdminBannerService { | ||
fun createBanner(request: BannerCreateRequest): BannerResponse | ||
fun deleteBanner(bannerId: Long) | ||
} |
24 changes: 24 additions & 0 deletions
24
...in/kotlin/com/open3r/openmusic/domain/admin/banner/service/impl/AdminBannerServiceImpl.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,24 @@ | ||
package com.open3r.openmusic.domain.admin.banner.service.impl | ||
|
||
import com.open3r.openmusic.domain.admin.banner.dto.request.BannerCreateRequest | ||
import com.open3r.openmusic.domain.admin.banner.service.AdminBannerService | ||
import com.open3r.openmusic.domain.banner.domain.entity.BannerEntity | ||
import com.open3r.openmusic.domain.banner.dto.response.BannerResponse | ||
import com.open3r.openmusic.domain.banner.repository.BannerRepository | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Service | ||
class AdminBannerServiceImpl( | ||
private val bannerRepository: BannerRepository | ||
) : AdminBannerService { | ||
@Transactional | ||
override fun createBanner(request: BannerCreateRequest): BannerResponse { | ||
return BannerResponse.of(bannerRepository.save(BannerEntity(url = request.url, imageUrl = request.imageUrl))) | ||
} | ||
|
||
@Transactional | ||
override fun deleteBanner(bannerId: Long) { | ||
bannerRepository.deleteById(bannerId) | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/com/open3r/openmusic/domain/banner/controller/BannerController.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,25 @@ | ||
package com.open3r.openmusic.domain.banner.controller | ||
|
||
import com.open3r.openmusic.domain.banner.service.BannerService | ||
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.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@Tag(name = "배너", description = "Banner") | ||
@RestController | ||
@RequestMapping("/banners") | ||
class BannerController( | ||
private val bannerService: BannerService | ||
) { | ||
@Operation(summary = "배너 목록 조회") | ||
@GetMapping | ||
fun getBanners() = BaseResponse(bannerService.getBanners(), 200).toEntity() | ||
|
||
@Operation(summary = "배너 조회") | ||
@GetMapping("/{bannerId}") | ||
fun getBanner(@PathVariable bannerId: Long) = BaseResponse(bannerService.getBanner(bannerId), 200).toEntity() | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/kotlin/com/open3r/openmusic/domain/banner/domain/entity/BannerEntity.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,18 @@ | ||
package com.open3r.openmusic.domain.banner.domain.entity | ||
|
||
import com.open3r.openmusic.global.common.domain.entity.BaseEntity | ||
import jakarta.persistence.* | ||
|
||
@Entity | ||
@Table(name = "banners") | ||
class BannerEntity( | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Long? = null, | ||
|
||
@Column(name = "url", nullable = false, updatable = false) | ||
val url: String, | ||
|
||
@Column(name = "image_url", nullable = false, updatable = false) | ||
val imageUrl: String, | ||
) : BaseEntity() |
22 changes: 22 additions & 0 deletions
22
src/main/kotlin/com/open3r/openmusic/domain/banner/dto/response/BannerResponse.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,22 @@ | ||
package com.open3r.openmusic.domain.banner.dto.response | ||
|
||
import com.open3r.openmusic.domain.banner.domain.entity.BannerEntity | ||
import java.time.LocalDateTime | ||
|
||
data class BannerResponse( | ||
val id: Long, | ||
val url: String, | ||
val imageUrl: String, | ||
val createdAt: LocalDateTime, | ||
val updatedAt: LocalDateTime, | ||
) { | ||
companion object { | ||
fun of(banner: BannerEntity) = BannerResponse( | ||
id = banner.id!!, | ||
url = banner.url, | ||
imageUrl = banner.imageUrl, | ||
createdAt = banner.createdAt!!, | ||
updatedAt = banner.updatedAt!!, | ||
) | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/com/open3r/openmusic/domain/banner/repository/BannerRepository.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,6 @@ | ||
package com.open3r.openmusic.domain.banner.repository | ||
|
||
import com.open3r.openmusic.domain.banner.domain.entity.BannerEntity | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface BannerRepository : JpaRepository<BannerEntity, Long> |
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/open3r/openmusic/domain/banner/service/BannerService.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,8 @@ | ||
package com.open3r.openmusic.domain.banner.service | ||
|
||
import com.open3r.openmusic.domain.banner.dto.response.BannerResponse | ||
|
||
interface BannerService { | ||
fun getBanners(): List<BannerResponse> | ||
fun getBanner(bannerId: Long): BannerResponse | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/kotlin/com/open3r/openmusic/domain/banner/service/impl/BannerServiceImpl.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,27 @@ | ||
package com.open3r.openmusic.domain.banner.service.impl | ||
|
||
import com.open3r.openmusic.domain.banner.dto.response.BannerResponse | ||
import com.open3r.openmusic.domain.banner.repository.BannerRepository | ||
import com.open3r.openmusic.domain.banner.service.BannerService | ||
import com.open3r.openmusic.global.error.CustomException | ||
import com.open3r.openmusic.global.error.ErrorCode | ||
import org.springframework.data.repository.findByIdOrNull | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Service | ||
class BannerServiceImpl( | ||
private val bannerRepository: BannerRepository | ||
) : BannerService { | ||
@Transactional(readOnly = true) | ||
override fun getBanners(): List<BannerResponse> { | ||
return bannerRepository.findAll().map { BannerResponse.of(it) } | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
override fun getBanner(bannerId: Long): BannerResponse { | ||
return BannerResponse.of( | ||
bannerRepository.findByIdOrNull(bannerId) ?: throw CustomException(ErrorCode.BANNER_NOT_FOUND) | ||
) | ||
} | ||
} |
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
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
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
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
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
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