Skip to content

Commit

Permalink
Merge pull request #560 from School-of-Company/553-add/upload-excel-f…
Browse files Browse the repository at this point in the history
…or-student-error-handling

# 553 학생 정보 일괄 삽입 예외 핸들링
  • Loading branch information
JuuuuHong authored Aug 15, 2024
2 parents 2b1e929 + 89225f3 commit bfd3d13
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package team.msg.domain.admin.exception

import team.msg.domain.admin.exception.constant.AdminErrorCode
import team.msg.global.error.exception.BitgouelException

class InvalidCellTypeException(
message: String
) : BitgouelException(message, AdminErrorCode.INVALID_CELL_TYPE.status)
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package team.msg.domain.admin.exception.constant
enum class AdminErrorCode(
val status: Int
) {
INVALID_CELL_TYPE(400),
ADMIN_NOT_FOUND(404)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.springframework.web.multipart.MultipartFile
import team.msg.common.enums.ApproveStatus
import team.msg.common.util.StudentUtil
import team.msg.common.util.UserUtil
import team.msg.domain.admin.exception.InvalidCellTypeException
import team.msg.domain.admin.presentation.data.request.QueryUsersRequest
import team.msg.domain.club.exception.ClubNotFoundException
import team.msg.domain.club.model.Club
Expand All @@ -21,6 +22,7 @@ import team.msg.domain.user.model.User
import team.msg.domain.user.presentation.data.response.UserResponse
import team.msg.domain.user.presentation.data.response.UsersResponse
import team.msg.domain.user.repository.UserRepository
import team.msg.global.exception.InternalServerException
import java.util.*

@Service
Expand Down Expand Up @@ -115,7 +117,13 @@ class AdminServiceImpl(
@Transactional(rollbackFor = [Exception::class])
override fun uploadStudentListExcel(file: MultipartFile) {
file.inputStream.use {
val workbook = WorkbookFactory.create(file.inputStream)
val workbook = try {
WorkbookFactory.create(file.inputStream)
} catch (e: IndexOutOfBoundsException) {
throw InvalidCellTypeException("전화번호 셀 서식을 텍스트로 바꿔주세요.")
} catch (e: Exception) {
throw InternalServerException("엑셀 파일 처리 중 문제가 발생했습니다. info : [ errorMessage = ${e.message}")
}

val sheet = workbook.getSheetAt(0)

Expand Down Expand Up @@ -151,18 +159,18 @@ class AdminServiceImpl(
private fun validateExcelStudentData(email: String, phoneNumber: String, password: String) {
val emailRegex = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}\$".toRegex()
if (!email.matches(emailRegex))
throw InvalidEmailException("유효하지 않은 이메일입니다. [ email = $email ]")
throw InvalidEmailException("유효하지 않은 이메일입니다. info : [ email = $email ]")

val phoneRegex = "^010[0-9]{8}\$".toRegex()
if (!phoneNumber.matches(phoneRegex))
throw InvalidPhoneNumberException("유효하지 않은 휴대폰 번호입니다. [ phoneNumber = $phoneNumber ]")
throw InvalidPhoneNumberException("유효하지 않은 휴대폰 번호입니다. info : [ phoneNumber = $phoneNumber ]")

val passwordRegex = "^(?=.*[A-Za-z0-9])[A-Za-z0-9!@#\\\\\$%^&*]{8,24}\$".toRegex()
if (!password.matches(passwordRegex))
throw InvalidPasswordException("유효하지 않은 비밀번호입니다. [ password = $password ]")
throw InvalidPasswordException("유효하지 않은 비밀번호입니다. info : [ password = $password ]")
}

private infix fun ClubRepository.findByName(clubName: String): Club =
this.findByName(clubName) ?: throw ClubNotFoundException("존재하지 않는 동아리입니다. Info [ clubName = $clubName ]")
this.findByName(clubName) ?: throw ClubNotFoundException("존재하지 않는 동아리입니다. info : [ clubName = $clubName ]")

}
1 change: 1 addition & 0 deletions bitgouel-api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ spring:
connection-timeout: 5000
timeout: 5000
write timeout: 5000

redis:
host: ${REDIS_HOST}
port: ${REDIS_PORT}
Expand Down
2 changes: 1 addition & 1 deletion scripts/deploy.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ elif [ "$DEPLOYMENT_ACTIVE_PROFILES" == "prod" ]; then
else
echo "Invalid Active profiles"
exit 1
fi
fi

0 comments on commit bfd3d13

Please sign in to comment.