diff --git a/.github/workflows/dev-pr-test.yml b/.github/workflows/dev-pr-test.yml index ebc16054..3f555e84 100644 --- a/.github/workflows/dev-pr-test.yml +++ b/.github/workflows/dev-pr-test.yml @@ -17,11 +17,11 @@ jobs: - name: checkout uses: actions/checkout@v3 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v3 with: - java-version: '11' - distribution: 'adopt' + distribution: 'temurin' + java-version: '17' - name: Set application properties run: | diff --git a/src/main/kotlin/upbrella/be/config/DevCorsConfig.kt b/src/main/kotlin/upbrella/be/config/DevCorsConfig.kt index c62d2819..4ef35aab 100644 --- a/src/main/kotlin/upbrella/be/config/DevCorsConfig.kt +++ b/src/main/kotlin/upbrella/be/config/DevCorsConfig.kt @@ -2,11 +2,9 @@ package upbrella.be.config import org.springframework.context.annotation.Profile import org.springframework.stereotype.Component - import javax.servlet.* import javax.servlet.http.HttpServletRequest import javax.servlet.http.HttpServletResponse -import java.io.IOException @Profile("dev") @Component diff --git a/src/main/kotlin/upbrella/be/rent/controller/RentController.kt b/src/main/kotlin/upbrella/be/rent/controller/RentController.kt index f9cd1f6c..303fb393 100644 --- a/src/main/kotlin/upbrella/be/rent/controller/RentController.kt +++ b/src/main/kotlin/upbrella/be/rent/controller/RentController.kt @@ -12,7 +12,7 @@ import upbrella.be.rent.service.ConditionReportService import upbrella.be.rent.service.ImprovementReportService import upbrella.be.rent.service.LockerService import upbrella.be.rent.service.RentService -import upbrella.be.slack.service.SlackAlarmService +import upbrella.be.slack.SlackAlarmService import upbrella.be.user.dto.response.SessionUser import upbrella.be.user.repository.UserReader import upbrella.be.util.CustomResponse @@ -97,9 +97,7 @@ class RentController( val userToReturn = userReader.findUserById(user.id) rentService.returnUmbrellaByUser(userToReturn, returnUmbrellaByUserRequest) - val unrefundedRentCount = rentService.countUnrefundedRent() - slackAlarmService.notifyReturn(unrefundedRentCount) return ResponseEntity .ok() .body(CustomResponse( diff --git a/src/main/kotlin/upbrella/be/rent/dto/response/ConditionReportResponse.kt b/src/main/kotlin/upbrella/be/rent/dto/response/ConditionReportResponse.kt index 443e0719..c67a0bbb 100644 --- a/src/main/kotlin/upbrella/be/rent/dto/response/ConditionReportResponse.kt +++ b/src/main/kotlin/upbrella/be/rent/dto/response/ConditionReportResponse.kt @@ -11,7 +11,7 @@ data class ConditionReportResponse( companion object { fun fromConditionReport(conditionReport: ConditionReport): ConditionReportResponse { return ConditionReportResponse( - id = conditionReport.history!!.id!!, + id = conditionReport.history.id!!, umbrellaUuid = conditionReport.history.umbrella.uuid, content = conditionReport.content, etc = conditionReport.etc diff --git a/src/main/kotlin/upbrella/be/rent/dto/response/ImprovementReportResponse.kt b/src/main/kotlin/upbrella/be/rent/dto/response/ImprovementReportResponse.kt index 819dfcd8..d77258b9 100644 --- a/src/main/kotlin/upbrella/be/rent/dto/response/ImprovementReportResponse.kt +++ b/src/main/kotlin/upbrella/be/rent/dto/response/ImprovementReportResponse.kt @@ -11,8 +11,8 @@ data class ImprovementReportResponse( companion object { fun fromImprovementReport(improvementReport: ImprovementReport): ImprovementReportResponse { return ImprovementReportResponse( - id = improvementReport.history?.id ?: 0, - umbrellaUuid = improvementReport.history?.umbrella?.uuid ?: 0, + id = improvementReport.history.id ?: 0, + umbrellaUuid = improvementReport.history.umbrella.uuid, content = improvementReport.content, etc = improvementReport.etc ) diff --git a/src/main/kotlin/upbrella/be/rent/dto/response/RentalHistoryResponse.kt b/src/main/kotlin/upbrella/be/rent/dto/response/RentalHistoryResponse.kt index 089ed35b..0dffe915 100644 --- a/src/main/kotlin/upbrella/be/rent/dto/response/RentalHistoryResponse.kt +++ b/src/main/kotlin/upbrella/be/rent/dto/response/RentalHistoryResponse.kt @@ -2,7 +2,6 @@ package upbrella.be.rent.dto.response import com.fasterxml.jackson.annotation.JsonFormat import java.time.LocalDateTime -import upbrella.be.rent.entity.History data class RentalHistoryResponse( val id: Long, @@ -24,9 +23,6 @@ data class RentalHistoryResponse( val etc: String? = null ) { companion object { - private fun isRefunded(history: History): Boolean { - return history.refundedAt != null - } fun createReturnedHistory(history: HistoryInfoDto, elapsedDay: Int, totalRentalDay: Int): RentalHistoryResponse { return RentalHistoryResponse( diff --git a/src/main/kotlin/upbrella/be/rent/entity/ConditionReport.kt b/src/main/kotlin/upbrella/be/rent/entity/ConditionReport.kt index 45b35c16..aa8dba1b 100644 --- a/src/main/kotlin/upbrella/be/rent/entity/ConditionReport.kt +++ b/src/main/kotlin/upbrella/be/rent/entity/ConditionReport.kt @@ -6,7 +6,7 @@ import javax.persistence.* class ConditionReport( @OneToOne @JoinColumn(name = "history_id") - val history: History? = null, + val history: History, val content: String? = null, val etc: String? = null, @Id diff --git a/src/main/kotlin/upbrella/be/rent/entity/History.kt b/src/main/kotlin/upbrella/be/rent/entity/History.kt index 0d92214b..ad92e04b 100644 --- a/src/main/kotlin/upbrella/be/rent/entity/History.kt +++ b/src/main/kotlin/upbrella/be/rent/entity/History.kt @@ -1,6 +1,5 @@ package upbrella.be.rent.entity -import upbrella.be.rent.dto.request.ReturnUmbrellaByUserRequest import upbrella.be.rent.exception.NotRefundedException import upbrella.be.store.entity.StoreMeta import upbrella.be.umbrella.entity.Umbrella @@ -25,11 +24,11 @@ class History( @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "rent_store_meta_id") - val rentStoreMeta: StoreMeta, + var rentStoreMeta: StoreMeta, @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "return_store_meta_id") - val returnStoreMeta: StoreMeta? = null, + var returnStoreMeta: StoreMeta? = null, val rentedAt: LocalDateTime = LocalDateTime.now(), var returnedAt: LocalDateTime? = null, @@ -60,26 +59,6 @@ class History( ) } - @JvmStatic - fun updateHistoryForReturn( - rentedHistory: History, - returnStoreMeta: StoreMeta, - request: ReturnUmbrellaByUserRequest - ): History { - return History( - id = rentedHistory.id, - umbrella = rentedHistory.umbrella, - user = rentedHistory.user, - paidAt = rentedHistory.paidAt, - bank = request.bank, - accountNumber = request.accountNumber, - rentStoreMeta = rentedHistory.rentStoreMeta, - returnStoreMeta = returnStoreMeta, - rentedAt = rentedHistory.rentedAt, - returnedAt = LocalDateTime.now(), - ) - } - fun ofUserHistory(history: History): SingleHistoryResponse { var isReturned = true var isRefunded = false @@ -139,4 +118,4 @@ class History( this.bank = null this.accountNumber = null } -} \ No newline at end of file +} diff --git a/src/main/kotlin/upbrella/be/rent/entity/ImprovementReport.kt b/src/main/kotlin/upbrella/be/rent/entity/ImprovementReport.kt index 5138284e..cd6ca6f1 100644 --- a/src/main/kotlin/upbrella/be/rent/entity/ImprovementReport.kt +++ b/src/main/kotlin/upbrella/be/rent/entity/ImprovementReport.kt @@ -6,20 +6,10 @@ import javax.persistence.* class ImprovementReport( @OneToOne @JoinColumn(name = "history_id") - val history: History? = null, + val history: History, val content: String? = null, val etc: String? = null, @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - val id: Long? =null -) { - companion object { - @JvmStatic - fun createFromReturn(history: History, content: String): ImprovementReport { - return ImprovementReport( - history = history, - content = content, - ) - } - } -} \ No newline at end of file + val id: Long? = null +) diff --git a/src/main/kotlin/upbrella/be/rent/repository/ConditionReportRepository.kt b/src/main/kotlin/upbrella/be/rent/repository/ConditionReportRepository.kt index 82a044a1..47c3d6c8 100644 --- a/src/main/kotlin/upbrella/be/rent/repository/ConditionReportRepository.kt +++ b/src/main/kotlin/upbrella/be/rent/repository/ConditionReportRepository.kt @@ -3,5 +3,4 @@ package upbrella.be.rent.repository import org.springframework.data.jpa.repository.JpaRepository import upbrella.be.rent.entity.ConditionReport -interface ConditionReportRepository : JpaRepository { -} \ No newline at end of file +interface ConditionReportRepository : JpaRepository diff --git a/src/main/kotlin/upbrella/be/rent/repository/ImprovementReportRepository.kt b/src/main/kotlin/upbrella/be/rent/repository/ImprovementReportRepository.kt index c0819bfc..12dac08d 100644 --- a/src/main/kotlin/upbrella/be/rent/repository/ImprovementReportRepository.kt +++ b/src/main/kotlin/upbrella/be/rent/repository/ImprovementReportRepository.kt @@ -3,5 +3,4 @@ package upbrella.be.rent.repository import org.springframework.data.jpa.repository.JpaRepository import upbrella.be.rent.entity.ImprovementReport -interface ImprovementReportRepository : JpaRepository { -} \ No newline at end of file +interface ImprovementReportRepository : JpaRepository diff --git a/src/main/kotlin/upbrella/be/rent/repository/RentRepositoryImpl.kt b/src/main/kotlin/upbrella/be/rent/repository/RentRepositoryImpl.kt index c4704af8..fd2dabc3 100644 --- a/src/main/kotlin/upbrella/be/rent/repository/RentRepositoryImpl.kt +++ b/src/main/kotlin/upbrella/be/rent/repository/RentRepositoryImpl.kt @@ -27,7 +27,7 @@ class RentRepositoryImpl( .orderBy(history.id.desc()) .offset(pageable.offset) .limit(pageable.pageSize.toLong()) - .fetch(); + .fetch() } override fun findHistoryInfos( @@ -61,7 +61,7 @@ class RentRepositoryImpl( .orderBy(history.id.desc()) .offset(pageable.offset) .limit(pageable.pageSize.toLong()) - .fetch(); + .fetch() } override fun countAll(filter: HistoryFilterRequest, pageable: Pageable): Long { @@ -82,12 +82,12 @@ class RentRepositoryImpl( .leftJoin(history.returnStoreMeta, storeMeta).fetchJoin() .where(history.user.id.eq(userId)) .orderBy(history.id.desc()) - .fetch(); + .fetch() } private fun filterRefunded(filter: HistoryFilterRequest): BooleanExpression? { if (filter.refunded == null) { - return null; + return null } if (filter.refunded == true) { @@ -96,4 +96,4 @@ class RentRepositoryImpl( return history.refundedAt.isNull } -} \ No newline at end of file +} diff --git a/src/main/kotlin/upbrella/be/rent/service/ImprovementReportService.kt b/src/main/kotlin/upbrella/be/rent/service/ImprovementReportService.kt index 7faea2ac..e991ec4d 100644 --- a/src/main/kotlin/upbrella/be/rent/service/ImprovementReportService.kt +++ b/src/main/kotlin/upbrella/be/rent/service/ImprovementReportService.kt @@ -3,7 +3,6 @@ package upbrella.be.rent.service import org.springframework.stereotype.Service import upbrella.be.rent.dto.response.ImprovementReportPageResponse import upbrella.be.rent.dto.response.ImprovementReportResponse -import upbrella.be.rent.entity.History import upbrella.be.rent.entity.ImprovementReport import upbrella.be.rent.repository.ImprovementReportRepository @@ -15,9 +14,9 @@ class ImprovementReportService( fun findAll(): ImprovementReportPageResponse = ImprovementReportPageResponse.of(findAllImprovementReport()) - fun addImprovementReportFromReturn(history: History, content: String) { - val report = ImprovementReport.createFromReturn(history, content) - improvementReportRepository.save(report) + fun save(improvementReport: ImprovementReport) { + + improvementReportRepository.save(improvementReport) } private fun findAllImprovementReport(): List = diff --git a/src/main/kotlin/upbrella/be/rent/service/RentService.kt b/src/main/kotlin/upbrella/be/rent/service/RentService.kt index 23f7b351..c3abc69a 100644 --- a/src/main/kotlin/upbrella/be/rent/service/RentService.kt +++ b/src/main/kotlin/upbrella/be/rent/service/RentService.kt @@ -9,8 +9,10 @@ import upbrella.be.rent.dto.request.ReturnUmbrellaByUserRequest import upbrella.be.rent.dto.response.* import upbrella.be.rent.entity.ConditionReport import upbrella.be.rent.entity.History +import upbrella.be.rent.entity.ImprovementReport import upbrella.be.rent.exception.* import upbrella.be.rent.repository.RentRepository +import upbrella.be.slack.SlackAlarmService import upbrella.be.store.entity.StoreMeta import upbrella.be.store.repository.StoreMetaReader import upbrella.be.umbrella.entity.Umbrella @@ -30,6 +32,7 @@ import java.time.temporal.ChronoUnit class RentService( private val umbrellaService: UmbrellaService, private val storeMetaReader: StoreMetaReader, + private val slackAlarmService: SlackAlarmService, private val improvementReportService: ImprovementReportService, private val rentRepository: RentRepository, private val conditionReportService: ConditionReportService, @@ -65,24 +68,31 @@ class RentService( rentRepository.findByUserIdAndReturnedAtIsNull(userToRent.id).ifPresent { throw ExistingUmbrellaForRentException("[ERROR] 해당 유저가 대여 중인 우산이 있습니다.") } - val willRentUmbrella = umbrellaService.findUmbrellaById(rentUmbrellaByUserRequest.umbrellaId) - if (willRentUmbrella.storeMeta.id != rentUmbrellaByUserRequest.storeId) { + val umbrella = umbrellaService.findUmbrellaById(rentUmbrellaByUserRequest.umbrellaId) + if (umbrella.storeMeta.id != rentUmbrellaByUserRequest.storeId) { throw UmbrellaStoreMissMatchException("[ERROR] 해당 우산은 해당 매장에 존재하지 않습니다.") } - if (willRentUmbrella.missed) { + if (umbrella.missed) { throw MissingUmbrellaException("[ERROR] 해당 우산은 분실되었습니다.") } - if (!willRentUmbrella.rentable) { + if (!umbrella.rentable) { throw NotAvailableUmbrellaException("[ERROR] 해당 우산은 대여중입니다.") } - willRentUmbrella.rentUmbrella() + umbrella.rentUmbrella() val rentalStore = storeMetaReader.findById(rentUmbrellaByUserRequest.storeId) - val conditionReport = rentUmbrellaByUserRequest.conditionReport val history = rentRepository.save( - History.ofCreatedByNewRent(willRentUmbrella, userToRent, rentalStore) + History.ofCreatedByNewRent(umbrella, userToRent, rentalStore) ) - val conditionReportToSave = ConditionReport(history, conditionReport, null, null) - conditionReportService.saveConditionReport(conditionReportToSave) + slackAlarmService.notifyRent(userToRent, history) + + rentUmbrellaByUserRequest.conditionReport + ?.takeIf { it.isNotBlank() } + ?.let { content -> + ConditionReport(history = history, content = content).also { conditionReport -> + conditionReportService.saveConditionReport(conditionReport) + slackAlarmService.notifyConditionReport(conditionReport) + } + } } @Transactional @@ -91,15 +101,34 @@ class RentService( val history = rentRepository.findByUserIdAndReturnedAtIsNull(userToReturn.id) .orElseThrow { NonExistingUmbrellaForRentException("[ERROR] 해당 유저가 대여 중인 우산이 없습니다.") } val returnStore = storeMetaReader.findById(request.returnStoreId) - val updatedHistory = History.updateHistoryForReturn(history, returnStore, request) + + history.bank = request.bank + history.accountNumber = request.accountNumber + history.returnStoreMeta = returnStore + history.returnedAt = LocalDateTime.now() + val returnedUmbrella: Umbrella = history.umbrella returnedUmbrella.returnUmbrella(returnStore) - rentRepository.save(updatedHistory) - addImprovementReportFromReturnByUser(updatedHistory, request) + + val unrefundedRentCount = countUnrefundedRent() + + slackAlarmService.notifyReturn(userToReturn, history, unrefundedRentCount) + rentRepository.save(history) + + request.improvementReportContent?.takeIf { it.isNotBlank() } + ?.let { content -> + ImprovementReport(history = history, content = content).also { improvementReport -> + improvementReportService.save(improvementReport) + slackAlarmService.notifyImprovementReport(improvementReport) + } + } } @Transactional - fun findAllHistories(filter: HistoryFilterRequest, pageable: Pageable): RentalHistoriesPageResponse { + fun findAllHistories( + filter: HistoryFilterRequest, + pageable: Pageable + ): RentalHistoriesPageResponse { val countOfAllHistories = rentRepository.countAll(filter, pageable) val countOfAllPages = countOfAllHistories / pageable.pageSize val rentalHistories = findAllRentalHistory(filter, pageable) @@ -109,19 +138,16 @@ class RentService( fun findAllHistoriesByUser(userId: Long): AllHistoryResponse = AllHistoryResponse.of(findAllByUserId(userId)) - private fun addImprovementReportFromReturnByUser(history: History, request: ReturnUmbrellaByUserRequest) { - request.improvementReportContent?.let { content -> - improvementReportService.addImprovementReportFromReturn(history, content) - } - } - private fun findAllByUserId(userId: Long): List = findAllByUser(userId).map { toSingleHistoryResponse(it) } private fun findAllByUser(userId: Long): List = rentRepository.findAllByUserId(userId) - private fun findAllRentalHistory(filter: HistoryFilterRequest, pageable: Pageable): List = + private fun findAllRentalHistory( + filter: HistoryFilterRequest, + pageable: Pageable + ): List = findHistoryInfos(filter, pageable).map { toRentalHistoryResponse(it) } private fun toSingleHistoryResponse(history: History): SingleHistoryResponse { @@ -141,8 +167,14 @@ class RentService( private fun toRentalHistoryResponse(history: HistoryInfoDto): RentalHistoryResponse { var elapsedDay = ChronoUnit.DAYS.between(history.rentAt, LocalDateTime.now()).toInt() return if (history.returnAt != null) { - elapsedDay = ChronoUnit.DAYS.between(history.rentAt.toLocalDate(), history.returnAt.toLocalDate()).toInt() - val totalRentalDay = ChronoUnit.DAYS.between(history.rentAt.toLocalDate(), history.returnAt.toLocalDate()).toInt() + elapsedDay = ChronoUnit.DAYS.between( + history.rentAt.toLocalDate(), + history.returnAt.toLocalDate() + ).toInt() + val totalRentalDay = ChronoUnit.DAYS.between( + history.rentAt.toLocalDate(), + history.returnAt.toLocalDate() + ).toInt() RentalHistoryResponse.createReturnedHistory(history, elapsedDay, totalRentalDay) } else { RentalHistoryResponse.createNonReturnedHistory(history, elapsedDay) @@ -187,6 +219,9 @@ class RentService( history.deleteBankAccount() } - private fun findHistoryInfos(filter: HistoryFilterRequest, pageable: Pageable): List = + private fun findHistoryInfos( + filter: HistoryFilterRequest, + pageable: Pageable + ): List = rentRepository.findHistoryInfos(filter, pageable) } diff --git a/src/main/kotlin/upbrella/be/slack/SlackAlarmService.kt b/src/main/kotlin/upbrella/be/slack/SlackAlarmService.kt new file mode 100644 index 00000000..b9466e8d --- /dev/null +++ b/src/main/kotlin/upbrella/be/slack/SlackAlarmService.kt @@ -0,0 +1,72 @@ +package upbrella.be.slack + +import org.springframework.http.HttpEntity +import org.springframework.http.HttpMethod.POST +import org.springframework.stereotype.Service +import org.springframework.web.client.RestTemplate +import upbrella.be.config.SlackBotConfig +import upbrella.be.rent.entity.ConditionReport +import upbrella.be.rent.entity.History +import upbrella.be.rent.entity.ImprovementReport +import upbrella.be.user.entity.User + +@Service +class SlackAlarmService( + private val slackBotConfig: SlackBotConfig, + private val restTemplate: RestTemplate +) { + + fun notifyRent(user: User, history: History) { + val message = buildString { + append("*우산 대여 알림: 입금을 확인해주세요.*\n\n") + append("사용자 ID : ${user.id}\n") + append("예금주 이름 : ${user.name}\n") + append("대여 지점 이름 : ${history.rentStoreMeta.name}\n") + } + send(message) + } + + fun notifyReturn(user: User, history: History, unrefundedCount: Long) { + val message = buildString { + append("*우산 반납 알림: 보증금을 환급해주세요.*\n\n") + append("사용자 ID : ${user.id}\n") + append("대여 지점 이름 : ${history.rentStoreMeta.name}\n") + append("대여 시각: ${history.rentedAt}\n") + append("반납 지점 이름 : ${history.returnStoreMeta?.name}\n") + append("반납 시각: ${history.returnedAt}\n") + append("*잔여 환급 대기 건수* : $unrefundedCount") + } + send(message) + } + + private fun send(message: String) { + val request = mutableMapOf( + "text" to message + ) + val entity = HttpEntity(request) + restTemplate.exchange(slackBotConfig.webHookUrl, POST, entity, String::class.java) + } + + fun notifyConditionReport(conditionReport: ConditionReport) { + val message = buildString { + append("*우산 상태 신고 접수*\n\n") + append("우산 ID : ${conditionReport.history.umbrella.id}\n") + append("대여 지점 이름 : ${conditionReport.history.rentStoreMeta.name}\n") + append("신고 내용 : ${conditionReport.content}\n") + } + send(message) + } + + fun notifyImprovementReport(improvementReport: ImprovementReport) { + val message = buildString { + append("*우산 개선 사항 신고가 접수되었습니다.*\n\n") + append("우산 ID : ${improvementReport.history.umbrella.id}\n") + append("대여 지점 이름 : ${improvementReport.history.rentStoreMeta.name}\n") + append("대여 시각: ${improvementReport.history.rentedAt}\n") + append("반납 지점 이름 : ${improvementReport.history.returnStoreMeta?.name}\n") + append("반납 시각: ${improvementReport.history.returnedAt}\n") + append("신고 내용 : ${improvementReport.content}\n") + } + send(message) + } +} diff --git a/src/main/kotlin/upbrella/be/slack/slack/SlackAlarmService.kt b/src/main/kotlin/upbrella/be/slack/slack/SlackAlarmService.kt deleted file mode 100644 index a893db43..00000000 --- a/src/main/kotlin/upbrella/be/slack/slack/SlackAlarmService.kt +++ /dev/null @@ -1,31 +0,0 @@ -package upbrella.be.slack.service - -import org.springframework.http.HttpEntity -import org.springframework.http.HttpMethod.POST -import org.springframework.stereotype.Service -import org.springframework.web.client.RestTemplate -import upbrella.be.config.SlackBotConfig - -@Service -class SlackAlarmService( - private val slackBotConfig: SlackBotConfig, - private val restTemplate: RestTemplate -) { - - fun notifyReturn(unrefundedCount: Long) { - val message = buildString { - append("*우산이 반납되었습니다. 보증금을 환급해주세요.*\n\n") - append("*환급 대기 건수* : ") - append(unrefundedCount) - } - send(message) - } - - private fun send(message: String) { - val request = mutableMapOf( - "text" to message - ) - val entity = HttpEntity(request) - restTemplate.exchange(slackBotConfig.webHookUrl, POST, entity, String::class.java) - } -} diff --git a/src/main/kotlin/upbrella/be/store/dto/response/ImageUrlsResponse.kt b/src/main/kotlin/upbrella/be/store/dto/response/ImageUrlsResponse.kt deleted file mode 100644 index 855ff454..00000000 --- a/src/main/kotlin/upbrella/be/store/dto/response/ImageUrlsResponse.kt +++ /dev/null @@ -1,5 +0,0 @@ -package upbrella.be.store.dto.response - -data class ImageUrlsResponse( - val imageUrls: List -) diff --git a/src/main/kotlin/upbrella/be/store/entity/StoreDetail.kt b/src/main/kotlin/upbrella/be/store/entity/StoreDetail.kt index 6a23d361..6651e317 100644 --- a/src/main/kotlin/upbrella/be/store/entity/StoreDetail.kt +++ b/src/main/kotlin/upbrella/be/store/entity/StoreDetail.kt @@ -3,7 +3,6 @@ package upbrella.be.store.entity import upbrella.be.store.dto.request.CreateStoreRequest import upbrella.be.store.dto.request.UpdateStoreRequest import javax.persistence.* -import kotlin.streams.toList @Entity class StoreDetail( @@ -51,8 +50,7 @@ class StoreDetail( } fun getSortedStoreImages(): List { - return storeImages.stream() - .sorted { o1, o2 -> (o1.id!! - o2.id!!).toInt() } - .toList() + return storeImages + .sortedBy { it.id } } } diff --git a/src/main/kotlin/upbrella/be/store/repository/ClassificationWriter.kt b/src/main/kotlin/upbrella/be/store/repository/ClassificationWriter.kt index 138387bb..b4ce5c62 100644 --- a/src/main/kotlin/upbrella/be/store/repository/ClassificationWriter.kt +++ b/src/main/kotlin/upbrella/be/store/repository/ClassificationWriter.kt @@ -2,7 +2,6 @@ package upbrella.be.store.repository import org.springframework.stereotype.Component import upbrella.be.store.entity.Classification -import upbrella.be.store.entity.ClassificationType @Component class ClassificationWriter( @@ -15,8 +14,4 @@ class ClassificationWriter( fun deleteById(id: Long) { classificationRepository.deleteById(id) } - - fun saveAll(classifications: List) { - classificationRepository.saveAll(classifications) - } -} \ No newline at end of file +} diff --git a/src/main/kotlin/upbrella/be/store/repository/StoreDetailReader.kt b/src/main/kotlin/upbrella/be/store/repository/StoreDetailReader.kt index 292782b6..702f0d85 100644 --- a/src/main/kotlin/upbrella/be/store/repository/StoreDetailReader.kt +++ b/src/main/kotlin/upbrella/be/store/repository/StoreDetailReader.kt @@ -17,7 +17,7 @@ class StoreDetailReader( @Transactional(readOnly = true) fun findByStoreMetaId(storeMetaId: Long): StoreDetail { return storeDetailRepository.findByStoreMetaIdUsingFetchJoin(storeMetaId) - .orElseThrow() { NonExistingStoreDetailException("[ERROR] 존재하지 않는 가게입니다.") } + .orElseThrow { NonExistingStoreDetailException("[ERROR] 존재하지 않는 가게입니다.") } } fun findAllStoresForAdmin(): List { diff --git a/src/main/kotlin/upbrella/be/store/repository/StoreDetailRepository.kt b/src/main/kotlin/upbrella/be/store/repository/StoreDetailRepository.kt index 936961bd..448d33b4 100644 --- a/src/main/kotlin/upbrella/be/store/repository/StoreDetailRepository.kt +++ b/src/main/kotlin/upbrella/be/store/repository/StoreDetailRepository.kt @@ -2,8 +2,5 @@ package upbrella.be.store.repository import org.springframework.data.jpa.repository.JpaRepository import upbrella.be.store.entity.StoreDetail -import java.util.* -interface StoreDetailRepository : JpaRepository, StoreDetailRepositoryCustom { - fun findStoreDetailByStoreMetaId(storeMetaId: Long): Optional -} \ No newline at end of file +interface StoreDetailRepository : JpaRepository, StoreDetailRepositoryCustom diff --git a/src/main/kotlin/upbrella/be/store/repository/StoreImageReader.kt b/src/main/kotlin/upbrella/be/store/repository/StoreImageReader.kt index 6ba6c217..d7667993 100644 --- a/src/main/kotlin/upbrella/be/store/repository/StoreImageReader.kt +++ b/src/main/kotlin/upbrella/be/store/repository/StoreImageReader.kt @@ -1,5 +1,6 @@ package upbrella.be.store.repository +import org.springframework.data.repository.findByIdOrNull import org.springframework.stereotype.Component import upbrella.be.store.entity.StoreImage @@ -8,6 +9,6 @@ class StoreImageReader( private val storeImageRepository: StoreImageRepository ) { fun findById(id: Long): StoreImage? { - return storeImageRepository.findById(id).orElse(null); + return storeImageRepository.findByIdOrNull(id) } -} \ No newline at end of file +} diff --git a/src/main/kotlin/upbrella/be/store/repository/StoreImageRepository.kt b/src/main/kotlin/upbrella/be/store/repository/StoreImageRepository.kt index e2d38fbd..3732f4e9 100644 --- a/src/main/kotlin/upbrella/be/store/repository/StoreImageRepository.kt +++ b/src/main/kotlin/upbrella/be/store/repository/StoreImageRepository.kt @@ -3,6 +3,4 @@ package upbrella.be.store.repository import org.springframework.data.jpa.repository.JpaRepository import upbrella.be.store.entity.StoreImage -interface StoreImageRepository : JpaRepository { - fun findByStoreDetailId(storeDetailId: Long): List -} \ No newline at end of file +interface StoreImageRepository : JpaRepository diff --git a/src/main/kotlin/upbrella/be/store/repository/StoreMetaRepository.kt b/src/main/kotlin/upbrella/be/store/repository/StoreMetaRepository.kt index cdc935f1..b521e5ac 100644 --- a/src/main/kotlin/upbrella/be/store/repository/StoreMetaRepository.kt +++ b/src/main/kotlin/upbrella/be/store/repository/StoreMetaRepository.kt @@ -2,10 +2,8 @@ package upbrella.be.store.repository import org.springframework.data.jpa.repository.JpaRepository import upbrella.be.store.entity.StoreMeta -import java.util.Optional interface StoreMetaRepository : JpaRepository, StoreMetaRepositoryCustom { - fun findByClassificationIdAndDeletedIsFalse(id: Long): Optional fun existsByClassificationIdAndDeletedIsFalse(classificationId: Long): Boolean -} \ No newline at end of file +} diff --git a/src/main/kotlin/upbrella/be/store/service/ClassificationService.kt b/src/main/kotlin/upbrella/be/store/service/ClassificationService.kt index 521e3ff8..8b05eb7b 100644 --- a/src/main/kotlin/upbrella/be/store/service/ClassificationService.kt +++ b/src/main/kotlin/upbrella/be/store/service/ClassificationService.kt @@ -1,6 +1,5 @@ package upbrella.be.store.service -import org.springframework.context.annotation.Lazy import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import upbrella.be.store.dto.request.CreateClassificationRequest @@ -12,7 +11,6 @@ import upbrella.be.store.dto.response.SingleSubClassificationResponse import upbrella.be.store.entity.Classification import upbrella.be.store.entity.ClassificationType import upbrella.be.store.exception.AssignedClassificationException -import upbrella.be.store.exception.IncorrectClassificationException import upbrella.be.store.exception.NonExistingClassificationException import upbrella.be.store.repository.ClassificationReader import upbrella.be.store.repository.ClassificationWriter @@ -83,4 +81,4 @@ class ClassificationService( subClassifications = classifications ) } -} \ No newline at end of file +} diff --git a/src/main/kotlin/upbrella/be/store/service/StoreDetailService.kt b/src/main/kotlin/upbrella/be/store/service/StoreDetailService.kt index 1d900149..e612490d 100644 --- a/src/main/kotlin/upbrella/be/store/service/StoreDetailService.kt +++ b/src/main/kotlin/upbrella/be/store/service/StoreDetailService.kt @@ -62,10 +62,9 @@ class StoreDetailService( val collected = storeDetails.groupBy { it.storeMeta!!.subClassification!!.id } // 같은 ID끼리 리스트로 모은 것을 StoreIntroductionsResponseByClassification으로 변환 - val storeDetailsByClassification = collected.entries.stream() - .sorted(compareBy { it.key }) + val storeDetailsByClassification = collected.entries + .sortedBy { it.key } .map { StoreIntroductionsResponseByClassification.of(it.key!!, it.value) } - .toList() return AllStoreIntroductionResponse.of(storeDetailsByClassification) } diff --git a/src/main/kotlin/upbrella/be/store/service/StoreImageService.kt b/src/main/kotlin/upbrella/be/store/service/StoreImageService.kt index 57ffbd2b..b97b335d 100644 --- a/src/main/kotlin/upbrella/be/store/service/StoreImageService.kt +++ b/src/main/kotlin/upbrella/be/store/service/StoreImageService.kt @@ -1,6 +1,5 @@ package upbrella.be.store.service -import org.springframework.context.annotation.Lazy import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import org.springframework.web.multipart.MultipartFile @@ -16,7 +15,7 @@ import upbrella.be.store.repository.StoreDetailReader import upbrella.be.store.repository.StoreImageReader import upbrella.be.store.repository.StoreImageWriter import java.io.IOException -import java.util.UUID +import java.util.* @Service class StoreImageService( @@ -96,4 +95,4 @@ class StoreImageService( val splitUrl = url.split("/") return splitUrl[splitUrl.size - 2] + "/" + splitUrl[splitUrl.size - 1] } -} \ No newline at end of file +} diff --git a/src/main/kotlin/upbrella/be/umbrella/controller/UmbrellaController.kt b/src/main/kotlin/upbrella/be/umbrella/controller/UmbrellaController.kt index a725d1d0..5454dabd 100644 --- a/src/main/kotlin/upbrella/be/umbrella/controller/UmbrellaController.kt +++ b/src/main/kotlin/upbrella/be/umbrella/controller/UmbrellaController.kt @@ -27,7 +27,7 @@ class UmbrellaController( 200, "전체 우산 현황 조회 성공", UmbrellaPageResponse( - umbrellaResponsePage = umbrellaService!!.findAllUmbrellas(pageable!!) + umbrellaResponsePage = umbrellaService.findAllUmbrellas(pageable!!) ) ) ) @@ -46,7 +46,7 @@ class UmbrellaController( 200, "지점 우산 현황 조회 성공", UmbrellaPageResponse( - umbrellaResponsePage = umbrellaService!!.findUmbrellasByStoreId(storeId, pageable!!) + umbrellaResponsePage = umbrellaService.findUmbrellasByStoreId(storeId, pageable!!) ) ) ) @@ -54,7 +54,7 @@ class UmbrellaController( @PostMapping("/admin/umbrellas") fun addUmbrella(@RequestBody umbrellaCreateRequest: @Valid UmbrellaCreateRequest?): ResponseEntity> { - umbrellaService!!.addUmbrella(umbrellaCreateRequest!!) + umbrellaService.addUmbrella(umbrellaCreateRequest!!) return ResponseEntity .ok() .body( @@ -72,7 +72,7 @@ class UmbrellaController( @RequestBody umbrellaModifyRequest: @Valid UmbrellaModifyRequest?, @PathVariable id: Long ): ResponseEntity> { - umbrellaService!!.modifyUmbrella(id, umbrellaModifyRequest!!) + umbrellaService.modifyUmbrella(id, umbrellaModifyRequest!!) return ResponseEntity .ok() .body( @@ -87,7 +87,7 @@ class UmbrellaController( @DeleteMapping("/admin/umbrellas/{id}") fun deleteUmbrella(@PathVariable id: Long): ResponseEntity> { - umbrellaService!!.deleteUmbrella(id) + umbrellaService.deleteUmbrella(id) return ResponseEntity .ok() .body( @@ -109,7 +109,7 @@ class UmbrellaController( "success", 200, "전체 우산 통계 조회 성공", - umbrellaService!!.getUmbrellaAllStatistics() + umbrellaService.getUmbrellaAllStatistics() ) ) } @@ -123,7 +123,7 @@ class UmbrellaController( "success", 200, "지점 우산 통계 조회 성공", - umbrellaService!!.getUmbrellaStatisticsByStoreId(storeId) + umbrellaService.getUmbrellaStatisticsByStoreId(storeId) ) ) } diff --git a/src/main/kotlin/upbrella/be/umbrella/controller/UmbrellaExceptionHandler.kt b/src/main/kotlin/upbrella/be/umbrella/controller/UmbrellaExceptionHandler.kt index 75353fc7..f1a03e1d 100644 --- a/src/main/kotlin/upbrella/be/umbrella/controller/UmbrellaExceptionHandler.kt +++ b/src/main/kotlin/upbrella/be/umbrella/controller/UmbrellaExceptionHandler.kt @@ -1,12 +1,12 @@ -package upbrella.be.umbrella.controller; +package upbrella.be.umbrella.controller -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.RestControllerAdvice; -import upbrella.be.umbrella.exception.ExistingUmbrellaUuidException; -import upbrella.be.umbrella.exception.NonExistingBorrowedHistoryException; -import upbrella.be.umbrella.exception.NonExistingUmbrellaException; -import upbrella.be.util.CustomErrorResponse; +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.ExceptionHandler +import org.springframework.web.bind.annotation.RestControllerAdvice +import upbrella.be.umbrella.exception.ExistingUmbrellaUuidException +import upbrella.be.umbrella.exception.NonExistingBorrowedHistoryException +import upbrella.be.umbrella.exception.NonExistingUmbrellaException +import upbrella.be.util.CustomErrorResponse @RestControllerAdvice class UmbrellaExceptionHandler { @@ -19,7 +19,7 @@ class UmbrellaExceptionHandler { .body(CustomErrorResponse( "fail", 400, - "이미 존재하는 우산 관리 번호입니다.")); + "이미 존재하는 우산 관리 번호입니다.")) } @ExceptionHandler(NonExistingUmbrellaException::class) @@ -30,7 +30,7 @@ class UmbrellaExceptionHandler { .body(CustomErrorResponse( "fail", 404, - "존재하지 않는 우산 고유 번호입니다.")); + "존재하지 않는 우산 고유 번호입니다.")) } @ExceptionHandler(NonExistingBorrowedHistoryException::class) @@ -41,6 +41,6 @@ class UmbrellaExceptionHandler { .body(CustomErrorResponse( "fail", 404, - "사용자가 빌린 우산이 없습니다.")); + "사용자가 빌린 우산이 없습니다.")) } } diff --git a/src/main/kotlin/upbrella/be/umbrella/dto/request/UmbrellaCreateRequest.kt b/src/main/kotlin/upbrella/be/umbrella/dto/request/UmbrellaCreateRequest.kt index 43a8895f..2d067fe7 100644 --- a/src/main/kotlin/upbrella/be/umbrella/dto/request/UmbrellaCreateRequest.kt +++ b/src/main/kotlin/upbrella/be/umbrella/dto/request/UmbrellaCreateRequest.kt @@ -1,4 +1,4 @@ -package upbrella.be.umbrella.dto.request; +package upbrella.be.umbrella.dto.request data class UmbrellaCreateRequest ( diff --git a/src/main/kotlin/upbrella/be/umbrella/dto/request/UmbrellaModifyRequest.kt b/src/main/kotlin/upbrella/be/umbrella/dto/request/UmbrellaModifyRequest.kt index 6a8162a2..ebabf6bf 100644 --- a/src/main/kotlin/upbrella/be/umbrella/dto/request/UmbrellaModifyRequest.kt +++ b/src/main/kotlin/upbrella/be/umbrella/dto/request/UmbrellaModifyRequest.kt @@ -1,4 +1,4 @@ -package upbrella.be.umbrella.dto.request; +package upbrella.be.umbrella.dto.request data class UmbrellaModifyRequest ( diff --git a/src/main/kotlin/upbrella/be/umbrella/dto/response/UmbrellaPageResponse.kt b/src/main/kotlin/upbrella/be/umbrella/dto/response/UmbrellaPageResponse.kt index fb5df57c..cd973fa7 100644 --- a/src/main/kotlin/upbrella/be/umbrella/dto/response/UmbrellaPageResponse.kt +++ b/src/main/kotlin/upbrella/be/umbrella/dto/response/UmbrellaPageResponse.kt @@ -1,4 +1,4 @@ -package upbrella.be.umbrella.dto.response; +package upbrella.be.umbrella.dto.response data class UmbrellaPageResponse ( diff --git a/src/main/kotlin/upbrella/be/umbrella/dto/response/UmbrellaResponse.kt b/src/main/kotlin/upbrella/be/umbrella/dto/response/UmbrellaResponse.kt index de62f508..9ada544e 100644 --- a/src/main/kotlin/upbrella/be/umbrella/dto/response/UmbrellaResponse.kt +++ b/src/main/kotlin/upbrella/be/umbrella/dto/response/UmbrellaResponse.kt @@ -1,4 +1,4 @@ -package upbrella.be.umbrella.dto.response; +package upbrella.be.umbrella.dto.response data class UmbrellaResponse ( diff --git a/src/main/kotlin/upbrella/be/user/service/BlackListService.kt b/src/main/kotlin/upbrella/be/user/service/BlackListService.kt index aaacc586..bf01b0bd 100644 --- a/src/main/kotlin/upbrella/be/user/service/BlackListService.kt +++ b/src/main/kotlin/upbrella/be/user/service/BlackListService.kt @@ -6,7 +6,6 @@ import upbrella.be.user.dto.response.AllBlackListResponse import upbrella.be.user.exception.BlackListUserException import upbrella.be.user.repository.BlackListReader import upbrella.be.user.repository.BlackListWriter -import upbrella.be.user.repository.UserReader @Service class BlackListService( @@ -28,4 +27,4 @@ class BlackListService( fun checkBlackList(userId: Long) { blackListReader.findById(userId)?.let { throw BlackListUserException("[ERROR] 정지된 회원입니다. 정지된 회원은 이용이 불가능합니다.") } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/upbrella/be/user/service/UserService.kt b/src/main/kotlin/upbrella/be/user/service/UserService.kt index 8a026363..607289e1 100644 --- a/src/main/kotlin/upbrella/be/user/service/UserService.kt +++ b/src/main/kotlin/upbrella/be/user/service/UserService.kt @@ -1,16 +1,20 @@ package upbrella.be.user.service -import org.springframework.context.annotation.Lazy import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import upbrella.be.rent.entity.History import upbrella.be.rent.service.RentService import upbrella.be.user.dto.request.JoinRequest import upbrella.be.user.dto.request.UpdateBankAccountRequest -import upbrella.be.user.dto.response.* +import upbrella.be.user.dto.response.AllUsersInfoResponse +import upbrella.be.user.dto.response.KakaoLoginResponse +import upbrella.be.user.dto.response.SessionUser +import upbrella.be.user.dto.response.UmbrellaBorrowedByUserResponse import upbrella.be.user.entity.BlackList import upbrella.be.user.entity.User -import upbrella.be.user.exception.* +import upbrella.be.user.exception.BlackListUserException +import upbrella.be.user.exception.ExistingMemberException +import upbrella.be.user.exception.NonExistingMemberException import upbrella.be.user.repository.* import upbrella.be.util.AesEncryptor import java.time.LocalDateTime diff --git a/src/test/kotlin/upbrella/be/config/FixtureBuilderFactory.kt b/src/test/kotlin/upbrella/be/config/FixtureBuilderFactory.kt index 174d64c0..e4dd5b31 100644 --- a/src/test/kotlin/upbrella/be/config/FixtureBuilderFactory.kt +++ b/src/test/kotlin/upbrella/be/config/FixtureBuilderFactory.kt @@ -27,7 +27,7 @@ import java.time.LocalDateTime object FixtureBuilderFactory { - val fixtureMonkey = FixtureMonkey.builder() + private val fixtureMonkey: FixtureMonkey = FixtureMonkey.builder() .objectIntrospector(BuilderArbitraryIntrospector.INSTANCE ) .plugin(KotlinPlugin()) .defaultNotNull(true) diff --git a/src/test/kotlin/upbrella/be/config/FixtureFactory.kt b/src/test/kotlin/upbrella/be/config/FixtureFactory.kt index eec6d745..3d22db1a 100644 --- a/src/test/kotlin/upbrella/be/config/FixtureFactory.kt +++ b/src/test/kotlin/upbrella/be/config/FixtureFactory.kt @@ -7,7 +7,6 @@ import com.navercorp.fixturemonkey.kotlin.giveMeBuilder import com.navercorp.fixturemonkey.kotlin.instantiator.instantiateBy import upbrella.be.rent.dto.response.HistoryInfoDto import upbrella.be.rent.dto.response.RentalHistoryResponse -import upbrella.be.rent.entity.History import upbrella.be.store.entity.StoreMeta import upbrella.be.umbrella.dto.request.UmbrellaCreateRequest import upbrella.be.umbrella.dto.response.UmbrellaResponse @@ -78,13 +77,6 @@ object FixtureFactory { .sample() } - @JvmStatic - fun buildHistoryWithUmbrella(umbrella: Umbrella): History { - return fixtureMonkey.giveMeBuilder() - .set("umbrella", umbrella) - .sample() - } - @JvmStatic fun buildOauthToken(): OauthToken { return fixtureMonkey.giveMeBuilder() diff --git a/src/test/kotlin/upbrella/be/docs/common/CustomController.kt b/src/test/kotlin/upbrella/be/docs/common/CustomController.kt index ca31ffa4..d52f1960 100644 --- a/src/test/kotlin/upbrella/be/docs/common/CustomController.kt +++ b/src/test/kotlin/upbrella/be/docs/common/CustomController.kt @@ -15,7 +15,7 @@ class CustomController { return ResponseEntity .ok() .body( - CustomResponse( + CustomResponse( "success", 200, "요청 성공 메시지", @@ -29,7 +29,7 @@ class CustomController { return ResponseEntity .badRequest() .body( - CustomResponse( + CustomResponse( "fail", 400, "잘못된 요청입니다", @@ -37,4 +37,4 @@ class CustomController { ) ) } -} \ No newline at end of file +} diff --git a/src/test/kotlin/upbrella/be/rent/controller/RentControllerTest.kt b/src/test/kotlin/upbrella/be/rent/controller/RentControllerTest.kt index 27090a5b..f0e61958 100644 --- a/src/test/kotlin/upbrella/be/rent/controller/RentControllerTest.kt +++ b/src/test/kotlin/upbrella/be/rent/controller/RentControllerTest.kt @@ -33,7 +33,7 @@ import upbrella.be.rent.service.ConditionReportService import upbrella.be.rent.service.ImprovementReportService import upbrella.be.rent.service.LockerService import upbrella.be.rent.service.RentService -import upbrella.be.slack.service.SlackAlarmService +import upbrella.be.slack.SlackAlarmService import upbrella.be.user.dto.response.SessionUser import upbrella.be.user.entity.User import upbrella.be.user.repository.UserReader diff --git a/src/test/kotlin/upbrella/be/rent/service/RentServiceTest.kt b/src/test/kotlin/upbrella/be/rent/service/RentServiceTest.kt index d32f47ed..a6160974 100644 --- a/src/test/kotlin/upbrella/be/rent/service/RentServiceTest.kt +++ b/src/test/kotlin/upbrella/be/rent/service/RentServiceTest.kt @@ -28,6 +28,7 @@ import upbrella.be.rent.exception.NonExistingHistoryException import upbrella.be.rent.exception.NotAvailableUmbrellaException import upbrella.be.rent.exception.NotRefundedException import upbrella.be.rent.repository.RentRepository +import upbrella.be.slack.SlackAlarmService import upbrella.be.store.entity.StoreMeta import upbrella.be.store.repository.StoreMetaReader import upbrella.be.umbrella.entity.Umbrella @@ -74,6 +75,9 @@ class RentServiceTest { @Mock private lateinit var conditionReportService: ConditionReportService + @Mock + private lateinit var slackAlarmService: SlackAlarmService + @InjectMocks private lateinit var rentService: RentService diff --git a/src/test/kotlin/upbrella/be/slack/service/SlackAlarmServiceTest.kt b/src/test/kotlin/upbrella/be/slack/service/SlackAlarmServiceTest.kt index a4ce30c1..bcd70bc2 100644 --- a/src/test/kotlin/upbrella/be/slack/service/SlackAlarmServiceTest.kt +++ b/src/test/kotlin/upbrella/be/slack/service/SlackAlarmServiceTest.kt @@ -2,6 +2,7 @@ package upbrella.be.slack.service import org.junit.jupiter.api.Assertions.assertAll import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -15,6 +16,13 @@ import org.springframework.http.HttpEntity import org.springframework.http.HttpMethod import org.springframework.web.client.RestTemplate import upbrella.be.config.SlackBotConfig +import upbrella.be.rent.dto.request.RentUmbrellaByUserRequest +import upbrella.be.rent.entity.History +import upbrella.be.slack.SlackAlarmService +import upbrella.be.store.entity.StoreMeta +import upbrella.be.umbrella.entity.Umbrella +import upbrella.be.user.entity.User +import java.time.LocalDateTime @ExtendWith(MockitoExtension::class) class SlackAlarmServiceTest { @@ -27,6 +35,64 @@ class SlackAlarmServiceTest { @InjectMocks private lateinit var slackAlarmService: SlackAlarmService + private lateinit var rentUmbrellaByUserRequest: RentUmbrellaByUserRequest + private lateinit var foundStoreMeta: StoreMeta + private lateinit var foundUmbrella: Umbrella + private lateinit var userToRent: User + private lateinit var history: History + + @BeforeEach + fun setUp() { + rentUmbrellaByUserRequest = RentUmbrellaByUserRequest( + region = "신촌", + storeId = 25L, + umbrellaId = 99L, + conditionReport = "상태 양호" + ) + + foundStoreMeta = StoreMeta( + id = 25L, + name = "motive study cafe", + deleted = false, + category = "category", + activated = false + ) + + foundUmbrella = Umbrella( + id = 99L, + uuid = 99L, + deleted = false, + storeMeta = foundStoreMeta, + rentable = true, + createdAt = LocalDateTime.now(), + etc = "etc", + missed = false, + ) + + userToRent = User( + 0L, + "테스터", + "010-1234-5678", + "email", + false, + null, + null, + 11L + ) + + history = History( + id = 33L, + rentedAt = LocalDateTime.of(1000, 12, 3, 4, 24), + returnedAt = LocalDateTime.of(1000, 12, 3, 4, 25), + refundedAt = LocalDateTime.of(1000, 12, 3, 4, 26), + refundedBy = userToRent, + returnStoreMeta = foundStoreMeta, + umbrella = foundUmbrella, + user = userToRent, + rentStoreMeta = foundStoreMeta, + ) + } + @Test @DisplayName("우산을 반납하면 Slack 봇으로 잔여 환급 개수와 함께 알림이 전송된다.") fun notifyReturn() { @@ -42,9 +108,10 @@ class SlackAlarmServiceTest { ).willReturn(null) // when - slackAlarmService.notifyReturn(1) + slackAlarmService.notifyReturn(userToRent, history, 1L) - val requestEntityCaptor = ArgumentCaptor.forClass(HttpEntity::class.java as Class>) + val requestEntityCaptor = + ArgumentCaptor.forClass(HttpEntity::class.java) // then assertAll( @@ -59,10 +126,9 @@ class SlackAlarmServiceTest { }, { assertTrue( - requestEntityCaptor.value.body.toString().contains("1") + requestEntityCaptor.value.body.toString().contains("우산 반납 알림") ) - }// "1"이 포함되었는지 확인 (우산 반납 수) - + } ) } -} \ No newline at end of file +} diff --git a/src/test/kotlin/upbrella/be/store/service/BusinessHourServiceTest.kt b/src/test/kotlin/upbrella/be/store/service/BusinessHourServiceTest.kt index 6cfd7ebc..abddacde 100644 --- a/src/test/kotlin/upbrella/be/store/service/BusinessHourServiceTest.kt +++ b/src/test/kotlin/upbrella/be/store/service/BusinessHourServiceTest.kt @@ -105,7 +105,7 @@ class BusinessHourServiceTest { val updateBusinessHours = mutableListOf() // 이전 데이터와 업데이트 데이터를 생성 - for (day in DayOfWeek.values()) { + for (day in DayOfWeek.entries) { businessHours.add( BusinessHour( date = day, diff --git a/src/test/kotlin/upbrella/be/store/service/ClassificationServiceTest.kt b/src/test/kotlin/upbrella/be/store/service/ClassificationServiceTest.kt index 38a8959b..9486174d 100644 --- a/src/test/kotlin/upbrella/be/store/service/ClassificationServiceTest.kt +++ b/src/test/kotlin/upbrella/be/store/service/ClassificationServiceTest.kt @@ -1,14 +1,13 @@ package upbrella.be.store.service -import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.jupiter.api.Assertions.assertAll import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.DisplayName -import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith -import org.mockito.BDDMockito.* +import org.mockito.BDDMockito.doNothing +import org.mockito.BDDMockito.given import org.mockito.InjectMocks import org.mockito.Mock import org.mockito.Mockito @@ -18,7 +17,6 @@ import upbrella.be.store.dto.request.CreateSubClassificationRequest import upbrella.be.store.entity.Classification import upbrella.be.store.entity.ClassificationType import upbrella.be.store.exception.AssignedClassificationException -import upbrella.be.store.exception.IncorrectClassificationException import upbrella.be.store.repository.ClassificationReader import upbrella.be.store.repository.ClassificationWriter import upbrella.be.store.repository.StoreMetaReader diff --git a/src/test/kotlin/upbrella/be/store/service/StoreDetailServiceTest.kt b/src/test/kotlin/upbrella/be/store/service/StoreDetailServiceTest.kt index dfed4898..cda5490e 100644 --- a/src/test/kotlin/upbrella/be/store/service/StoreDetailServiceTest.kt +++ b/src/test/kotlin/upbrella/be/store/service/StoreDetailServiceTest.kt @@ -16,7 +16,6 @@ import upbrella.be.store.entity.* import upbrella.be.store.exception.NonExistingStoreDetailException import upbrella.be.store.repository.ClassificationReader import upbrella.be.store.repository.StoreDetailReader -import upbrella.be.store.repository.StoreDetailWriter import upbrella.be.store.repository.StoreMetaReader import upbrella.be.umbrella.service.UmbrellaService import java.time.DayOfWeek @@ -38,15 +37,9 @@ class StoreDetailServiceTest { @Mock private lateinit var storeDetailReader: StoreDetailReader - @Mock - private lateinit var storeDetailWriter: StoreDetailWriter - @Mock private lateinit var businessHourService: BusinessHourService - @Mock - private lateinit var storeImageService: StoreImageService - @InjectMocks private lateinit var storeDetailService: StoreDetailService @@ -180,19 +173,6 @@ class StoreDetailServiceTest { private val businessHours = listOf(monday, tuesday, wednesday, thursday, friday, saturday, sunday) - private val storeMeta = StoreMeta( - id = 1L, - name = "협업 지점명", - activated = true, - deleted = false, - classification = classification, - subClassification = subClassification, - category = "카테고리", - latitude = 33.33, - longitude = 33.33, - businessHours = businessHours - ) - private val first = StoreImage( id = 1L, imageUrl = "https://null.s3.ap-northeast-2.amazonaws.com/store-image/filename.jpg" @@ -203,8 +183,6 @@ class StoreDetailServiceTest { imageUrl = "https://null.s3.ap-northeast-2.amazonaws.com/store-image/filename.jpg" ) - private val images = setOf(first, second) - private val singleStoreResponse = SingleStoreResponse( id = 1L, name = "협업 지점명", @@ -580,9 +558,9 @@ class StoreDetailServiceTest { given(storeDetailReader.findByStoreMetaId(storeId)) .willReturn(storeDetail) - given(classificationReader.findByIdAndType(request.classificationId!!, ClassificationType.CLASSIFICATION)) + given(classificationReader.findByIdAndType(request.classificationId, ClassificationType.CLASSIFICATION)) .willReturn(classificationUpdate) - given(classificationReader.findByIdAndType(request.subClassificationId!!, ClassificationType.SUB_CLASSIFICATION)) + given(classificationReader.findByIdAndType(request.subClassificationId, ClassificationType.SUB_CLASSIFICATION)) .willReturn(subClassificationUpdate) given(storeMetaReader.findById(storeId)) .willReturn(storeMeta) diff --git a/src/test/kotlin/upbrella/be/store/service/StoreMetaServiceTest.kt b/src/test/kotlin/upbrella/be/store/service/StoreMetaServiceTest.kt index 1826aaba..707b2307 100644 --- a/src/test/kotlin/upbrella/be/store/service/StoreMetaServiceTest.kt +++ b/src/test/kotlin/upbrella/be/store/service/StoreMetaServiceTest.kt @@ -2,8 +2,11 @@ package upbrella.be.store.service import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThatThrownBy -import org.junit.jupiter.api.* import org.junit.jupiter.api.Assertions.assertAll +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Nested +import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.mockito.BDDMockito.* import org.mockito.InjectMocks @@ -19,7 +22,6 @@ import upbrella.be.store.dto.response.StoreMetaWithUmbrellaCount import upbrella.be.store.entity.* import upbrella.be.store.exception.DeletedStoreDetailException import upbrella.be.store.exception.EssentialImageException -import upbrella.be.store.exception.NonExistingStoreMetaException import upbrella.be.store.repository.* import upbrella.be.umbrella.entity.Umbrella import upbrella.be.umbrella.exception.NonExistingUmbrellaException diff --git a/src/test/kotlin/upbrella/be/umbrella/controller/UmbrellaControllerTest.kt b/src/test/kotlin/upbrella/be/umbrella/controller/UmbrellaControllerTest.kt index 2f607419..fee3b67a 100644 --- a/src/test/kotlin/upbrella/be/umbrella/controller/UmbrellaControllerTest.kt +++ b/src/test/kotlin/upbrella/be/umbrella/controller/UmbrellaControllerTest.kt @@ -116,7 +116,7 @@ class UmbrellaControllerTest : RestDocsSupport() { } val pageable = PageRequest.of(0, 5) - given(umbrellaService.findUmbrellasByStoreId(storeId.toLong(), pageable)) + given(umbrellaService.findUmbrellasByStoreId(storeId, pageable)) .willReturn(umbrellaResponseList) val info: MultiValueMap = LinkedMultiValueMap() @@ -213,7 +213,7 @@ class UmbrellaControllerTest : RestDocsSupport() { .sample() // 여기서 컨트롤러에 예외 핸들러를 설정 - mockMvc = RestDocsSupport.setControllerAdvice(initController(), + mockMvc = setControllerAdvice(initController(), UmbrellaExceptionHandler() ) @@ -244,7 +244,7 @@ class UmbrellaControllerTest : RestDocsSupport() { @Test fun success() { // given - val id = FixtureBuilderFactory.buildLong(1000) + val id = buildLong(1000) val umbrellaModifyRequest = FixtureBuilderFactory.builderUmbrellaModifyRequest() .sample() @@ -289,11 +289,11 @@ class UmbrellaControllerTest : RestDocsSupport() { @Test fun existingUmbrellaUuid() { // given - val id = FixtureBuilderFactory.buildLong(1000) + val id = buildLong(1000) val umbrellaModifyRequest = FixtureBuilderFactory.builderUmbrellaModifyRequest() .sample() - mockMvc = RestDocsSupport.setControllerAdvice(initController(), + mockMvc = setControllerAdvice(initController(), UmbrellaExceptionHandler() ) @@ -319,11 +319,11 @@ class UmbrellaControllerTest : RestDocsSupport() { @Test fun notExistingUmbrellaId() { // given - val id = FixtureBuilderFactory.buildLong(1000) + val id = buildLong(1000) val umbrellaModifyRequest = FixtureBuilderFactory.builderUmbrellaModifyRequest() .sample() - mockMvc = RestDocsSupport.setControllerAdvice(initController(), + mockMvc = setControllerAdvice(initController(), UmbrellaExceptionHandler() ) @@ -354,7 +354,7 @@ class UmbrellaControllerTest : RestDocsSupport() { @Test fun success() { // given - val id = FixtureBuilderFactory.buildLong(1000) + val id = buildLong(1000) willDoNothing().given(umbrellaService).deleteUmbrella(eq(id)) // when & then @@ -380,8 +380,8 @@ class UmbrellaControllerTest : RestDocsSupport() { @Test fun notExistingUmbrella() { // given - val id = FixtureBuilderFactory.buildLong(1000) - mockMvc = RestDocsSupport.setControllerAdvice(initController(), + val id = buildLong(1000) + mockMvc = setControllerAdvice(initController(), UmbrellaExceptionHandler() ) @@ -492,7 +492,7 @@ class UmbrellaControllerTest : RestDocsSupport() { @Test fun notExistingStoreMeta() { // given - val storeId = FixtureBuilderFactory.buildLong(1000) + val storeId = buildLong(1000) mockMvc = setControllerAdvice(initController(), StoreExceptionHandler()) willThrow( diff --git a/src/test/kotlin/upbrella/be/umbrella/service/UmbrellaServiceTest.kt b/src/test/kotlin/upbrella/be/umbrella/service/UmbrellaServiceTest.kt index b213d113..3fc7549c 100644 --- a/src/test/kotlin/upbrella/be/umbrella/service/UmbrellaServiceTest.kt +++ b/src/test/kotlin/upbrella/be/umbrella/service/UmbrellaServiceTest.kt @@ -22,7 +22,6 @@ import upbrella.be.rent.service.RentService import upbrella.be.store.entity.StoreMeta import upbrella.be.store.exception.NonExistingStoreMetaException import upbrella.be.store.repository.StoreMetaReader -import upbrella.be.store.service.StoreMetaService import upbrella.be.umbrella.dto.request.UmbrellaCreateRequest import upbrella.be.umbrella.dto.request.UmbrellaModifyRequest import upbrella.be.umbrella.dto.response.UmbrellaResponse diff --git a/src/test/kotlin/upbrella/be/user/integration/UserIntegrationTest.kt b/src/test/kotlin/upbrella/be/user/integration/UserIntegrationTest.kt index 91042110..3bef1212 100644 --- a/src/test/kotlin/upbrella/be/user/integration/UserIntegrationTest.kt +++ b/src/test/kotlin/upbrella/be/user/integration/UserIntegrationTest.kt @@ -475,7 +475,8 @@ class UserIntegrationTest : RestDocsSupport() { .andExpect(status().isOk) // then - assertThat(em.find(User::class.java, 1L)).isNotNull + val user = userRepository.findAll().firstOrNull() + assertThat(user).isNotNull } @Test diff --git a/src/test/kotlin/upbrella/be/user/service/BlackListServiceTest.kt b/src/test/kotlin/upbrella/be/user/service/BlackListServiceTest.kt index 09633684..4460b73b 100644 --- a/src/test/kotlin/upbrella/be/user/service/BlackListServiceTest.kt +++ b/src/test/kotlin/upbrella/be/user/service/BlackListServiceTest.kt @@ -14,10 +14,8 @@ import org.mockito.junit.jupiter.MockitoExtension import upbrella.be.user.entity.BlackList import upbrella.be.user.exception.BlackListUserException import upbrella.be.user.repository.BlackListReader -import upbrella.be.user.repository.BlackListRepository import upbrella.be.user.repository.BlackListWriter import java.time.LocalDateTime -import java.util.* @ExtendWith(MockitoExtension::class) class BlackListServiceTest { @@ -90,4 +88,4 @@ class BlackListServiceTest { // then verify(blackListWriter, times(1)).deleteById(blackListId) } -} \ No newline at end of file +} diff --git a/src/test/kotlin/upbrella/be/user/service/UserServiceTest.kt b/src/test/kotlin/upbrella/be/user/service/UserServiceTest.kt index ee11501b..6719fdad 100644 --- a/src/test/kotlin/upbrella/be/user/service/UserServiceTest.kt +++ b/src/test/kotlin/upbrella/be/user/service/UserServiceTest.kt @@ -31,15 +31,15 @@ import java.time.LocalDateTime @ExtendWith(MockitoExtension::class) class UserServiceTest { - @Mock - private lateinit var userRepository: UserRepository - @Mock private lateinit var blackListReader: BlackListReader @Mock private lateinit var blackListWriter: BlackListWriter + @Mock + private lateinit var userRepository: UserRepository + @Mock private lateinit var userReader: UserReader diff --git a/src/test/kotlin/upbrella/be/util/AesTest.kt b/src/test/kotlin/upbrella/be/util/AesTest.kt deleted file mode 100644 index 0b062146..00000000 --- a/src/test/kotlin/upbrella/be/util/AesTest.kt +++ /dev/null @@ -1,52 +0,0 @@ -package upbrella.be.util - -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.DisplayName -import org.junit.jupiter.api.Test -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.test.context.SpringBootTest - -@SpringBootTest -class AesTest @Autowired constructor( - private val aesEncryptor: AesEncryptor, -){ - @Test - @DisplayName("복호화 테스트") - fun testDecrypt() { - // given - val plainText = "Hello World!" - val encryptedText = aesEncryptor.encrypt(plainText) - - // when - val decryptedText = aesEncryptor.decrypt(encryptedText) - - // then - assertThat(decryptedText).isEqualTo("Hello World!") - } - - @Test - @DisplayName("Null을 암호화하는 경우 출력도 Null") - fun testEncryptNullInput() { - // given - val nullString : String? = null - - // when - val encryptedText = aesEncryptor.encrypt(nullString) - - // then - assertThat(encryptedText).isNull() - } - - @Test - @DisplayName("Null을 복호화 하는 경우 경우 출력도 Null") - fun testDecryptNullInput() { - // given - val nullString : String? = null - - // when - val decryptedText = aesEncryptor.decrypt(nullString) - - // then - assertThat(decryptedText).isNull() - } -} diff --git a/src/test/resources/application-test.yml b/src/test/resources/application-test.yml index 8228cec0..27c61b88 100644 --- a/src/test/resources/application-test.yml +++ b/src/test/resources/application-test.yml @@ -1,16 +1,17 @@ spring: - config: - import: "classpath:application.properties" datasource: - url: ${DATABASE_URL} - username: ${DATABASE_USERNAME} - password: ${DATABASE_PASSWORD} - driver-class-name: com.mysql.cj.jdbc.Driver + url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE + username: sa + password: + driver-class-name: org.h2.Driver jpa: + hibernate: + ddl-auto: create-drop properties: hibernate: + dialect: org.hibernate.dialect.H2Dialect format_sql: true - show-sql: true + show_sql: true logging: level: @@ -19,5 +20,4 @@ logging: SQL: DEBUG type: descriptor: - sql: trace - + sql: TRACE