Skip to content

Commit

Permalink
Merge pull request #441 from Team-Ampersand/develop
Browse files Browse the repository at this point in the history
Develop 변경사항 마스터 반영
  • Loading branch information
esperar authored Sep 24, 2024
2 parents 3647ca5 + 3d16cfe commit 7d54a63
Show file tree
Hide file tree
Showing 17 changed files with 241 additions and 85 deletions.
28 changes: 15 additions & 13 deletions .github/workflows/dotori-develop-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ on:

jobs:
build:

runs-on: self-hosted

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
Expand All @@ -24,14 +22,18 @@ jobs:
username: ${{secrets.DOCKERHUB_USERNAME}}
password: ${{secrets.DOCKERHUB_TOKEN}}

- 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
- name: Deploy to dev
uses: appleboy/ssh-action@master
id: dotori-dev
with:
host: ${{ secrets.HOST_DEV }}
username: ubuntu
password: ${{ secrets.PASSWORD }}
port: 22
key: ${{ secrets.KEYPAIR }}
script: |
sudo docker ps
sudo docker rm -f dotori-dev 2>/dev/null || true
sudo docker pull ${{secrets.DOCKERHUB_USERNAME}}/dotori-dev
sudo docker run --net="host" --name dotori-dev --rm -d -p 8080:8080 ${{secrets.DOCKERHUB_USERNAME}}/dotori-dev
sudo docker image prune -f
28 changes: 15 additions & 13 deletions .github/workflows/dotori-master-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ on:

jobs:
build:

runs-on: self-hosted

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
Expand All @@ -24,14 +22,18 @@ jobs:
username: ${{secrets.DOCKERHUB_USERNAME}}
password: ${{secrets.DOCKERHUB_TOKEN}}

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

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

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

