Skip to content

Commit

Permalink
πŸš€ :: 1.3.0 ALPHA
Browse files Browse the repository at this point in the history
β€’ 루틴이 μš”μΌλ‹Ή ν•˜λ‚˜λ§Œ ν• λ‹Ή λ˜λ„λ‘ μˆ˜μ •
β€’ 였늘의 루틴 쑰회 API κ΅¬ν˜„
β€’ 걸음수 생성, μˆ˜μ • API κ΅¬ν˜„
  • Loading branch information
gurdl0525 authored Feb 8, 2024
2 parents 616b092 + bb4762d commit 148b6aa
Show file tree
Hide file tree
Showing 83 changed files with 976 additions and 182 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,6 @@ jobs:
SWAGGER_UI_PATH=${{ secrets.SWAGGER_UI_PATH }}
FRONT_DOMAIN=${{ secrets.FRONT_DOMAIN }}
BACK_DOMAIN=${{ secrets.BACK_DOMAIN_PROD }}
CSRF_HEADER=${{ secrets.CSRF_HEADER }}
CSRF_COOKIE=${{ secrets.CSRF_COOKIE }}
CSRF_PARAMETER=${{ secrets.CSRF_PARAMETER }}
3 changes: 3 additions & 0 deletions .github/workflows/deploy-stag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,6 @@ jobs:
SWAGGER_UI_PATH=${{ secrets.SWAGGER_UI_PATH }}
FRONT_LOCAL=${{ secrets.FRONT_LOCAL }}
BACK_DOMAIN=${{ secrets.BACK_DOMAIN_STAG }}
CSRF_HEADER=${{ secrets.CSRF_HEADER }}
CSRF_COOKIE=${{ secrets.CSRF_COOKIE }}
CSRF_PARAMETER=${{ secrets.CSRF_PARAMETER }}
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ ENV BACK_DOMAIN ${BACK_DOMAIN}

ENV SPRING_PROFILES_ACTIVE ${PROFILE}

ARG CSRF_HEADER
ENV CSRF_HEADER ${CSRF_HEADER}

ARG CSRF_COOKIE
ENV CSRF_COOKIE ${CSRF_COOKIE}

ARG CSRF_PARAMETER
ENV CSRF_PARAMETER ${CSRF_PARAMETER}

EXPOSE 8080

ENTRYPOINT ["java", "-jar", "application.jar"]
3 changes: 3 additions & 0 deletions maeumgagym-application/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ dependencies {
implementation("com.querydsl:querydsl-jpa:${PluginVersions.QUERY_DSL}")
kapt("com.querydsl:querydsl-apt:${PluginVersions.QUERY_DSL}:jpa")
kapt("org.springframework.boot:spring-boot-configuration-processor")

// redis
implementation(Dependencies.REDIS)
}

