Skip to content

Commit f8ceba2

Browse files
authored
merge: (#963) 최근 게시물 조회 api 생성
2 parents 0920170 + d504822 commit f8ceba2

File tree

9 files changed

+57
-0
lines changed

9 files changed

+57
-0
lines changed

dms-main/main-core/src/main/kotlin/team/aliens/dms/domain/notice/dto/NoticeResponse.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,17 @@ data class NoticesResponse(
3737
data class NoticeIdResponse(
3838
val noticeId: UUID
3939
)
40+
41+
data class LatestNoticeResponse(
42+
val id: UUID,
43+
val title: String
44+
) {
45+
companion object {
46+
fun of(notice: Notice): LatestNoticeResponse {
47+
return LatestNoticeResponse(
48+
id = notice.id,
49+
title = notice.title
50+
)
51+
}
52+
}
53+
}

dms-main/main-core/src/main/kotlin/team/aliens/dms/domain/notice/service/GetNoticeService.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ interface GetNoticeService {
88

99
fun getAllNoticesBySchoolIdAndOrder(schoolId: UUID, orderType: OrderType): List<Notice>
1010

11+
fun getLatestNoticeBySchoolId(schoolId: UUID): Notice?
12+
1113
fun getNoticeById(noticeId: UUID): Notice
1214

1315
fun getNoticeByIdAndManagerId(noticeId: UUID, managerId: UUID): Notice

dms-main/main-core/src/main/kotlin/team/aliens/dms/domain/notice/service/GetNoticeServiceImpl.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ class GetNoticeServiceImpl(
1616
return queryNoticePort.queryAllNoticesBySchoolIdAndOrder(schoolId, orderType)
1717
}
1818

19+
override fun getLatestNoticeBySchoolId(schoolId: UUID): Notice? {
20+
return queryNoticePort.queryLatestNoticeBySchoolId(schoolId)
21+
}
22+
1923
override fun getNoticeById(noticeId: UUID): Notice {
2024
return queryNoticePort.queryNoticeById(noticeId)
2125
?: throw NoticeNotFoundException

dms-main/main-core/src/main/kotlin/team/aliens/dms/domain/notice/spi/QueryNoticePort.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ interface QueryNoticePort {
1313

1414
fun queryAllNoticesBySchoolIdAndOrder(schoolId: UUID, orderType: OrderType): List<Notice>
1515

16+
fun queryLatestNoticeBySchoolId(schoolId: UUID): Notice?
17+
1618
fun queryNoticeByIdAndManagerId(noticeId: UUID, managerId: UUID): Notice?
1719
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package team.aliens.dms.domain.notice.usecase
2+
3+
import team.aliens.dms.common.annotation.ReadOnlyUseCase
4+
import team.aliens.dms.domain.notice.dto.LatestNoticeResponse
5+
import team.aliens.dms.domain.notice.service.NoticeService
6+
import team.aliens.dms.domain.user.service.UserService
7+
8+
@ReadOnlyUseCase
9+
class QueryLatestNoticeUseCase(
10+
private val userService: UserService,
11+
private val noticeService: NoticeService
12+
) {
13+
14+
fun execute(): LatestNoticeResponse? {
15+
val user = userService.getCurrentUser()
16+
val latestNotice = noticeService.getLatestNoticeBySchoolId(user.schoolId)
17+
18+
return latestNotice?.let { LatestNoticeResponse.of(it) }
19+
}
20+
}

dms-main/main-infrastructure/src/main/kotlin/team/aliens/dms/global/security/SecurityConfig.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class SecurityConfig(
8484

8585
authorize
8686
// /notices
87+
.requestMatchers(HttpMethod.GET, "/notices/latest").hasAnyAuthority(STUDENT.name, MANAGER.name)
8788
.requestMatchers(HttpMethod.GET, "/notices/status").hasAuthority(STUDENT.name)
8889
.requestMatchers(HttpMethod.GET, "/notices").hasAnyAuthority(STUDENT.name, MANAGER.name)
8990
.requestMatchers(HttpMethod.GET, "/notices/{notice-id}").hasAnyAuthority(STUDENT.name, MANAGER.name)

dms-main/main-persistence/src/main/kotlin/team/aliens/dms/persistence/notice/NoticePersistenceAdapter.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ class NoticePersistenceAdapter(
3737
}
3838
}
3939

40+
override fun queryLatestNoticeBySchoolId(schoolId: UUID) = noticeMapper.toDomain(
41+
noticeRepository.findFirstByManagerUserSchoolIdOrderByCreatedAtDesc(schoolId)
42+
)
43+
4044
override fun queryNoticeByIdAndManagerId(noticeId: UUID, managerId: UUID) = noticeMapper.toDomain(
4145
noticeRepository.findByIdAndManagerUserId(noticeId, managerId)
4246
)

dms-main/main-persistence/src/main/kotlin/team/aliens/dms/persistence/notice/repository/NoticeJpaRepository.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ interface NoticeJpaRepository : JpaRepository<NoticeJpaEntity, UUID> {
1616

1717
fun findAllByManagerUserSchoolIdOrderByCreatedAtDesc(schoolId: UUID): List<NoticeJpaEntity>
1818

19+
fun findFirstByManagerUserSchoolIdOrderByCreatedAtDesc(schoolId: UUID): NoticeJpaEntity?
20+
1921
fun findByIdAndManagerUserId(id: UUID, managerId: UUID): NoticeJpaEntity?
2022
}

dms-main/main-presentation/src/main/kotlin/team/aliens/dms/domain/notice/NoticeWebAdapter.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping
1414
import org.springframework.web.bind.annotation.RequestParam
1515
import org.springframework.web.bind.annotation.ResponseStatus
1616
import org.springframework.web.bind.annotation.RestController
17+
import team.aliens.dms.domain.notice.dto.LatestNoticeResponse
1718
import team.aliens.dms.domain.notice.dto.NoticeIdResponse
1819
import team.aliens.dms.domain.notice.dto.NoticeResponse
1920
import team.aliens.dms.domain.notice.dto.NoticesResponse
@@ -23,6 +24,7 @@ import team.aliens.dms.domain.notice.dto.request.WebOrderType
2324
import team.aliens.dms.domain.notice.dto.response.GetNoticeStatusResponse
2425
import team.aliens.dms.domain.notice.usecase.CreateNoticeUseCase
2526
import team.aliens.dms.domain.notice.usecase.QueryAllNoticesUseCase
27+
import team.aliens.dms.domain.notice.usecase.QueryLatestNoticeUseCase
2628
import team.aliens.dms.domain.notice.usecase.QueryNoticeDetailsUseCase
2729
import team.aliens.dms.domain.notice.usecase.QueryNoticeStatusUseCase
2830
import team.aliens.dms.domain.notice.usecase.RemoveNoticeUseCase
@@ -36,6 +38,7 @@ class NoticeWebAdapter(
3638
private val queryNoticeStatusUseCase: QueryNoticeStatusUseCase,
3739
private val queryNoticeDetailsUseCase: QueryNoticeDetailsUseCase,
3840
private val queryAllNoticesUseCase: QueryAllNoticesUseCase,
41+
private val queryLatestNoticeUseCase: QueryLatestNoticeUseCase,
3942
private val removeNoticeUseCase: RemoveNoticeUseCase,
4043
private val updateNoticeUseCase: UpdateNoticeUseCase,
4144
private val createNoticeUseCase: CreateNoticeUseCase
@@ -48,6 +51,11 @@ class NoticeWebAdapter(
4851
return GetNoticeStatusResponse(result)
4952
}
5053

54+
@GetMapping("/latest")
55+
fun getLatestNotice(): LatestNoticeResponse? {
56+
return queryLatestNoticeUseCase.execute()
57+
}
58+
5159
@GetMapping("/{notice-id}")
5260
fun getDetails(@PathVariable("notice-id") @NotNull noticeId: UUID): NoticeResponse {
5361
return queryNoticeDetailsUseCase.execute(noticeId)

0 commit comments

Comments
 (0)