Skip to content

Commit

Permalink
Merge pull request #424 from Team-Ampersand/refactor/member
Browse files Browse the repository at this point in the history
refactor :: imageUpload refactor
  • Loading branch information
yena5511 authored Sep 15, 2024
2 parents 1865cd2 + 82d469b commit 6f8a6dc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.dotori.v2.domain.member.domain.entity

import com.dotori.v2.domain.member.domain.entity.QMember.member
import com.dotori.v2.domain.member.enums.*
import com.dotori.v2.domain.rule.domain.entity.RuleViolation
import com.dotori.v2.global.thirdparty.aws.s3.S3Service
import com.dotori.v2.domain.student.presentation.data.req.ModifyStudentInfoRequest
import com.dotori.v2.global.entity.BaseTimeEntity
import java.time.LocalDateTime
Expand Down Expand Up @@ -102,10 +104,6 @@ class Member(
this.selfStudyExpiredDate = localDateTime
}

fun updateProfileImage(profileImage: String?) {
this.profileImage = profileImage
}

fun graduate(period: String): Member {
this.stuNum = period
return this
Expand All @@ -117,4 +115,15 @@ class Member(
this.gender = request.gender
this.roles = Collections.singletonList(request.role)
}

fun updateProfileImage(profileImage: String?): Member {
this.profileImage = profileImage
return this
}

fun isProfileImageExists(): Boolean {
return !this.profileImage.isNullOrEmpty()
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ class UpdateProfileImageServiceImpl(
): UpdateProfileImageService {
override fun execute(multipartFiles: MultipartFile?) {
val member: Member = userUtil.fetchCurrentUser()
profileImageService.imageUpload(member = member, multipartFiles = multipartFiles, isUpdate = true)
profileImageService.imageUpload(member = member, multipartFiles = multipartFiles)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ class ProfileImageService (
private val s3Service: S3Service,
private val redisCacheService: RedisCacheService
) {
fun imageUpload(member: Member, multipartFiles: MultipartFile?, isUpdate: Boolean = false) {

fun imageUpload(member: Member, multipartFiles: MultipartFile?) {
validateExtension(multipartFiles)

val uploadFileUrl: String? = s3Service.uploadSingleFile(multipartFiles)
val uploadFileUrl = s3Service.uploadSingleFile(multipartFiles)

if (isUpdate) s3Service.deleteFile(member.profileImage!!)
if (member.isProfileImageExists()) {
s3Service.deleteFile(member.profileImage!!)
}

member.updateProfileImage(uploadFileUrl)

Expand Down

0 comments on commit 6f8a6dc

Please sign in to comment.