Skip to content

Commit

Permalink
feat(#53): converted banner service classes java to kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
KimDoubleB committed Jan 22, 2023
1 parent 3567db5 commit d15f258
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 39 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package site.archive.service.banner

import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import site.archive.domain.banner.Banner
import site.archive.domain.banner.BannerRepository
import site.archive.domain.banner.BannerType
import site.archive.dto.v2.BannerListResponseDto
import site.archive.dto.v2.BannerResponseDto

@Service
@Transactional(readOnly = true)
class BannerService(val bannerRepository: BannerRepository) {

fun getAllBanner(): BannerListResponseDto {
val bannerResponse = bannerRepository.findAllByOrderByCreatedAtDesc()
.map { BannerResponseDto(it.type.toString(), it.summaryImage, it.mainContent) }
.toList()
return BannerListResponseDto(bannerResponse)
}

@Transactional
fun createBanner(summaryImageUri: String, mainContent: String, type: BannerType): BannerResponseDto {
val banner = bannerRepository.save(Banner(summaryImageUri, mainContent, type))
return BannerResponseDto.from(banner)
}

@Transactional
fun deleteBanner(bannerId: Long) {
bannerRepository.deleteById(bannerId)
}

}

0 comments on commit d15f258

Please sign in to comment.