Skip to content

Commit

Permalink
6/21 배포 작업 (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
cookienc authored Jun 21, 2024
1 parent 8afa9d4 commit 41e7240
Show file tree
Hide file tree
Showing 44 changed files with 621 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface AirPodsRepository : JpaRepository<AirPods, Long> {
"""
select a
from AirPods a
join fetch a.prices.airPodsPrices
left join fetch a.prices.airPodsPrices
where a.coupangId = :coupangId
"""
)
Expand All @@ -27,7 +27,7 @@ interface AirPodsRepository : JpaRepository<AirPods, Long> {
"""
select a
from AirPods a
join fetch a.prices.airPodsPrices
left join fetch a.prices.airPodsPrices
"""
)
fun findAllFetch(): List<AirPods>
Expand All @@ -36,11 +36,21 @@ interface AirPodsRepository : JpaRepository<AirPods, Long> {
"""
select a
from AirPods a
join fetch a.prices.airPodsPrices
left join fetch a.prices.airPodsPrices
where a.id = :id
"""
)
fun findByIdAllFetch(@Param("id") id: Long): Optional<AirPods>

fun findByIdBetween(startId: Long, endId: Long): List<AirPods>

@Query(
"""
select a
from AirPods a
left join fetch a.prices.airPodsPrices
where a.id in :ids
"""
)
fun findAllInIds(@Param("ids") ids: List<Long>): List<AirPods>
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ class AirPodsService(
fun findByIdBetween(startId: Long, endId: Long): List<AirPods> {
return airPodsRepository.findByIdBetween(startId, endId)
}

@Transactional(readOnly = true)
fun findAllInIds(ids: List<Long>): List<AirPods> {
return airPodsRepository.findAllInIds(ids)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,14 @@ interface MacbookRepository: JpaRepository<Macbook, Long>, MacbookRepositoryCust
fun findAllPricesByMacbookId(@Param("id") id: Long): Optional<Macbook>

fun findByIdBetween(startId: Long, endId: Long): List<Macbook>

@Query(
"""
select m
from Macbook m
left join fetch m.prices.macbookPrices
where m.id in :ids
"""
)
fun findAllInIds(@Param("ids") ids: List<Long>): List<Macbook>
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,9 @@ class MacbookService(
fun findByIdBetween(startId: Long, endId: Long): List<Macbook> {
return macbookRepository.findByIdBetween(startId, endId)
}

@Transactional(readOnly = true)
fun findAllInIds(ids: List<Long>): List<Macbook> {
return macbookRepository.findAllInIds(ids)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ package backend.itracker.crawl.service.mapper.ipad
import backend.itracker.crawl.exception.CrawlException
import backend.itracker.crawl.ipad.domain.Ipad
import backend.itracker.crawl.service.vo.DefaultProduct
import io.github.oshai.kotlinlogging.KotlinLogging
import org.springframework.stereotype.Component

private val logger = KotlinLogging.logger {}

@Component
class IpadMappers(
private val ipadMappers: List<IpadMappingComponent>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package backend.itracker.tracker.config

import backend.itracker.tracker.resolver.OauthArgumentResolver
import backend.itracker.tracker.resolver.AnonymousMemberArgumentResolver
import backend.itracker.tracker.resolver.LoginMemberArgumentResolver
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
private val loginMemberArgumentResolver: LoginMemberArgumentResolver,
private val anonymousMemberArgumentResolver: AnonymousMemberArgumentResolver,
) : WebMvcConfigurer {

override fun addArgumentResolvers(resolvers: MutableList<HandlerMethodArgumentResolver>) {
resolvers.add(oauthArgumentResolver)
resolvers.add(loginMemberArgumentResolver)
resolvers.add(anonymousMemberArgumentResolver)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package backend.itracker.tracker.infra.oauth.kakao

import backend.itracker.tracker.infra.oauth.kakao.client.KakaoApiClient
import backend.itracker.tracker.oauth.Member
import backend.itracker.tracker.member.domain.Member
import backend.itracker.tracker.oauth.OauthServerType
import backend.itracker.tracker.oauth.RedirectType
import backend.itracker.tracker.oauth.client.OauthMemberClient
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package backend.itracker.tracker.infra.oauth.kakao.dto

import backend.itracker.tracker.oauth.Member
import backend.itracker.tracker.member.domain.Member
import backend.itracker.tracker.oauth.OauthId
import backend.itracker.tracker.oauth.OauthServerType
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package backend.itracker.tracker.member.controller

import backend.itracker.tracker.common.request.PageParams
import backend.itracker.tracker.common.response.Pages
import backend.itracker.tracker.member.controller.request.FavoritePatchRequest
import backend.itracker.tracker.member.domain.Favorite
import backend.itracker.tracker.member.domain.FavoriteProduct
import backend.itracker.tracker.member.domain.Member
import backend.itracker.tracker.member.service.FavoriteService
import backend.itracker.tracker.member.service.handler.response.CommonFavoriteProductModel
import backend.itracker.tracker.resolver.LoginMember
import org.springframework.data.domain.PageRequest
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.ModelAttribute
import org.springframework.web.bind.annotation.PatchMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RestController

private const val FAVORITE_DEFAULT_SIZE = 6

@RestController
class FavoriteController(
private val favoriteService: FavoriteService
) {

@PatchMapping("/api/v1/favorites")
fun patchFavorites(
@LoginMember member: Member,
@RequestBody request: FavoritePatchRequest
): ResponseEntity<Unit> {
val favoriteInfo = request.toFavoriteInfo()
val favorite = Favorite(
member = member,
product = FavoriteProduct(productId = favoriteInfo.productId, productCategory = favoriteInfo.category)
)
favoriteService.patchFavorite(favorite)

return ResponseEntity.noContent().build()
}

@GetMapping("/api/v1/favorites")
fun findAllFavorites(
@LoginMember member: Member,
@ModelAttribute pageParams: PageParams,
): ResponseEntity<Pages<CommonFavoriteProductModel>> {
val favorites = favoriteService.findAllFavoritesByMember(
member, PageRequest.of(pageParams.offset, FAVORITE_DEFAULT_SIZE)
)

return ResponseEntity.ok(Pages.withPagination(favorites))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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.member.domain.Member
import backend.itracker.tracker.resolver.LoginMember
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package backend.itracker.tracker.member.controller.request

import backend.itracker.crawl.common.ProductCategory
import backend.itracker.tracker.member.service.vo.FavoriteInfo

data class FavoritePatchRequest(
val productId: Long,
val productCategory: String
) {

fun toFavoriteInfo() : FavoriteInfo
{
return FavoriteInfo(
productId = productId,
category = ProductCategory.valueOf(productCategory.uppercase())
)
}
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package backend.itracker.tracker.member.controller.response

import backend.itracker.tracker.oauth.Member
import backend.itracker.tracker.member.domain.Member

data class MyInfoResponse(
val id: Long,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package backend.itracker.tracker.member.domain

enum class AuthType {
USER, ADMIN;
}
32 changes: 32 additions & 0 deletions src/main/kotlin/backend/itracker/tracker/member/domain/Favorite.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package backend.itracker.tracker.member.domain

import backend.itracker.crawl.common.BaseEntity
import jakarta.persistence.Embedded
import jakarta.persistence.Entity
import jakarta.persistence.FetchType
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table
import jakarta.persistence.UniqueConstraint

@Entity
@Table(
name = "favorite",
uniqueConstraints = [
UniqueConstraint(
name = "favorite_product_unique",
columnNames = ["member_id", "product_id", "product_category"]
)
]
)
class Favorite(

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
val member: Member,

@Embedded
val product: FavoriteProduct,

id: Long = 0
) : BaseEntity(id)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package backend.itracker.tracker.member.domain

import backend.itracker.crawl.common.ProductCategory
import jakarta.persistence.Embeddable
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated

@Embeddable
class FavoriteProduct(

val productId: Long,

@Enumerated(EnumType.STRING)
val productCategory: ProductCategory,
) {

override fun toString(): String {
return "FavoriteProduct(productId=$productId, productCategory=$productCategory)"
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package backend.itracker.tracker.oauth
package backend.itracker.tracker.member.domain

import backend.itracker.crawl.common.BaseEntity
import backend.itracker.tracker.oauth.OauthId
import backend.itracker.tracker.oauth.OauthServerType
import jakarta.persistence.Column
import jakarta.persistence.Embedded
import jakarta.persistence.Entity
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
import jakarta.persistence.FetchType
import jakarta.persistence.OneToMany
import jakarta.persistence.Table
import jakarta.persistence.UniqueConstraint

Expand All @@ -29,6 +33,9 @@ class Member(
@Enumerated(EnumType.STRING)
val authType: AuthType = AuthType.USER,

@OneToMany(fetch = FetchType.LAZY, mappedBy = "member")
val favorites: List<Favorite> = mutableListOf(),

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

Expand All @@ -37,7 +44,17 @@ class Member(
this.profileImage = target.profileImage
}

fun isAnonymous() = this.id == 0L

override fun toString(): String {
return "Member(id='$id' oauthId=$oauthId, nickname='$nickname', profileImage='$profileImage', authType=$authType)"
}

companion object {
fun anonymous() = Member(
oauthId = OauthId("anonymous", OauthServerType.KAKAO),
nickname = "익명",
profileImage = "익명",
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package backend.itracker.tracker.member.domain.repository

import backend.itracker.tracker.member.domain.Favorite
import backend.itracker.tracker.member.domain.FavoriteProduct
import backend.itracker.tracker.member.domain.Member
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param
import java.util.*

interface FavoriteRepository : JpaRepository<Favorite, Long> {

@Query(
"""
select f
from Favorite f
where f.member.id = :memberId
and f.product = :product
"""
)
fun findByFavorite(
@Param("memberId") memberId: Long,
@Param("product") product: FavoriteProduct,
): Optional<Favorite>

fun findAllByMember(member: Member, pageable: Pageable): Page<Favorite>
}
Loading

0 comments on commit 41e7240

Please sign in to comment.