Skip to content

Commit

Permalink
remove duplicated dto and other minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
angelodpadron committed Nov 24, 2024
1 parent cdf373a commit 3890bc4
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.meliapp.backend.controller

import org.meliapp.backend.dto.ApiResponse
import org.meliapp.backend.dto.management.BookmarkBasicResume
import org.meliapp.backend.dto.management.UserBasicResume
import org.meliapp.backend.dto.management.top.ProductBookmarkCount
import org.meliapp.backend.dto.management.top.ProductSaleCount
Expand All @@ -23,7 +22,7 @@ class AdminController(
ResponseEntity.ok(ApiResponse(adminService.getRegisteredUsers()))

@GetMapping("/bookmarked-products")
fun getBookmarkedProducts(): ResponseEntity<ApiResponse<List<BookmarkBasicResume>>> =
fun getBookmarkedProducts(): ResponseEntity<ApiResponse<List<ProductBookmarkCount>>> =
ResponseEntity.ok(ApiResponse(adminService.getBookmarkedProducts()))

@GetMapping("/top-five-bookmarked")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty
import java.time.LocalDateTime

data class UserBasicResume(
val id: Long,
val email: String,
@JsonProperty("created_at")
val createdAt: LocalDateTime
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.meliapp.backend.repository

import org.meliapp.backend.dto.management.BookmarkBasicResume
import org.meliapp.backend.dto.management.top.ProductBookmarkCount
import org.meliapp.backend.model.Bookmark
import org.springframework.data.domain.Pageable
Expand All @@ -26,10 +25,10 @@ interface BookmarkRepository : JpaRepository<Bookmark, Long> {
fun getMostBookmarked(pageable: Pageable): List<ProductBookmarkCount>

@Query("""
SELECT new org.meliapp.backend.dto.management.BookmarkBasicResume(p.meliId, p.title, COUNT(p))
SELECT new org.meliapp.backend.dto.management.top.ProductBookmarkCount(p.meliId, p.title, COUNT(p))
FROM Bookmark b JOIN b.product p
GROUP BY p.meliId, p.title
ORDER BY p.title DESC
""")
fun getBookmarksBasicResume(): List<BookmarkBasicResume>
fun getBookmarksBasicResume(): List<ProductBookmarkCount>
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface UserRepository : JpaRepository<User, Long> {
fun existsByEmail(email: String): Boolean

@Query("""
SELECT new org.meliapp.backend.dto.management.UserBasicResume(u.email, u.createdAt)
SELECT new org.meliapp.backend.dto.management.UserBasicResume(u.id, u.email, u.createdAt)
FROM User u INNER JOIN u.roles r
WHERE r.name = 'ROLE_USER'
""")
Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/org/meliapp/backend/service/AdminService.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.meliapp.backend.service

import org.meliapp.backend.dto.management.BookmarkBasicResume
import org.meliapp.backend.dto.management.UserBasicResume
import org.meliapp.backend.dto.management.top.ProductBookmarkCount
import org.meliapp.backend.dto.management.top.ProductSaleCount
Expand Down Expand Up @@ -32,6 +31,6 @@ class AdminService(
fun top5Buyers(): List<UserPurchaseCount> =
purchaseRepository.getTopBuyers(pageRequest)

fun getBookmarkedProducts(): List<BookmarkBasicResume> =
fun getBookmarkedProducts(): List<ProductBookmarkCount> =
bookmarkRepository.getBookmarksBasicResume()
}

0 comments on commit 3890bc4

Please sign in to comment.