Skip to content

Commit

Permalink
6/19 배포 작업 (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
cookienc authored Jun 19, 2024
1 parent 623ce52 commit 9eada97
Show file tree
Hide file tree
Showing 50 changed files with 281 additions and 181 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/db_backup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: db_backup

on:
schedule:
- cron: '0 3 * * *'

jobs:
cron:
runs-on: [self-hosted, Linux, prod]

steps:
- name: Execute Backup Script
run: ~/backend/db/backup_cron.sh
2 changes: 1 addition & 1 deletion secrets
4 changes: 4 additions & 0 deletions src/main/kotlin/backend/itracker/crawl/common/BaseEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ abstract class BaseEntity(
override fun hashCode(): Int {
return id.hashCode()
}

override fun toString(): String {
return "BaseEntity(id=$id, createdAt=$createdAt, updatedAt=$updatedAt)"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package backend.itracker.crawl.macbook.service.dto

import backend.itracker.tracker.service.response.filter.CommonFilterModel
import backend.itracker.tracker.product.response.filter.CommonFilterModel

data class MacbookFilterCondition(
val size: Int?,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package backend.itracker.config
package backend.itracker.schedule.config

import org.springframework.scheduling.annotation.EnableScheduling
import org.springframework.stereotype.Component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package backend.itracker.tracker.controller.converter
package backend.itracker.tracker.common.converter

import backend.itracker.tracker.oauth.OauthServerType
import org.springframework.core.convert.converter.Converter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package backend.itracker.tracker.controller.converter
package backend.itracker.tracker.common.converter

import backend.itracker.crawl.common.ProductCategory
import org.springframework.core.convert.converter.Converter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package backend.itracker.tracker.controller.request
package backend.itracker.tracker.common.request

private const val DEFAULT_PAGE_SIZE = 10

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package backend.itracker.tracker.controller.response
package backend.itracker.tracker.common.response

import org.springframework.data.domain.Page

Expand All @@ -18,7 +18,7 @@ data class Pages<T>(

}

data class SinglePage<T>(
data class SingleData<T>(
val data: T
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package backend.itracker.tracker.config

import backend.itracker.tracker.resolver.OauthArgumentResolver
import org.springframework.context.annotation.Configuration
import org.springframework.web.method.support.HandlerMethodArgumentResolver
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer

@Configuration
class ArgumentResolverConfig(
private val oauthArgumentResolver: OauthArgumentResolver
) : WebMvcConfigurer {

override fun addArgumentResolvers(resolvers: MutableList<HandlerMethodArgumentResolver>) {
resolvers.add(oauthArgumentResolver)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package backend.itracker.config
package backend.itracker.tracker.config

import com.querydsl.jpa.impl.JPAQueryFactory
import jakarta.persistence.EntityManager
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package backend.itracker.tracker.config

import backend.itracker.tracker.controller.converter.OauthServerTypeConverter
import backend.itracker.tracker.controller.converter.ProductCategoryConverter
import backend.itracker.tracker.common.converter.OauthServerTypeConverter
import backend.itracker.tracker.common.converter.ProductCategoryConverter
import org.springframework.context.annotation.Configuration
import org.springframework.format.FormatterRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package backend.itracker.tracker.service.service
package backend.itracker.tracker.coupang.client

import backend.itracker.tracker.service.common.HmacGenerator
import backend.itracker.tracker.service.request.DeepLinkRequest
import backend.itracker.tracker.service.response.CoupangDeepLinkResponse
import backend.itracker.tracker.service.response.Deeplink
import backend.itracker.tracker.coupang.common.HmacGenerator
import backend.itracker.tracker.coupang.request.DeepLinkRequest
import backend.itracker.tracker.coupang.response.CoupangDeepLinkResponse
import backend.itracker.tracker.coupang.response.Deeplink
import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.beans.factory.annotation.Value
import org.springframework.http.HttpEntity
Expand All @@ -21,6 +21,7 @@ private const val AUTHORIZATION = "Authorization"
private const val CONTENT_TYPE = "Content-Type"
private const val CONTENT_ENCODING = "Content-Encoding"


@Service
class CoupangApiClient(
val hmacGenerator: HmacGenerator,
Expand Down Expand Up @@ -51,4 +52,3 @@ class CoupangApiClient(
)
}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package backend.itracker.tracker.service.common
package backend.itracker.tracker.coupang.common

import org.springframework.stereotype.Component
import java.security.GeneralSecurityException
Expand All @@ -7,6 +7,7 @@ import java.util.*
import javax.crypto.Mac
import javax.crypto.spec.SecretKeySpec


private const val SECRET_ALGORITHM = "HmacSHA256"
private const val DATE_FORMAT = "yyMMdd'T'HHmmss'Z'"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package backend.itracker.tracker.controller
package backend.itracker.tracker.coupang.controller

import backend.itracker.crawl.airpods.service.AirPodsService
import backend.itracker.crawl.common.PartnersLinkInfo
import backend.itracker.crawl.common.ProductCategory
import backend.itracker.crawl.macbook.service.MacbookService
import backend.itracker.tracker.service.service.CoupangPartnersService
import backend.itracker.tracker.coupang.service.CoupangPartnersService
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.PatchMapping
import org.springframework.web.bind.annotation.PathVariable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package backend.itracker.tracker.service.request
package backend.itracker.tracker.coupang.request

data class DeepLinkRequest(
val coupangUrls: List<String>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package backend.itracker.tracker.service.response
package backend.itracker.tracker.coupang.response

data class CoupangDeepLinkResponse(
val rCode: Int,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package backend.itracker.tracker.service.service
package backend.itracker.tracker.coupang.service

import backend.itracker.crawl.airpods.service.AirPodsService
import backend.itracker.crawl.macbook.service.MacbookService
import backend.itracker.tracker.service.response.Deeplink
import backend.itracker.tracker.coupang.client.CoupangApiClient
import backend.itracker.tracker.coupang.response.Deeplink
import org.springframework.stereotype.Service

private const val MAX_REQUEST_SIZE = 20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package backend.itracker.tracker.infra.oauth.jwt

import backend.itracker.tracker.infra.oauth.AuthorizationHeader
import backend.itracker.tracker.infra.oauth.exception.OauthRequestException
import io.jsonwebtoken.Claims
import backend.itracker.tracker.oauth.OauthId
import backend.itracker.tracker.oauth.OauthServerType
import io.jsonwebtoken.ExpiredJwtException
import io.jsonwebtoken.IncorrectClaimException
import io.jsonwebtoken.JwtParser
Expand All @@ -22,11 +23,12 @@ class JwtDecoder(
.requireIssuer(jwtConfig.issuer)
.build()

fun parseAuthorizationHeader(authorizationHeader: AuthorizationHeader): Claims {
fun parseOauthId(authorizationHeader: AuthorizationHeader): OauthId {
try {
val token: String = authorizationHeader.parseHeader()

return jwtParser.parseClaimsJws(token).body
val claims = jwtParser.parseClaimsJws(token).body
return OauthId(claims["serverId"].toString(), OauthServerType.from(claims["type"].toString()))
} catch (e: SignatureException) {
throw OauthRequestException("Signature 가 잘못되었습니다.")
} catch (e: ExpiredJwtException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ data class KakaoMemberResponse(
fun toDomain(): Member {
return Member(
oauthId = OauthId(id.toString(), OauthServerType.KAKAO),
nickname = kakaoAccount.profile.nickname
nickname = kakaoAccount.profile.nickname,
profileImage = kakaoAccount.profile.profileImageUrl,
)
}

Expand Down Expand Up @@ -54,7 +55,7 @@ data class KakaoMemberResponse(
data class Profile(
val nickname: String,
val thumbnailImageUrl: String?,
val profileImageUrl: String?,
val profileImageUrl: String,
val isDefaultImage: Boolean?
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package backend.itracker.tracker.member.controller

import backend.itracker.tracker.common.response.SingleData
import backend.itracker.tracker.member.controller.response.MyInfoResponse
import backend.itracker.tracker.oauth.Member
import backend.itracker.tracker.resolver.LoginMember
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController

@RestController
class MemberController {

@GetMapping("/api/v1/me")
fun getMyInfo(@LoginMember member: Member): ResponseEntity<SingleData<MyInfoResponse>> {
return ResponseEntity.ok(SingleData(MyInfoResponse.from(member)))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package backend.itracker.tracker.member.controller.response

import backend.itracker.tracker.oauth.Member

data class MyInfoResponse(
val id: Long,
val nickname: String,
val image: String,
) {

companion object {
fun from(member: Member): MyInfoResponse {
return MyInfoResponse(
id = member.id,
nickname = member.nickname,
image = member.profileImage
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package backend.itracker.tracker.member.service

import backend.itracker.tracker.oauth.Member
import backend.itracker.tracker.oauth.OauthId
import backend.itracker.tracker.oauth.repository.MemberRepository
import backend.itracker.tracker.oauth.repository.getByOauthId
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.util.*

@Transactional
@Service
class MemberService(
private val memberRepository: MemberRepository
) {

fun save(member: Member): Member {
return memberRepository.save(member)
}

fun updateProfile(oauthId: OauthId, target: Member) {
val findMember = memberRepository.getByOauthId(oauthId)
findMember.updateProfile(target)
}

@Transactional(readOnly = true)
fun findByOauthId(oauthId: OauthId): Optional<Member> {
return memberRepository.findByOauthId(oauthId)
}

@Transactional(readOnly = true)
fun getByOauthId(oauthId: OauthId): Member {
return memberRepository.getByOauthId(oauthId)
}
}
13 changes: 11 additions & 2 deletions src/main/kotlin/backend/itracker/tracker/oauth/Member.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package backend.itracker.tracker.oauth

import backend.itracker.crawl.common.BaseEntity
import jakarta.persistence.Column
import jakarta.persistence.Embedded
import jakarta.persistence.Entity
import jakarta.persistence.EnumType
Expand All @@ -20,15 +21,23 @@ class Member(
@Embedded
val oauthId: OauthId,

val nickname: String,
var nickname: String,

@Column(columnDefinition = "text")
var profileImage: String,

@Enumerated(EnumType.STRING)
val authType: AuthType = AuthType.USER,

id: Long = 0L
) : BaseEntity(id) {

fun updateProfile(target: Member) {
this.nickname = target.nickname
this.profileImage = target.profileImage
}

override fun toString(): String {
return "Member(oauthId=$oauthId, nickname='$nickname', authType=$authType)"
return "Member(id='$id' oauthId=$oauthId, nickname='$nickname', profileImage='$profileImage', authType=$authType)"
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package backend.itracker.tracker.controller
package backend.itracker.tracker.oauth.controller

import backend.itracker.tracker.oauth.OauthServerType
import backend.itracker.tracker.oauth.RedirectType
import backend.itracker.tracker.service.oauth.OauthService
import backend.itracker.tracker.oauth.service.OauthService
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
import org.springframework.http.HttpHeaders
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import backend.itracker.tracker.oauth.Member
import backend.itracker.tracker.oauth.OauthId
import org.springframework.data.jpa.repository.JpaRepository
import java.util.*
import kotlin.jvm.optionals.getOrNull

fun MemberRepository.getByOauthId(oauthId: OauthId) = findByOauthId(oauthId).getOrNull()
?: throw NoSuchElementException("회원을 찾을 수 없습니다. oauthId: $oauthId")

interface MemberRepository : JpaRepository<Member, Long> {

Expand Down
Loading

0 comments on commit 9eada97

Please sign in to comment.