-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
621 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 6 additions & 3 deletions
9
src/main/kotlin/backend/itracker/tracker/config/ArgumentResolverConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/kotlin/backend/itracker/tracker/infra/oauth/kakao/KakaoMemberClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/kotlin/backend/itracker/tracker/infra/oauth/kakao/dto/KakaoMemberResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/kotlin/backend/itracker/tracker/member/controller/FavoriteController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/backend/itracker/tracker/member/controller/request/FavoritePatchRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
) | ||
} | ||
} | ||
|
2 changes: 1 addition & 1 deletion
2
src/main/kotlin/backend/itracker/tracker/member/controller/response/MyInfoResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/backend/itracker/tracker/member/domain/AuthType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
32
src/main/kotlin/backend/itracker/tracker/member/domain/Favorite.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
20 changes: 20 additions & 0 deletions
20
src/main/kotlin/backend/itracker/tracker/member/domain/FavoriteProduct.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/kotlin/backend/itracker/tracker/member/domain/repository/FavoriteRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
Oops, something went wrong.