Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #395

Merged
merged 10 commits into from
Aug 8, 2024
9 changes: 6 additions & 3 deletions .github/workflows/dotori-develop-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ jobs:
username: ${{secrets.DOCKERHUB_USERNAME}}
password: ${{secrets.DOCKERHUB_TOKEN}}

- name: Pull Docker image
run: sudo docker pull ${{secrets.DOCKERHUB_USERNAME}}/dotori-dev

- name: Docker stop container
run: sudo docker rm -f dotori-dev 2>/dev/null || true

- name: Docker remove Image
run: sudo docker rmi ${{secrets.DOCKERHUB_USERNAME}}/dotori-dev

- name: Pull Docker image
run: sudo docker pull ${{secrets.DOCKERHUB_USERNAME}}/dotori-dev

- name: Run Docker Container
run: sudo docker run --net="host" --name dotori-dev --rm -d -p 8080:8080 ${{secrets.DOCKERHUB_USERNAME}}/dotori-dev

Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/dotori-master-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ jobs:
username: ${{secrets.DOCKERHUB_USERNAME}}
password: ${{secrets.DOCKERHUB_TOKEN}}

- name: Stop Docker container
run: sudo docker rm -f dotori 2>/dev/null || true

- name: Remove Docker Image
run: sudo docker rmi ${{secrets.DOCKERHUB_USERNAME}}/dotori

- name: Pull Docker image
run: sudo docker pull ${{secrets.DOCKERHUB_USERNAME}}/dotori

- name: Docker stop container
run: sudo docker rm -f dotori 2>/dev/null || true

- name: Run Docker Container
run: sudo docker run --net="host" --name dotori --rm -d -p 8080:8080 ${{secrets.DOCKERHUB_USERNAME}}/dotori

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import com.dotori.v2.domain.massage.domain.entity.MassageCount
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Lock
import javax.persistence.LockModeType
import org.springframework.data.jpa.repository.Query

