-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat: #93 홈화면 로직 구현
- Loading branch information
Showing
16 changed files
with
253 additions
and
39 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/com/routebox/routebox/application/popular_route/GetPopularRoutesUseCase.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,16 @@ | ||
package com.routebox.routebox.application.popular_route | ||
|
||
import com.routebox.routebox.application.popular_route.dto.PopularRouteDto | ||
import com.routebox.routebox.domain.popular_route.PopularRouteService | ||
import org.springframework.stereotype.Component | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Component | ||
class GetPopularRoutesUseCase( | ||
private val popularRouteService: PopularRouteService, | ||
) { | ||
@Transactional(readOnly = true) | ||
operator fun invoke(): List<PopularRouteDto> { | ||
return popularRouteService.getPopularRoutes() | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/com/routebox/routebox/application/popular_route/dto/PopularRouteDto.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,6 @@ | ||
package com.routebox.routebox.application.popular_route.dto | ||
|
||
data class PopularRouteDto( | ||
val id: Long, | ||
val name: String, | ||
) |
16 changes: 16 additions & 0 deletions
16
...kotlin/com/routebox/routebox/application/recommended_route/GetRecommendedRoutesUseCase.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,16 @@ | ||
package com.routebox.routebox.application.recommended_route | ||
|
||
import com.routebox.routebox.application.recommended_route.dto.RecommendedRouteDto | ||
import com.routebox.routebox.domain.recommended_route.RecommendedRouteService | ||
import org.springframework.stereotype.Component | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Component | ||
class GetRecommendedRoutesUseCase( | ||
private val recommendedRouteService: RecommendedRouteService, | ||
) { | ||
@Transactional(readOnly = true) | ||
operator fun invoke(): List<RecommendedRouteDto> { | ||
return recommendedRouteService.getRecommendRoutes() | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...ain/kotlin/com/routebox/routebox/application/recommended_route/dto/RecommendedRouteDto.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,8 @@ | ||
package com.routebox.routebox.application.recommended_route.dto | ||
data class RecommendedRouteDto( | ||
val id: Long, | ||
val name: String, | ||
val description: String?, | ||
val commonComment: String?, | ||
val routeImageUrl: String?, | ||
) |
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
...ler/route/dto/GetPopularRoutesResponse.kt → ...oute/dto/home/GetPopularRoutesResponse.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
8 changes: 4 additions & 4 deletions
8
...route/dto/GetRecommendedRoutesResponse.kt → .../dto/home/GetRecommendedRoutesResponse.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
...x/controller/route/dto/PopularRouteDto.kt → ...troller/route/dto/home/PopularRouteDto.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
12 changes: 6 additions & 6 deletions
12
...controller/route/dto/RecommendRouteDto.kt → ...ler/route/dto/home/RecommendedRouteDto.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,26 +1,26 @@ | ||
package com.routebox.routebox.controller.route.dto | ||
package com.routebox.routebox.controller.route.dto.home | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema | ||
|
||
data class RecommendRouteDto( | ||
data class RecommendedRouteDto( | ||
@Schema(description = "루트 ID") | ||
val id: Long, | ||
|
||
@Schema(description = "루트 이름") | ||
val routeName: String, | ||
|
||
@Schema(description = "루트 설명") | ||
val routeDescription: String, | ||
val routeDescription: String?, | ||
|
||
@Schema(description = "루트 대표 이미지") | ||
val routeImageUrl: String, | ||
val routeImageUrl: String?, | ||
) { | ||
companion object { | ||
fun from(id: Long, routeName: String, routeDescription: String, routeImageUrl: String): RecommendRouteDto = RecommendRouteDto( | ||
fun from(id: Long, routeName: String, routeDescription: String?, routeImageUrl: String?): RecommendedRouteDto = RecommendedRouteDto( | ||
id = id, | ||
routeName = routeName, | ||
routeDescription = routeDescription, | ||
routeImageUrl = routeImageUrl, | ||
routeImageUrl = if (routeImageUrl.isNullOrEmpty()) null else routeImageUrl, | ||
) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/kotlin/com/routebox/routebox/domain/popular_route/PopularRoute.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,24 @@ | ||
package com.routebox.routebox.domain.popular_route | ||
|
||
import com.routebox.routebox.domain.common.TimeTrackedBaseEntity | ||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.GeneratedValue | ||
import jakarta.persistence.GenerationType | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.Table | ||
|
||
@Table(name = "popular_routes") | ||
@Entity | ||
class PopularRoute( | ||
id: Long = 0, | ||
routeId: Long, | ||
) : TimeTrackedBaseEntity() { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "popular_route_id") | ||
val id: Long = id | ||
|
||
val routeId: Long = routeId | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/kotlin/com/routebox/routebox/domain/popular_route/PopularRouteService.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 com.routebox.routebox.domain.popular_route | ||
|
||
import com.routebox.routebox.application.popular_route.dto.PopularRouteDto | ||
import com.routebox.routebox.infrastructure.popular_route.PopularRouteRepository | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Service | ||
class PopularRouteService( | ||
private val popularRouteRepository: PopularRouteRepository, | ||
) { | ||
|
||
/** | ||
* 인기 루트 조회 | ||
*/ | ||
@Transactional(readOnly = true) | ||
fun getPopularRoutes(): List<PopularRouteDto> { | ||
return popularRouteRepository.findAllPopularRoutes() | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/kotlin/com/routebox/routebox/domain/recommended_route/RecommendedRoute.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,31 @@ | ||
package com.routebox.routebox.domain.recommended_route | ||
|
||
import com.routebox.routebox.domain.common.TimeTrackedBaseEntity | ||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.GeneratedValue | ||
import jakarta.persistence.GenerationType | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.Table | ||
import java.time.LocalDateTime | ||
|
||
@Table(name = "recommended_routes") | ||
@Entity | ||
class RecommendedRoute( | ||
id: Long = 0, | ||
routeId: Long, | ||
showFrom: LocalDateTime, | ||
commonComment: String? = null, | ||
) : TimeTrackedBaseEntity() { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "recommended_route_id") | ||
val id: Long = id | ||
|
||
val routeId: Long = routeId | ||
|
||
val showFrom: LocalDateTime = showFrom | ||
|
||
val commonComment: String? = commonComment | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/kotlin/com/routebox/routebox/domain/recommended_route/RecommendedRouteService.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 com.routebox.routebox.domain.recommended_route | ||
|
||
import com.routebox.routebox.application.recommended_route.dto.RecommendedRouteDto | ||
import com.routebox.routebox.infrastructure.recommended_route.RecommendedRouteRepository | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Service | ||
class RecommendedRouteService( | ||
private val recommendedRouteRepository: RecommendedRouteRepository, | ||
) { | ||
|
||
/** | ||
* 추천 루트 조회 | ||
*/ | ||
@Transactional(readOnly = true) | ||
fun getRecommendRoutes(): List<RecommendedRouteDto> { | ||
return recommendedRouteRepository.findAllRecommendedRoutes() | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/kotlin/com/routebox/routebox/infrastructure/popular_route/PopularRouteRepository.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,18 @@ | ||
package com.routebox.routebox.infrastructure.popular_route | ||
|
||
import com.routebox.routebox.application.popular_route.dto.PopularRouteDto | ||
import com.routebox.routebox.domain.popular_route.PopularRoute | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.data.jpa.repository.Query | ||
|
||
interface PopularRouteRepository : JpaRepository<PopularRoute, Long> { | ||
@Query( | ||
""" | ||
SELECT NEW com.routebox.routebox.application.popular_route.dto.PopularRouteDto(r.id, r.name) | ||
FROM PopularRoute pr | ||
JOIN Route r ON pr.routeId = r.id | ||
WHERE r.isPublic = true | ||
""", | ||
) | ||
fun findAllPopularRoutes(): List<PopularRouteDto> | ||
} |
24 changes: 24 additions & 0 deletions
24
...tlin/com/routebox/routebox/infrastructure/recommended_route/RecommendedRouteRepository.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,24 @@ | ||
package com.routebox.routebox.infrastructure.recommended_route | ||
|
||
import com.routebox.routebox.application.recommended_route.dto.RecommendedRouteDto | ||
import com.routebox.routebox.domain.recommended_route.RecommendedRoute | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.data.jpa.repository.Query | ||
|
||
interface RecommendedRouteRepository : JpaRepository<RecommendedRoute, Long> { | ||
@Query( | ||
""" | ||
SELECT NEW com.routebox.routebox.application.recommended_route.dto.RecommendedRouteDto( | ||
r.id, r.name, r.description, rr.commonComment, | ||
CASE WHEN rai.fileUrl IS NOT NULL THEN rai.fileUrl ELSE "" END | ||
) | ||
FROM RecommendedRoute rr | ||
JOIN Route r ON rr.routeId = r.id | ||
LEFT JOIN RouteActivity ra ON ra.route = r | ||
LEFT JOIN RouteActivityImage rai ON rai.activity = ra | ||
WHERE r.isPublic = true AND rr.showFrom <= CURRENT_TIMESTAMP | ||
GROUP BY r.id | ||
""", | ||
) | ||
fun findAllRecommendedRoutes(): List<RecommendedRouteDto> | ||
} |
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