allOpen {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ object TableNames {
const val PICKLE_TAG_INDEX = "${INDEX_PREFIX}pickle_tag"

const val PICKLE_LIKE_INDEX = "${INDEX_PREFIX}pickle_like"

const val REDIS_STEP_TABLE = "${TABLE_PREFIX}step"
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PickleMapper(
description = description,
title = title,
uploader = userMapper.toEntity(uploader),
likes = em.find(PickleJpaEntity::class.java, videoId).likes,
likes = em.find(PickleJpaEntity::class.java, videoId)?.likes ?: mutableSetOf(),
likeCount = likeCount,
tags = tags,
createdAt = createdAt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,44 @@ package com.info.maeumgagym.domain.routine

import com.info.common.PersistenceAdapter
import com.info.maeumgagym.domain.routine.mapper.RoutineMapper
import com.info.maeumgagym.domain.routine.repository.RoutineNativeRepository
import com.info.maeumgagym.domain.routine.repository.RoutineRepository
import com.info.maeumgagym.routine.model.Routine
import com.info.maeumgagym.routine.port.out.DeleteRoutinePort
import com.info.maeumgagym.routine.port.out.ReadRoutinePort
import com.info.maeumgagym.routine.port.out.ReadRoutineByIdPort
import com.info.maeumgagym.routine.port.out.SaveRoutinePort
import org.springframework.transaction.annotation.Propagation
import org.springframework.transaction.annotation.Transactional
import java.time.DayOfWeek
import java.util.*

@PersistenceAdapter
internal class RoutinePersistenceAdapter(
private val routineMapper: RoutineMapper,
private val routineRepository: RoutineRepository
) : SaveRoutinePort, ReadRoutinePort, DeleteRoutinePort, ReadRoutineByIdPort {
private val routineRepository: RoutineRepository,
private val routineNativeRepository: RoutineNativeRepository
) : SaveRoutinePort, ReadRoutinePort, DeleteRoutinePort {

@Transactional(propagation = Propagation.MANDATORY)
override fun save(routine: Routine): Routine {
val routineJpaEntity = routineRepository.save(routineMapper.toEntity(routine))
return routineMapper.toDomain(routineJpaEntity)
}

override fun readById(routineId: Long): Routine? =
routineRepository.findById(routineId)?.let { routineMapper.toDomain(it) }

override fun readAllByUserId(userId: UUID): List<Routine> {
val routineEntityList = routineRepository.findAllByUserId(userId)
return routineEntityList.map { routineMapper.toDomain(it) }
}

override fun readByUserIdAndDayOfWeekAndIsArchivedFalse(userId: UUID, dayOfWeek: DayOfWeek): Routine? =
routineNativeRepository.findByUserIdAndDayOfWeekAndIsArchivedFalse(userId, dayOfWeek.name)?.run {
routineMapper.toDomain(this)
}

@Transactional(propagation = Propagation.MANDATORY)
override fun delete(routine: Routine) =
routineRepository.delete(routineMapper.toEntity(routine))

override fun readRoutineById(routineId: Long): Routine? =
routineRepository.findById(routineId)?.let { routineMapper.toDomain(it) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RoutineJpaEntity(
var routineName: String = routineName
protected set

@ElementCollection
@ElementCollection(fetch = FetchType.EAGER)
var exerciseInfoList: MutableList<ExerciseInfo> = exerciseInfoList
protected set

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import com.info.maeumgagym.routine.model.ExerciseInfoModel
import com.info.maeumgagym.routine.model.Routine
import com.info.maeumgagym.routine.model.RoutineStatusModel
import org.springframework.stereotype.Component
import javax.persistence.EntityManager

@Component
class RoutineMapper {
class RoutineMapper(
private val em: EntityManager
) {
fun toEntity(routine: Routine): RoutineJpaEntity = routine.run {
RoutineJpaEntity(
id = id,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.info.maeumgagym.domain.routine.repository

import com.info.maeumgagym.TableNames
import com.info.maeumgagym.domain.routine.entity.RoutineJpaEntity
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.Repository
import org.springframework.data.repository.query.Param
import java.util.*

@org.springframework.stereotype.Repository
interface RoutineNativeRepository : Repository<RoutineJpaEntity, Long?> {

@Query(
value = "SELECT * FROM ${TableNames.ROUTINE_TABLE} r " +
"INNER JOIN ${TableNames.ROUTINE_TABLE}_day_of_weeks d " +
"ON r.id = d.${TableNames.ROUTINE_TABLE}_id " +
"WHERE r.is_archived = false AND r.user_id = :userId AND d.day_of_weeks LIKE :dayOfWeek",
nativeQuery = true
)
fun findByUserIdAndDayOfWeekAndIsArchivedFalse(
@Param("userId") userId: UUID,
@Param("dayOfWeek") dayOfWeek: String
): RoutineJpaEntity?
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ package com.info.maeumgagym.domain.routine.repository

import com.info.maeumgagym.domain.routine.entity.RoutineJpaEntity
import org.springframework.data.repository.Repository
import java.util.UUID
import java.util.*

@org.springframework.stereotype.Repository
interface RoutineRepository : Repository<RoutineJpaEntity, Long> {
fun save(entity: RoutineJpaEntity): RoutineJpaEntity

fun findAllByUserId(userId: UUID): List<RoutineJpaEntity>
fun findById(id: Long): RoutineJpaEntity?

fun save(entity: RoutineJpaEntity): RoutineJpaEntity
fun findAllByUserId(userId: UUID): List<RoutineJpaEntity>

fun delete(entity: RoutineJpaEntity)

fun findById(id: Long): RoutineJpaEntity?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.info.maeumgagym.domain.step

import com.info.common.PersistenceAdapter
import com.info.maeumgagym.domain.step.mapper.StepMapper
import com.info.maeumgagym.domain.step.repository.StepRepository
import com.info.maeumgagym.step.model.Step
import com.info.maeumgagym.step.port.out.ReadStepPort
import com.info.maeumgagym.step.port.out.SaveStepPort
import org.springframework.transaction.annotation.Propagation
import org.springframework.transaction.annotation.Transactional

@PersistenceAdapter
internal class StepPersistenceAdapter(
private val stepRepository: StepRepository,
private val stepMapper: StepMapper
) : SaveStepPort, ReadStepPort {
override fun readByUserOauthId(oauthId: String): Step? =
stepRepository.findById(oauthId)?.let { stepMapper.toDomain(it) }

@Transactional(propagation = Propagation.MANDATORY)
override fun save(step: Step): Step = stepMapper.toDomain(stepRepository.save(stepMapper.toEntity(step)))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.info.maeumgagym.domain.step.entity

import com.info.maeumgagym.TableNames
import org.springframework.data.annotation.Id
import org.springframework.data.redis.core.RedisHash
import org.springframework.data.redis.core.TimeToLive

@RedisHash(value = TableNames.REDIS_STEP_TABLE)
class StepRedisEntity(
id: String,
numberOfSteps: Int,
ttl: Long
) {
@Id
var id: String = id
protected set

var numberOfSteps: Int = numberOfSteps
protected set

@TimeToLive
var ttl: Long = ttl
protected set
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.info.maeumgagym.domain.step.mapper

import com.info.maeumgagym.domain.step.entity.StepRedisEntity
import com.info.maeumgagym.step.model.Step
import org.springframework.stereotype.Component

@Component
class StepMapper {
fun toEntity(domain: Step): StepRedisEntity = domain.run {
StepRedisEntity(
id = id,
numberOfSteps = numberOfSteps,
ttl = ttl
)
}

fun toDomain(entity: StepRedisEntity): Step = entity.run {
Step(
id = id,
numberOfSteps = numberOfSteps,
ttl = ttl
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.info.maeumgagym.domain.step.repository

import com.info.maeumgagym.domain.step.entity.StepRedisEntity
import org.springframework.data.repository.Repository
@org.springframework.stereotype.Repository
interface StepRepository : Repository<StepRedisEntity, String> {
fun save(entity: StepRedisEntity): StepRedisEntity

fun findById(id: String): StepRedisEntity?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.info.common

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

@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS)
@MustBeDocumented
@Transactional(readOnly = true)
@Service
annotation class ReadOnlyUseCase()
3 changes: 3 additions & 0 deletions maeumgagym-common/src/main/kotlin/com/info/common/UseCase.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.info.common

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

@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS)
@MustBeDocumented
@Transactional(isolation = Isolation.REPEATABLE_READ, rollbackFor = [Exception::class])
@Service
annotation class UseCase()
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ import com.info.maeumgagym.user.model.User
import com.info.maeumgagym.user.port.out.ExistUserPort
import com.info.maeumgagym.user.port.out.RecoveryUserPort
import com.info.maeumgagym.user.port.out.SaveUserPort
import org.springframework.transaction.annotation.Isolation
import org.springframework.transaction.annotation.Transactional

@UseCase
@Transactional(isolation = Isolation.REPEATABLE_READ, rollbackFor = [Exception::class])
internal class AppleOAuthService(
private val saveUserPort: SaveUserPort,
private val generateJwtPort: GenerateJwtPort,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.info.maeumgagym.auth.service

import com.info.common.UseCase
import com.info.common.ReadOnlyUseCase
import com.info.maeumgagym.auth.port.`in`.DuplicatedNicknameCheckUseCase
import com.info.maeumgagym.user.port.out.ExistUserPort

@UseCase
@ReadOnlyUseCase
internal class DuplicatedCheckService(
private val existUserPort: ExistUserPort
) : DuplicatedNicknameCheckUseCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@ package com.info.maeumgagym.auth.service

import com.info.common.UseCase
import com.info.maeumgagym.auth.exception.AlreadyExistUserException
import com.info.maeumgagym.user.exception.DuplicatedNicknameException
import com.info.maeumgagym.user.exception.UserNotFoundException
import com.info.maeumgagym.auth.port.`in`.GoogleLoginUseCase
import com.info.maeumgagym.auth.port.`in`.GoogleRecoveryUseCase
import com.info.maeumgagym.auth.port.`in`.GoogleSignupUseCase
import com.info.maeumgagym.auth.port.out.GenerateJwtPort
import com.info.maeumgagym.auth.port.out.GetGoogleInfoPort
import com.info.maeumgagym.auth.port.out.RevokeGoogleTokenPort
import com.info.maeumgagym.user.exception.DuplicatedNicknameException
import com.info.maeumgagym.user.exception.UserNotFoundException
import com.info.maeumgagym.user.model.Role
import com.info.maeumgagym.user.model.User
import com.info.maeumgagym.user.port.out.*
import org.springframework.transaction.annotation.Isolation
import org.springframework.transaction.annotation.Transactional
import com.info.maeumgagym.user.port.out.ExistUserPort
import com.info.maeumgagym.user.port.out.RecoveryUserPort
import com.info.maeumgagym.user.port.out.SaveUserPort

@UseCase
@Transactional(isolation = Isolation.REPEATABLE_READ, rollbackFor = [Exception::class])
internal class GoogleOAuthService(
private val getGoogleInfoPort: GetGoogleInfoPort,
private val saveUserPort: SaveUserPort,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@ package com.info.maeumgagym.auth.service

import com.info.common.UseCase
import com.info.maeumgagym.auth.exception.AlreadyExistUserException
import com.info.maeumgagym.auth.port.`in`.KakaoRecoveryUseCase
import com.info.maeumgagym.user.exception.UserNotFoundException
import com.info.maeumgagym.auth.port.`in`.KakaoLoginUseCase
import com.info.maeumgagym.auth.port.`in`.KakaoRecoveryUseCase
import com.info.maeumgagym.auth.port.`in`.KakaoSignupUseCase
import com.info.maeumgagym.auth.port.out.GenerateJwtPort
import com.info.maeumgagym.auth.port.out.GetKakaoInfoPort
import com.info.maeumgagym.user.exception.DuplicatedNicknameException
import com.info.maeumgagym.user.exception.UserNotFoundException
import com.info.maeumgagym.user.model.Role
import com.info.maeumgagym.user.model.User
import com.info.maeumgagym.user.port.out.*
import org.springframework.transaction.annotation.Isolation
import org.springframework.transaction.annotation.Transactional
import com.info.maeumgagym.user.port.out.ExistUserPort
import com.info.maeumgagym.user.port.out.RecoveryUserPort
import com.info.maeumgagym.user.port.out.SaveUserPort

@UseCase
@Transactional(isolation = Isolation.REPEATABLE_READ, rollbackFor = [Exception::class])
internal class KakaoOAuthService(
private val getKakaoInfoPort: GetKakaoInfoPort,
private val generateJwtPort: GenerateJwtPort,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ package com.info.maeumgagym.auth.service
import com.info.common.UseCase
import com.info.maeumgagym.auth.port.`in`.ReissueUseCase
import com.info.maeumgagym.auth.port.out.ReissuePort
import org.springframework.transaction.annotation.Isolation
import org.springframework.transaction.annotation.Transactional

@UseCase
@Transactional(isolation = Isolation.REPEATABLE_READ, rollbackFor = [Exception::class])
internal class ReissueService(
private val reissuePort: ReissuePort
) : ReissueUseCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import com.info.maeumgagym.auth.port.`in`.WithdrawalUserUseCase
import com.info.maeumgagym.auth.port.out.ReadCurrentUserPort
import com.info.maeumgagym.auth.port.out.RevokeTokensPort
import com.info.maeumgagym.user.port.out.DeleteUserPort
import org.springframework.transaction.annotation.Isolation
import org.springframework.transaction.annotation.Transactional

@UseCase
@Transactional(isolation = Isolation.REPEATABLE_READ, rollbackFor = [Exception::class])
internal class WithdrawalUserService(
private val deleteUserPort: DeleteUserPort,
private val readCurrentUserPort: ReadCurrentUserPort,
Expand Down
Loading

0 comments on commit 148b6aa

Please sign in to comment.