- name: Delete old docker images
run: sudo docker system prune -f
- name: Deploy to Master
uses: appleboy/ssh-action@master
id: dotori-prod
with:
host: ${{ secrets.HOST_PROD }}
username: ubuntu
password: ${{ secrets.PASSWORD }}
port: 22
key: ${{ secrets.KEYPAIR }}
script: |
sudo docker ps
sudo docker rm -f dotori-prod 2>/dev/null || true
sudo docker pull ${{secrets.DOCKERHUB_USERNAME}}/dotori-prod
sudo docker run --net="host" --name dotori-prod --rm -d -p 8080:8080 ${{secrets.DOCKERHUB_USERNAME}}/dotori-prod
sudo docker image prune -f
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import com.dotori.v2.domain.email.exception.EmailAuthNotFoundException
import com.dotori.v2.domain.email.exception.EmailNotBeenException
import com.dotori.v2.domain.member.domain.repository.MemberRepository
import com.dotori.v2.domain.member.exception.MemberAlreadyException
import com.dotori.v2.domain.student.presentation.data.res.FindAllStudentListResDto
import com.dotori.v2.global.config.redis.service.RedisCacheService
import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
Expand All @@ -17,7 +19,11 @@ class SignUpServiceImpl(
private val emailCertificateRepository: EmailCertificateRepository,
private val memberRepository: MemberRepository,
private val passwordEncoder: PasswordEncoder,
private val redisCacheService: RedisCacheService
): SignUpService {

private val CACHE_KEY = "memberList"

override fun execute(signUpReqDto: SignUpReqDto) {
val emailCertificate = emailCertificateRepository.findByEmail(signUpReqDto.email)
?: throw EmailAuthNotFoundException()
Expand All @@ -34,5 +40,15 @@ class SignUpServiceImpl(
val member = signUpReqDto.toEntity(encodedPassword)

memberRepository.save(member)
initCache()
}

private fun initCache() {
val cachedData =
redisCacheService.getFromCache(CACHE_KEY) as? FindAllStudentListResDto

if (cachedData != null) {
redisCacheService.deleteFromCache(CACHE_KEY)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.dotori.v2.domain.member.service.impl

import com.dotori.v2.domain.member.service.DeleteProfileImageService
import com.dotori.v2.domain.student.presentation.data.res.FindAllStudentListResDto
import com.dotori.v2.global.config.redis.service.RedisCacheService
import com.dotori.v2.global.thirdparty.aws.s3.S3Service
import com.dotori.v2.global.util.UserUtil
import org.springframework.stereotype.Service
Expand All @@ -10,13 +12,25 @@ import org.springframework.transaction.annotation.Transactional
@Transactional(rollbackFor = [Exception::class])
class DeleteProfileImageServiceImpl(
private val userUtil: UserUtil,
private val s3Service: S3Service
private val s3Service: S3Service,
private val redisCacheService: RedisCacheService
) : DeleteProfileImageService {

private val CACHE_KEY = "memberList"

override fun execute() {
val member = userUtil.fetchCurrentUser()
s3Service.deleteFile(member.profileImage!!)
member.updateProfileImage(null)
initCache()
}

private fun initCache() {
val cachedData =
redisCacheService.getFromCache(CACHE_KEY) as? FindAllStudentListResDto

if (cachedData != null) {
redisCacheService.deleteFromCache(CACHE_KEY)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.dotori.v2.domain.member.service.impl
import com.dotori.v2.domain.member.domain.entity.Member
import com.dotori.v2.global.util.ProfileImageService
import com.dotori.v2.domain.member.service.UpdateProfileImageService
import com.dotori.v2.domain.student.presentation.data.res.FindAllStudentListResDto
import com.dotori.v2.global.config.redis.service.RedisCacheService
import com.dotori.v2.global.util.UserUtil
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
Expand All @@ -12,10 +14,25 @@ import org.springframework.web.multipart.MultipartFile
@Transactional(rollbackFor = [Exception::class])
class UpdateProfileImageServiceImpl(
private val userUtil: UserUtil,
private val profileImageService: ProfileImageService
private val profileImageService: ProfileImageService,
private val redisCacheService: RedisCacheService
): UpdateProfileImageService {

private val CACHE_KEY = "memberList"

override fun execute(multipartFiles: MultipartFile?) {
val member: Member = userUtil.fetchCurrentUser()
val member = userUtil.fetchCurrentUser()
profileImageService.imageUpload(member = member, multipartFiles = multipartFiles)
initCache(member, multipartFiles)
}

private fun initCache(member: Member, multipartFiles: MultipartFile?) {
val cachedData =
redisCacheService.getFromCache(CACHE_KEY) as? FindAllStudentListResDto

if (cachedData != null) {
redisCacheService.deleteFromCache(CACHE_KEY)
}
profileImageService.imageUpload(member = member, multipartFiles = multipartFiles, isUpdate = true)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.dotori.v2.domain.member.service.impl
import com.dotori.v2.domain.member.domain.entity.Member
import com.dotori.v2.global.util.ProfileImageService
import com.dotori.v2.domain.member.service.UploadProfileImageService
import com.dotori.v2.domain.student.presentation.data.res.FindAllStudentListResDto
import com.dotori.v2.global.config.redis.service.RedisCacheService
import com.dotori.v2.global.util.UserUtil
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
Expand All @@ -12,10 +14,24 @@ import org.springframework.web.multipart.MultipartFile
@Transactional(rollbackFor = [Exception::class])
class UploadProfileImageServiceImpl(
private val userUtil: UserUtil,
private val profileImageService: ProfileImageService
private val profileImageService: ProfileImageService,
private val redisCacheService: RedisCacheService
): UploadProfileImageService {

private val CACHE_KEY = "memberList"

override fun execute(multipartFiles: MultipartFile?) {
val member: Member = userUtil.fetchCurrentUser()
profileImageService.imageUpload(member = member, multipartFiles = multipartFiles)
initCache()
}

private fun initCache() {
val cachedData =
redisCacheService.getFromCache(CACHE_KEY) as? FindAllStudentListResDto

if (cachedData != null) {
redisCacheService.deleteFromCache(CACHE_KEY)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.dotori.v2.domain.member.service.impl

import com.dotori.v2.domain.member.domain.repository.MemberRepository
import com.dotori.v2.domain.member.service.WithdrawalService
import com.dotori.v2.domain.student.presentation.data.res.FindAllStudentListResDto
import com.dotori.v2.global.config.redis.service.RedisCacheService
import com.dotori.v2.global.thirdparty.aws.s3.S3Service
import com.dotori.v2.global.util.UserUtil
import org.springframework.stereotype.Service
Expand All @@ -13,10 +15,24 @@ class WithdrawalServiceImpl(
private val memberRepository: MemberRepository,
private val s3Service: S3Service,
private val userUtil: UserUtil,
private val redisCacheService: RedisCacheService
) : WithdrawalService {

private val CACHE_KEY = "memberList"

override fun execute() {
val currentUser = userUtil.fetchCurrentUser()
currentUser.profileImage?.let { s3Service.deleteFile(it) }
memberRepository.delete(currentUser)
initCache()
}

private fun initCache() {
val cachedData =
redisCacheService.getFromCache(CACHE_KEY) as? FindAllStudentListResDto

if (cachedData != null) {
redisCacheService.deleteFromCache(CACHE_KEY)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import com.dotori.v2.domain.selfstudy.util.FindSelfStudyCountUtil
import com.dotori.v2.domain.selfstudy.util.SaveSelfStudyUtil
import com.dotori.v2.domain.selfstudy.util.SelfStudyCheckUtil
import com.dotori.v2.domain.selfstudy.util.ValidDayOfWeekAndHourUtil
import com.dotori.v2.domain.student.presentation.data.res.FindAllStudentListResDto
import com.dotori.v2.global.config.redis.service.RedisCacheService
import com.dotori.v2.global.util.UserUtil
import com.dotori.v2.indicator.IndicatorTarget
import org.springframework.stereotype.Service
Expand All @@ -20,9 +22,12 @@ class ApplySelfStudyServiceImpl(
private val findSelfStudyCountUtil: FindSelfStudyCountUtil,
private val selfStudyCheckUtil: SelfStudyCheckUtil,
private val saveSelfStudyUtil: SaveSelfStudyUtil,
private val validDayOfWeekAndHourUtil: ValidDayOfWeekAndHourUtil
private val validDayOfWeekAndHourUtil: ValidDayOfWeekAndHourUtil,
private val redisCacheService: RedisCacheService
) : ApplySelfStudyService{

private val CACHE_KEY = "memberList"

@IndicatorTarget
override fun execute() {
validDayOfWeekAndHourUtil.validateApply()
Expand All @@ -38,5 +43,15 @@ class ApplySelfStudyServiceImpl(
member.updateSelfStudyStatus(SelfStudyStatus.APPLIED)
selfStudyCount.addCount()
saveSelfStudyUtil.save(member)
initCache()
}

private fun initCache() {
val cachedData =
redisCacheService.getFromCache(CACHE_KEY) as? FindAllStudentListResDto

if (cachedData != null) {
redisCacheService.deleteFromCache(CACHE_KEY)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.dotori.v2.domain.member.domain.repository.MemberRepository
import com.dotori.v2.domain.member.enums.SelfStudyStatus
import com.dotori.v2.domain.member.exception.MemberNotFoundException
import com.dotori.v2.domain.selfstudy.service.BanSelfStudyService
import com.dotori.v2.domain.student.presentation.data.res.FindAllStudentListResDto
import com.dotori.v2.global.config.redis.service.RedisCacheService
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
Expand All @@ -13,11 +15,16 @@ import java.time.LocalDateTime
@Service
@Transactional(rollbackFor = [Exception::class])
class BanSelfStudyServiceImpl(
private val memberRepository: MemberRepository
private val memberRepository: MemberRepository,
private val redisCacheService: RedisCacheService
) : BanSelfStudyService {

private val CACHE_KEY = "memberList"

override fun execute(id: Long) {
val member = memberRepository.findByIdOrNull(id) ?: throw MemberNotFoundException()
updateSelfStudyAndExpiredDate(member, SelfStudyStatus.IMPOSSIBLE, LocalDateTime.now().plusDays(7))
initCache()
}

private fun updateSelfStudyAndExpiredDate(
Expand All @@ -28,4 +35,13 @@ class BanSelfStudyServiceImpl(
findMember.updateSelfStudyStatus(selfStudyStatus)
findMember.updateSelfStudyExpiredDate(localDateTime)
}

private fun initCache() {
val cachedData =
redisCacheService.getFromCache(CACHE_KEY) as? FindAllStudentListResDto

if (cachedData != null) {
redisCacheService.deleteFromCache(CACHE_KEY)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.dotori.v2.domain.member.domain.repository.MemberRepository
import com.dotori.v2.domain.member.enums.SelfStudyStatus
import com.dotori.v2.domain.member.exception.MemberNotFoundException
import com.dotori.v2.domain.selfstudy.service.CancelBanSelfStudyService
import com.dotori.v2.domain.student.presentation.data.res.FindAllStudentListResDto
import com.dotori.v2.global.config.redis.service.RedisCacheService
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
Expand All @@ -13,12 +15,16 @@ import java.time.LocalDateTime
@Service
@Transactional(rollbackFor = [Exception::class])
class CancelBanSelfStudyServiceImpl(
private val memberRepository: MemberRepository
private val memberRepository: MemberRepository,
private val redisCacheService: RedisCacheService
) : CancelBanSelfStudyService{

private val CACHE_KEY = "memberList"

override fun execute(id: Long) {
val member = memberRepository.findByIdOrNull(id) ?: throw MemberNotFoundException()
updateSelfStudyAndExpiredDate(member, SelfStudyStatus.CAN, null)

initCache()
}

private fun updateSelfStudyAndExpiredDate(
Expand All @@ -29,4 +35,13 @@ class CancelBanSelfStudyServiceImpl(
findMember.updateSelfStudyStatus(selfStudyStatus)
findMember.updateSelfStudyExpiredDate(localDateTime)
}

private fun initCache() {
val cachedData =
redisCacheService.getFromCache(CACHE_KEY) as? FindAllStudentListResDto

if (cachedData != null) {
redisCacheService.deleteFromCache(CACHE_KEY)
}
}
}
Loading

0 comments on commit 7d54a63

Please sign in to comment.