Skip to content

Commit

Permalink
Merge branch 'main' into feat/chat
Browse files Browse the repository at this point in the history
  • Loading branch information
ws11222 authored Feb 2, 2025
2 parents e8b6ef0 + abe06ae commit 556ded8
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ class ArticleController(

@GetMapping("/item/search/{articleId}")
fun searchArticles(
@RequestBody request: SearchRequest,
@PathVariable articleId: Long,
@RequestParam("text") text: String,
@AuthUser user: User,
): ResponseEntity<List<Item>> {
val articles = articleService.searchArticle(request, articleId)
val articles = articleService.searchArticle(text, articleId)
val response: List<Item> =
articles.map { article ->
Item.fromArticle(Article.fromEntity(article), articleService.getChattingUsersByArticle(Article.fromEntity(article)).size)
Expand Down Expand Up @@ -175,10 +175,6 @@ data class UpdateStatusRequest(
val status: Int,
)

data class SearchRequest(
val text: String,
)

data class ArticleResponse(
val article: Article,
val chattingUsers: List<User>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.toyProject7.karrot.article.ArticleNotFoundException
import com.toyProject7.karrot.article.ArticlePermissionDeniedException
import com.toyProject7.karrot.article.controller.Article
import com.toyProject7.karrot.article.controller.PostArticleRequest
import com.toyProject7.karrot.article.controller.SearchRequest
import com.toyProject7.karrot.article.controller.UpdateStatusRequest
import com.toyProject7.karrot.article.persistence.ArticleEntity
import com.toyProject7.karrot.article.persistence.ArticleLikesEntity
Expand Down Expand Up @@ -254,10 +253,9 @@ class ArticleService(

@Transactional
fun searchArticle(
request: SearchRequest,
text: String,
articleId: Long,
): List<ArticleEntity> {
val text = request.text
val articles =
articleRepository.findTop10ByTitleContainingIgnoreCaseOrContentContainingIgnoreCaseAndIdLessThanOrderByIdDesc(
text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class AuctionService(
return auctionRepository.findByIdOrNull(auctionId) ?: throw AuctionNotFoundException()
}

@Scheduled(fixedRate = 60000) // Run every minute
@Scheduled(fixedRate = 10000)
fun checkAndEndAuctions() {
val now = Instant.now()
val endedAuctions = auctionRepository.findByEndTimeBeforeAndStatus(now, 0)
Expand Down Expand Up @@ -237,10 +237,12 @@ class AuctionService(
isDummy = 1,
)
articleRepository.save(articleEntity)
chatRoomService.createChatRoom(
articleEntity.id ?: throw IllegalArgumentException("Article ID cannot be null"),
articleEntity.seller.id ?: throw IllegalArgumentException("Seller ID cannot be null"),
articleEntity.buyer?.id ?: throw IllegalArgumentException("Buyer ID cannot be null"),
)
if (auction.seller.id != auction.bidder?.id) {
chatRoomService.createChatRoom(
articleEntity.id ?: throw IllegalArgumentException("Article ID cannot be null"),
articleEntity.seller.id ?: throw IllegalArgumentException("Seller ID cannot be null"),
articleEntity.buyer?.id ?: throw IllegalArgumentException("Buyer ID cannot be null"),
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ class CommentService(
if (comment.user.id != user.id) {
throw CommentWriterDoesNotMatchException()
}
comment.feed.content = request.content
comment.content = request.content
comment.updatedAt = Instant.now()
commentRepository.save(comment)
feedService.saveCommentInFeed(comment.feed, comment)
return Comment.fromEntity(comment)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ class FeedController(

@GetMapping("/feed/search/{feedId}")
fun searchFeeds(
@RequestBody request: SearchRequest,
@PathVariable feedId: Long,
@RequestParam("text") text: String,
@AuthUser user: User,
): ResponseEntity<List<FeedPreview>> {
val feeds = feedService.searchFeed(request, feedId)
val feeds = feedService.searchFeed(text, feedId)
val response: List<FeedPreview> =
feeds.map { feed ->
FeedPreview.fromEntity(feed)
Expand All @@ -159,7 +159,3 @@ data class PostFeedRequest(
val tag: String,
val imageCount: Int,
)

data class SearchRequest(
val text: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.toyProject7.karrot.feed.FeedNotFoundException
import com.toyProject7.karrot.feed.FeedPermissionDeniedException
import com.toyProject7.karrot.feed.controller.Feed
import com.toyProject7.karrot.feed.controller.PostFeedRequest
import com.toyProject7.karrot.feed.controller.SearchRequest
import com.toyProject7.karrot.feed.persistence.FeedEntity
import com.toyProject7.karrot.feed.persistence.FeedLikesEntity
import com.toyProject7.karrot.feed.persistence.FeedLikesRepository
Expand Down Expand Up @@ -239,10 +238,9 @@ class FeedService(

@Transactional
fun searchFeed(
request: SearchRequest,
text: String,
feedId: Long,
): List<FeedEntity> {
val text = request.text
val feeds =
feedRepository.findTop10ByTitleContainingIgnoreCaseOrContentContainingIgnoreCaseAndIdLessThanOrderByIdDesc(text, text, feedId)
refreshPresignedUrlIfExpired(feeds)
Expand Down

0 comments on commit 556ded8

Please sign in to comment.