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

Feature/annotation #73

Merged
merged 2 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@ package com.msg.gauth.domain.admin.services
import com.msg.gauth.domain.admin.exception.FileExtensionInvalidException
import com.msg.gauth.domain.user.enums.Gender
import com.msg.gauth.domain.user.repository.UserRepository
import com.msg.gauth.global.annotation.service.TransactionalService
import com.msg.gauth.global.util.ExcelUtil
import org.apache.commons.compress.utils.FileNameUtils
import org.apache.poi.hssf.usermodel.HSSFWorkbook
import org.apache.poi.ss.usermodel.Sheet
import org.apache.poi.ss.usermodel.Workbook
import org.apache.poi.xssf.usermodel.XSSFWorkbook
import org.apache.tika.Tika
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import org.springframework.web.multipart.MultipartFile

@Service
@TransactionalService
class ExcelParsingService(
private val userRepository: UserRepository,
){
@Transactional(rollbackFor = [Exception::class])
fun execute(file: MultipartFile){
val tika = Tika()
val detect = tika.detect(file.bytes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ import com.msg.gauth.domain.user.exception.EmailNotVerifiedException
import com.msg.gauth.domain.user.exception.UserNotFoundException
import com.msg.gauth.domain.auth.presentation.dto.request.PasswordInitReqDto
import com.msg.gauth.domain.user.repository.UserRepository
import com.msg.gauth.global.annotation.service.TransactionalService
import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@TransactionalService
class InitPasswordService(
private val userRepository: UserRepository,
private val emailAuthRepository: EmailAuthRepository,
private val passwordEncoder: PasswordEncoder,
){
@Transactional(rollbackFor = [Exception::class])
fun execute(passwordInitReqDto: PasswordInitReqDto){
val emailAuth = emailAuthRepository.findById(passwordInitReqDto.email)
.orElseThrow { throw EmailNotVerifiedException() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package com.msg.gauth.domain.auth.services

import com.msg.gauth.domain.auth.repository.RefreshTokenRepository
import com.msg.gauth.domain.user.utils.UserUtil
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import com.msg.gauth.global.annotation.service.TransactionalService

@Service
@TransactionalService
class LogoutService(
private val userUtil: UserUtil,
private val refreshTokenRepository: RefreshTokenRepository
) {
@Transactional(rollbackFor = [Exception::class])
fun execute() {
val currentUser = userUtil.fetchCurrentUser()
refreshTokenRepository.findByUserId(currentUser.id)?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ import com.msg.gauth.domain.auth.exception.ExpiredRefreshTokenException
import com.msg.gauth.domain.auth.exception.InvalidRefreshTokenException
import com.msg.gauth.domain.auth.presentation.dto.response.RefreshResponseDto
import com.msg.gauth.domain.auth.repository.RefreshTokenRepository
import com.msg.gauth.global.annotation.service.TransactionalService
import com.msg.gauth.global.security.jwt.JwtTokenProvider
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@TransactionalService
class RefreshService(
private val jwtTokenProvider: JwtTokenProvider,
private val refreshTokenRepository: RefreshTokenRepository
) {
@Transactional(rollbackFor = [Exception::class])
fun execute(refreshToken: String): RefreshResponseDto {
val refreshToken = jwtTokenProvider.parseToken(refreshToken) ?: throw InvalidRefreshTokenException()
val email = jwtTokenProvider.exactEmailFromRefreshToken(refreshToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,17 @@ import com.msg.gauth.domain.user.User
import com.msg.gauth.domain.user.enums.UserState
import com.msg.gauth.domain.user.exception.UserNotFoundException
import com.msg.gauth.domain.user.repository.UserRepository
import com.msg.gauth.global.annotation.service.TransactionalService
import com.msg.gauth.global.security.jwt.JwtTokenProvider
import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@TransactionalService
class SignInService(
private val jwtTokenProvider: JwtTokenProvider,
private val userRepository: UserRepository,
private val refreshTokenRepository: RefreshTokenRepository,
private val passwordEncoder: PasswordEncoder
) {

@Transactional(rollbackFor = [Exception::class])
fun execute(dto: SigninRequestDto): SigninResponseDto {
val user: User = userRepository.findByEmail(dto.email) ?: throw UserNotFoundException()
if (!passwordEncoder.matches(dto.password, user.password))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@ import com.msg.gauth.domain.email.repository.EmailAuthRepository
import com.msg.gauth.domain.user.User
import com.msg.gauth.domain.user.exception.EmailNotVerifiedException
import com.msg.gauth.domain.user.repository.UserRepository
import com.msg.gauth.global.annotation.service.TransactionalService
import com.msg.gauth.global.exception.exceptions.DuplicateEmailException
import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@TransactionalService
class SignUpService(
private val userRepository: UserRepository,
private val passwordEncoder: PasswordEncoder,
private val emailAuthRepository: EmailAuthRepository
) {
@Transactional(rollbackFor = [Exception::class])
fun execute(signUpDto: SignUpDto): Long {
if (userRepository.existsByEmail(signUpDto.email)) {
throw DuplicateEmailException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import com.msg.gauth.domain.auth.presentation.dto.response.SignupImageResDto
import com.msg.gauth.domain.email.exception.AuthCodeExpiredException
import com.msg.gauth.domain.email.exception.AuthCodeNotVerificationException
import com.msg.gauth.domain.email.repository.EmailAuthRepository
import com.msg.gauth.global.annotation.service.TransactionalService
import com.msg.gauth.global.aws.s3.S3Util
import org.springframework.stereotype.Service
import org.springframework.web.multipart.MultipartFile

@Service
@TransactionalService
class SignupImageUploadService(
private val s3Util: S3Util,
private val emailAuthRepository: EmailAuthRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ import com.msg.gauth.domain.client.exception.ClientNotFindException
import com.msg.gauth.domain.client.exception.UserNotMatchException
import com.msg.gauth.domain.client.repository.ClientRepository
import com.msg.gauth.domain.user.utils.UserUtil
import com.msg.gauth.global.annotation.service.TransactionalService
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@TransactionalService
class DeleteClientService(
private val clientRepository: ClientRepository,
private val userUtil: UserUtil,
){
@Transactional(rollbackFor = [Exception::class])
fun execute(id: Long){
val client = clientRepository.findByIdOrNull(id)
?: throw ClientNotFindException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ package com.msg.gauth.domain.client.services

import com.msg.gauth.domain.client.persentation.dto.response.SingleClientResDto
import com.msg.gauth.domain.client.repository.ClientRepository
import com.msg.gauth.domain.user.utils.UserUtil
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import com.msg.gauth.global.annotation.service.ReadOnlyService

@Service
@Transactional(readOnly = true, rollbackFor = [Exception::class])
@ReadOnlyService
class GetAllClientsService(
private val clientRepository: ClientRepository
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import com.msg.gauth.domain.client.exception.ClientNotFindException
import com.msg.gauth.domain.client.persentation.dto.response.ClientDetailResDto
import com.msg.gauth.domain.client.repository.ClientRepository
import com.msg.gauth.domain.user.utils.UserUtil
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import com.msg.gauth.global.annotation.service.ReadOnlyService

@Service
@Transactional(readOnly = true, rollbackFor = [Exception::class])
@ReadOnlyService
class GetMyDetailClientService(
private val clientRepository: ClientRepository,
private val userUtil: UserUtil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ import com.msg.gauth.domain.client.persentation.dto.request.ClientRegisterReqDto
import com.msg.gauth.domain.client.persentation.dto.response.ClientRegisterResDto
import com.msg.gauth.domain.client.repository.ClientRepository
import com.msg.gauth.domain.user.utils.UserUtil
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import com.msg.gauth.global.annotation.service.TransactionalService
import java.util.UUID

@Service
@TransactionalService
class RegisterClientService(
private val clientRepository: ClientRepository,
private val userUtil: UserUtil
) {
@Transactional(rollbackFor = [Exception::class])
fun execute(clientRegisterDto: ClientRegisterReqDto): ClientRegisterResDto {
val clientSecret = createUUID()
val clientId = createUUID()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import com.msg.gauth.domain.client.exception.ClientNotFindException
import com.msg.gauth.domain.client.persentation.dto.request.ClientUpdateReqDto
import com.msg.gauth.domain.client.repository.ClientRepository
import com.msg.gauth.domain.user.utils.UserUtil
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import com.msg.gauth.global.annotation.service.TransactionalService

@Service
@TransactionalService
class UpdateClientService(
private val clientRepository: ClientRepository,
private val userUtil: UserUtil
) {
@Transactional(rollbackFor = [Exception::class])
fun updateClient(id: Long, clientUpdateReqDto: ClientUpdateReqDto){
val client = clientRepository.findByIdAndCreatedBy(id, userUtil.fetchCurrentUser()) ?: throw ClientNotFindException()
clientRepository.save(client.updateClient(clientUpdateReqDto))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ package com.msg.gauth.domain.email.services

import com.msg.gauth.domain.email.exception.AuthCodeExpiredException
import com.msg.gauth.domain.email.repository.EmailAuthRepository
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import com.msg.gauth.global.annotation.service.TransactionalService

@Service
@TransactionalService
class MailVerificationService(
private val emailAuthRepository: EmailAuthRepository
) {

@Transactional(rollbackFor = [Exception::class])
fun execute(email: String, uuid: String) {
val emailAuth = emailAuthRepository.findById(email)
.orElseThrow { AuthCodeExpiredException() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package com.msg.gauth.domain.oauth.services
import com.msg.gauth.domain.oauth.presentation.dto.response.ServiceNameResponseDto
import com.msg.gauth.domain.client.exception.ClientNotFindException
import com.msg.gauth.domain.client.repository.ClientRepository
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import com.msg.gauth.global.annotation.service.ReadOnlyService

@Service
@ReadOnlyService
class GetServiceNameService(
private val clientRepository: ClientRepository,
){
@Transactional(readOnly = true, rollbackFor = [Exception::class])
fun execute(clientId: String): ServiceNameResponseDto {
val client = (clientRepository.findByClientId(clientId)
?: throw ClientNotFindException())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,16 @@ import com.msg.gauth.domain.oauth.repository.OauthCodeRepository
import com.msg.gauth.domain.user.enums.UserState
import com.msg.gauth.domain.user.exception.UserNotFoundException
import com.msg.gauth.domain.user.repository.UserRepository
import org.springframework.data.redis.core.RedisTemplate
import com.msg.gauth.global.annotation.service.ReadOnlyService
import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.util.*

@Service
@ReadOnlyService
class OauthCodeService(
private val userRepository: UserRepository,
private val passwordEncoder: PasswordEncoder,
private val oauthCodeRepository: OauthCodeRepository,
){
@Transactional(readOnly = true, rollbackFor = [Exception::class])
fun execute(oauthLoginRequestDto: OauthCodeRequestDto): OauthCodeResponseDto {
val user = userRepository.findByEmail(oauthLoginRequestDto.email) ?: throw UserNotFoundException()
if (!passwordEncoder.matches(oauthLoginRequestDto.password, user.password))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import com.msg.gauth.domain.oauth.presentation.dto.response.UserTokenResponseDto
import com.msg.gauth.domain.oauth.repository.OauthRefreshTokenRepository
import com.msg.gauth.domain.user.exception.UserNotFoundException
import com.msg.gauth.domain.user.repository.UserRepository
import com.msg.gauth.global.annotation.service.TransactionalService
import com.msg.gauth.global.security.jwt.JwtTokenProvider
import org.springframework.stereotype.Service

@Service
@TransactionalService
class OauthRefreshService(
private val tokenRepository: OauthRefreshTokenRepository,
private val tokenProvider: JwtTokenProvider,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
package com.msg.gauth.domain.oauth.services

import com.msg.gauth.domain.auth.exception.PasswordMismatchException
import com.msg.gauth.domain.client.Client
import com.msg.gauth.domain.client.exception.ClientNotFindException
import com.msg.gauth.domain.client.repository.ClientRepository
import com.msg.gauth.domain.oauth.OauthRefreshToken
import com.msg.gauth.domain.oauth.exception.ClientSecretMismatchException
import com.msg.gauth.domain.oauth.exception.OauthCodeExpiredException
import com.msg.gauth.domain.oauth.presentation.dto.request.OauthLoginReqDto
import com.msg.gauth.domain.oauth.presentation.dto.request.UserTokenRequestDto
import com.msg.gauth.domain.oauth.presentation.dto.response.UserTokenResponseDto
import com.msg.gauth.domain.oauth.repository.OauthCodeRepository
import com.msg.gauth.domain.oauth.repository.OauthRefreshTokenRepository
import com.msg.gauth.domain.user.User
import com.msg.gauth.domain.user.exception.UserNotFoundException
import com.msg.gauth.domain.user.repository.UserRepository
import com.msg.gauth.global.annotation.service.ReadOnlyService
import com.msg.gauth.global.security.jwt.JwtTokenProvider
import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@ReadOnlyService
class OauthTokenService(
private val clientRepository: ClientRepository,
private val userRepository: UserRepository,
Expand All @@ -29,7 +26,6 @@ class OauthTokenService(
private val oauthCodeRepository: OauthCodeRepository,
private val passwordEncoder: PasswordEncoder,
){
@Transactional(rollbackFor = [Exception::class], readOnly = true)
fun execute(userTokenRequestDto: UserTokenRequestDto): UserTokenResponseDto{
val client = (clientRepository.findByClientId(userTokenRequestDto.clientId)
?: throw ClientNotFindException())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@ package com.msg.gauth.domain.user.services

import com.msg.gauth.domain.email.repository.EmailAuthRepository
import com.msg.gauth.domain.user.exception.EmailNotVerifiedException
import com.msg.gauth.domain.user.exception.UserNotFoundException
import com.msg.gauth.domain.user.presentation.dto.request.PasswordChangeReqDto
import com.msg.gauth.domain.user.repository.UserRepository
import com.msg.gauth.domain.user.utils.UserUtil
import com.msg.gauth.global.annotation.service.TransactionalService
import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@TransactionalService
class ChangePasswordService(
private val emailAuthRepository: EmailAuthRepository,
private val userUtil: UserUtil,
private val userRepository: UserRepository,
private val passwordEncoder: PasswordEncoder,
){
@Transactional(rollbackFor = [Exception::class])
fun execute(passwordChangeReqDto: PasswordChangeReqDto){
val currentUser = userUtil.fetchCurrentUser()
val emailAuth = emailAuthRepository.findById(currentUser.email)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package com.msg.gauth.domain.user.services
import com.msg.gauth.domain.client.repository.ClientRepository
import com.msg.gauth.domain.user.presentation.dto.response.MyProfileResDto
import com.msg.gauth.domain.user.utils.UserUtil
import org.springframework.stereotype.Service
import com.msg.gauth.global.annotation.service.ReadOnlyService

@Service
@ReadOnlyService
class MyProfileService(
private val userUtil: UserUtil,
private val clientRepository: ClientRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@ package com.msg.gauth.domain.user.services

import com.msg.gauth.domain.user.repository.UserRepository
import com.msg.gauth.domain.user.utils.UserUtil
import com.msg.gauth.global.annotation.service.TransactionalService
import com.msg.gauth.global.aws.s3.S3Util
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import org.springframework.web.multipart.MultipartFile

@Service
@TransactionalService
class UploadProfileService(
private val s3Util: S3Util,
private val userUtil: UserUtil,
private val userRepository: UserRepository,
){

@Transactional(rollbackFor = [Exception::class])
fun execute(file: MultipartFile){
val url = s3Util.upload(file)
val user = userUtil.fetchCurrentUser()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.msg.gauth.global.annotation.service

import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true, rollbackFor = [Exception::class])
annotation class ReadOnlyService()
Loading