Skip to content

Commit 5bb51fc

Browse files
committed
feat: 디스플레이용 조회 API 구현
1 parent 1542d9e commit 5bb51fc

7 files changed

Lines changed: 126 additions & 1 deletion

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package site.billilge.api.backend.domain.display.controller
2+
3+
import io.swagger.v3.oas.annotations.Operation
4+
import io.swagger.v3.oas.annotations.responses.ApiResponse
5+
import io.swagger.v3.oas.annotations.responses.ApiResponses
6+
import io.swagger.v3.oas.annotations.tags.Tag
7+
import org.springframework.http.ResponseEntity
8+
import site.billilge.api.backend.domain.display.dto.response.DisplayResponse
9+
10+
@Tag(name = "Display", description = "디스플레이 조회 API")
11+
interface DisplayApi {
12+
13+
@Operation(
14+
summary = "디스플레이 데이터 조회",
15+
description = "활성 포스터, 일정 캘린더(±3일), 복지물품 현황을 조회하는 API"
16+
)
17+
@ApiResponses(
18+
value = [
19+
ApiResponse(
20+
responseCode = "200",
21+
description = "디스플레이 데이터 조회 성공"
22+
)
23+
]
24+
)
25+
fun getDisplay(): ResponseEntity<DisplayResponse>
26+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package site.billilge.api.backend.domain.display.controller
2+
3+
import org.springframework.http.ResponseEntity
4+
import org.springframework.web.bind.annotation.GetMapping
5+
import org.springframework.web.bind.annotation.RequestMapping
6+
import org.springframework.web.bind.annotation.RestController
7+
import site.billilge.api.backend.domain.display.dto.response.DisplayResponse
8+
import site.billilge.api.backend.domain.display.facade.DisplayFacade
9+
10+
@RestController
11+
@RequestMapping("/display")
12+
class DisplayController(
13+
private val displayFacade: DisplayFacade,
14+
) : DisplayApi {
15+
16+
@GetMapping
17+
override fun getDisplay(): ResponseEntity<DisplayResponse> {
18+
return ResponseEntity.ok(displayFacade.getDisplay())
19+
}
20+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package site.billilge.api.backend.domain.display.dto.response
2+
3+
data class DisplayResponse(
4+
val posters: List<PosterDetail>,
5+
val schedules: List<Map<String, List<String>>>,
6+
val items: List<DisplayItemDetail>,
7+
) {
8+
data class PosterDetail(
9+
val posterId: Long,
10+
val title: String,
11+
val imageUrl: String,
12+
)
13+
14+
data class DisplayItemDetail(
15+
val itemName: String,
16+
val count: Int,
17+
val imageUrl: String,
18+
)
19+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package site.billilge.api.backend.domain.display.facade
2+
3+
import org.springframework.stereotype.Component
4+
import site.billilge.api.backend.domain.display.dto.response.DisplayResponse
5+
import site.billilge.api.backend.domain.display.service.DisplayCalendarScheduleService
6+
import site.billilge.api.backend.domain.display.service.DisplayPosterService
7+
import site.billilge.api.backend.domain.item.service.ItemService
8+
import java.time.LocalDate
9+
10+
@Component
11+
class DisplayFacade(
12+
private val displayPosterService: DisplayPosterService,
13+
private val displayCalendarScheduleService: DisplayCalendarScheduleService,
14+
private val itemService: ItemService,
15+
) {
16+
fun getDisplay(): DisplayResponse {
17+
val posters = displayPosterService.getActivePosters()
18+
.map { poster ->
19+
DisplayResponse.PosterDetail(
20+
posterId = poster.id!!,
21+
title = poster.title,
22+
imageUrl = poster.imageUrl,
23+
)
24+
}
25+
26+
val today = LocalDate.now()
27+
val startDate = today.minusDays(3)
28+
val endDate = today.plusDays(3)
29+
30+
val scheduleEntities = displayCalendarScheduleService.getSchedules(startDate, endDate)
31+
val scheduleMap = scheduleEntities.associate { it.date to it.scheduleList }
32+
33+
val schedules = (0L..6L).map { offset ->
34+
val date = startDate.plusDays(offset)
35+
mapOf(date.toString() to (scheduleMap[date] ?: emptyList()))
36+
}
37+
38+
val items = itemService.getAllItems()
39+
.map { item ->
40+
DisplayResponse.DisplayItemDetail(
41+
itemName = item.name,
42+
count = item.count,
43+
imageUrl = item.imageUrl,
44+
)
45+
}
46+
47+
return DisplayResponse(
48+
posters = posters,
49+
schedules = schedules,
50+
items = items,
51+
)
52+
}
53+
}

src/main/kotlin/site/billilge/api/backend/domain/display/repository/DisplayPosterRepository.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ package site.billilge.api.backend.domain.display.repository
33
import org.springframework.data.jpa.repository.JpaRepository
44
import site.billilge.api.backend.domain.display.entity.DisplayPoster
55

6-
interface DisplayPosterRepository : JpaRepository<DisplayPoster, Long>
6+
interface DisplayPosterRepository : JpaRepository<DisplayPoster, Long> {
7+
fun findByIsActiveTrue(): List<DisplayPoster>
8+
}

src/main/kotlin/site/billilge/api/backend/domain/display/service/DisplayPosterService.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ class DisplayPosterService(
1616
return displayPosterRepository.findAll()
1717
}
1818

19+
fun getActivePosters(): List<DisplayPoster> {
20+
return displayPosterRepository.findByIsActiveTrue()
21+
}
22+
1923
@Transactional
2024
fun addPoster(imageUrl: String, title: String) {
2125
val poster = DisplayPoster(

src/main/kotlin/site/billilge/api/backend/global/config/SecurityConfig.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class SecurityConfig (
6262
.authorizeHttpRequests { httpRequests ->
6363
httpRequests
6464
.requestMatchers("/auth/**").permitAll()
65+
.requestMatchers("/display").permitAll()
6566
.requestMatchers(*SWAGGER_API_PATH).permitAll()
6667
.anyRequest().authenticated()
6768
}

0 commit comments

Comments
 (0)