interface MassageCountRepository : JpaRepository<MassageCount, Long> {
@Lock(LockModeType.PESSIMISTIC_WRITE)
fun findMassageCountById(id: Long): MassageCount

@Lock(LockModeType.PESSIMISTIC_WRITE)
@Query("select m from MassageCount m where m = :id")
fun findMassageCountByIdForUpdate(id: Long): MassageCount
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@ package com.dotori.v2.domain.massage.service.impl

import com.dotori.v2.domain.massage.domain.entity.MassageCount
import com.dotori.v2.domain.massage.domain.repository.MassageCountRepository
import com.dotori.v2.domain.massage.exception.MassageOverException
import com.dotori.v2.domain.massage.presentation.dto.res.MassageInfoResDto
import com.dotori.v2.domain.massage.service.GetMassageInfoService
import com.dotori.v2.domain.massage.util.ValidDayOfWeekAndHourMassageUtil
import com.dotori.v2.domain.member.domain.entity.Member
import com.dotori.v2.domain.member.enums.MassageStatus
import com.dotori.v2.global.error.exception.BasicException
import com.dotori.v2.global.util.UserUtil
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true, rollbackFor = [Exception::class])
@Transactional(readOnly = true)
class GetMassageInfoServiceImpl(
private val massageCountRepository: MassageCountRepository,
private val validDayOfWeekAndHourMassageUtil: ValidDayOfWeekAndHourMassageUtil,
private val userUtil: UserUtil,
) : GetMassageInfoService {

override fun execute(): MassageInfoResDto {
val massageCount = massageCountRepository.findMassageCountById(1L)
val member = userUtil.fetchCurrentUser()
Expand All @@ -41,11 +40,7 @@ class GetMassageInfoServiceImpl(
private fun isMassageStatusCan(member: Member) = member.massageStatus == MassageStatus.CAN

private fun validMassageApplyCant(massageCount: MassageCount): Boolean {
try {
validDayOfWeekAndHourMassageUtil.validateApply()
if (massageCount.count >= massageCount.limit)
throw MassageOverException()
} catch (ex: BasicException) {
if (!validDayOfWeekAndHourMassageUtil.isApplyValid() || massageCount.count >= massageCount.limit) {
return true
}
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ class FindMassageCountUtil(
private val massageCountRepository: MassageCountRepository
) {
fun findMassageCount(): MassageCount =
massageCountRepository.findMassageCountById(1L)
massageCountRepository.findMassageCountByIdForUpdate(1L)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import com.dotori.v2.domain.massage.exception.NotMassageApplyHourException
import com.dotori.v2.domain.massage.exception.NotMassageCancelDayException
import com.dotori.v2.domain.massage.exception.NotMassageCancelHourException
import org.springframework.stereotype.Component
import java.lang.Exception
import java.time.DayOfWeek
import java.time.LocalDateTime

@Component
class ValidDayOfWeekAndHourMassageUtil {

fun validateApply() {
val currentTime = LocalDateTime.now()
val dayOfWeek = currentTime.dayOfWeek
Expand All @@ -34,4 +36,13 @@ class ValidDayOfWeekAndHourMassageUtil {
throw NotMassageCancelHourException()
}

fun isApplyValid(): Boolean {
return try {
validateApply()
true
} catch (e: Exception) {
false
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import com.dotori.v2.domain.selfstudy.domain.entity.SelfStudyCount
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Lock
import javax.persistence.LockModeType
import org.springframework.data.jpa.repository.Query


interface SelfStudyCountRepository : JpaRepository<SelfStudyCount, Long> {
@Lock(LockModeType.PESSIMISTIC_WRITE)
fun findSelfStudyCountById(id: Long): SelfStudyCount

@Lock(LockModeType.PESSIMISTIC_WRITE)
@Query("select s from SelfStudyCount s where s.id = :id")
fun findSelfStudyCountByIdForUpdate(id: Long): SelfStudyCount
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package com.dotori.v2.domain.selfstudy.service.impl

import com.dotori.v2.domain.member.domain.entity.Member
import com.dotori.v2.domain.member.enums.SelfStudyStatus
import com.dotori.v2.domain.selfstudy.domain.entity.SelfStudyCount
import com.dotori.v2.domain.selfstudy.domain.repository.SelfStudyCountRepository
import com.dotori.v2.domain.selfstudy.exception.SelfStudyOverException
import com.dotori.v2.domain.selfstudy.presentation.dto.res.SelfStudyInfoResDto
import com.dotori.v2.domain.selfstudy.service.GetSelfStudyInfoService
import com.dotori.v2.domain.selfstudy.util.ValidDayOfWeekAndHourUtil
import com.dotori.v2.global.error.exception.BasicException
import com.dotori.v2.global.util.UserUtil
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true, rollbackFor = [Exception::class])
@Transactional(readOnly = true)
class GetSelfStudyInfoServiceImpl(
private val selfStudyCountRepository: SelfStudyCountRepository,
private val validDayOfWeekAndHourUtil: ValidDayOfWeekAndHourUtil,
Expand All @@ -39,11 +36,7 @@ class GetSelfStudyInfoServiceImpl(
}

private fun validSelfStudyApplyCant(selfStudyCount: SelfStudyCount): Boolean {
try {
validDayOfWeekAndHourUtil.validateApply()
if (selfStudyCount.count >= selfStudyCount.limit)
throw SelfStudyOverException()
} catch (ex: BasicException) {
if (!validDayOfWeekAndHourUtil.isApplyValid() || selfStudyCount.count >= selfStudyCount.limit) {
return true
}
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ class FindSelfStudyCountUtil(
private val selfStudyCountRepository: SelfStudyCountRepository
) {
fun findSelfStudyCount(): SelfStudyCount =
selfStudyCountRepository.findSelfStudyCountById(1L)
selfStudyCountRepository.findSelfStudyCountByIdForUpdate(1L)
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,12 @@ class ValidDayOfWeekAndHourUtil(
private fun isDevProfile(): Boolean {
return environment.activeProfiles.contains("dev")
}
fun isApplyValid(): Boolean {
return try {
validateApply()
true
} catch (ex: BasicException) {
false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class GetMassageInfoServiceTest : BehaviorSpec({
}
}

every { validDayOfWeekAndHourMassageUtil.validateApply() } throws NotMassageApplyDayException()
every { validDayOfWeekAndHourMassageUtil.isApplyValid() } returns false
`when`("신청할 수 없는 요일일때") {
val result = getMassageInfoServiceImpl.execute()
then("massageStatus가 CANT여야함") {
Expand All @@ -45,7 +45,7 @@ class GetMassageInfoServiceTest : BehaviorSpec({
}
init(massageCountRepository, massageCount, userUtil, member, validDayOfWeekAndHourMassageUtil)

every { validDayOfWeekAndHourMassageUtil.validateApply() } throws NotMassageApplyHourException()
every { validDayOfWeekAndHourMassageUtil.isApplyValid() } returns false
`when`("신청할 수 없는 시간일때") {
val result = getMassageInfoServiceImpl.execute()
then("massageStatus가 CANT여야함") {
Expand Down Expand Up @@ -82,5 +82,5 @@ private fun init(
) {
every { massageCountRepository.findMassageCountById(1L) } returns massageCount
every { userUtil.fetchCurrentUser() } returns member
every { validDayOfWeekAndHourMassageUtil.validateApply() } returns Unit
every { validDayOfWeekAndHourMassageUtil.isApplyValid() } returns true
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class GetSelfStudyInfoServiceTest : BehaviorSpec({
val userUtil = mockk<UserUtil>()

val service = GetSelfStudyInfoServiceImpl(selfStudyCountRepository, validDayOfWeekAndHourUtil, userUtil)
given("유저가 주어지고"){
given("유저가 주어지고") {
val testMember = Member(
memberName = "test",
stuNum = "2116",
Expand All @@ -35,13 +35,13 @@ class GetSelfStudyInfoServiceTest : BehaviorSpec({
every { userUtil.fetchCurrentUser() } returns testMember
val selfStudyCount = SelfStudyCount(id = 1)
every { selfStudyCountRepository.findSelfStudyCountById(1) } returns selfStudyCount
every { validDayOfWeekAndHourUtil.validateApply() } returns Unit
every { validDayOfWeekAndHourUtil.isApplyValid() } returns true
selfStudyCount.addCount()
selfStudyCount.addCount()
`when`("서비스를 실행하면"){
`when`("서비스를 실행하면") {
val result = service.execute()
then("결괴값이 유저의 정보와 2가 반환되어야함"){
result shouldBe SelfStudyInfoResDto(selfStudyStatus = testMember.selfStudyStatus, limit = 50, count = selfStudyCount.count)
then("결과값이 유저의 정보와 2가 반환되어야 함") {
result shouldBe SelfStudyInfoResDto(selfStudyStatus = testMember.selfStudyStatus,limit = 50, count = selfStudyCount.count)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class FindSelfStudyCountUtilTest : BehaviorSpec({
`when`("유틸을 실행할때") {
selfStudyCountUtil.findSelfStudyCount()
then("selfStudyCountRepository는 조회 메서드를 실행해야됨") {
verify(exactly = 1) { selfStudyCountRepository.findSelfStudyCountById(1L) }
verify(exactly = 1) { selfStudyCountRepository.findSelfStudyCountByIdForUpdate(1L) }
}
}
}
Expand Down
Loading