Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,17 @@ data class NoticesResponse(
data class NoticeIdResponse(
val noticeId: UUID
)

data class LatestNoticeResponse(
val id: UUID,
val title: String
) {
companion object {
fun of(notice: Notice): LatestNoticeResponse {
return LatestNoticeResponse(
id = notice.id,
title = notice.title
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ interface GetNoticeService {

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

fun getLatestNoticeBySchoolId(schoolId: UUID): Notice?

fun getNoticeById(noticeId: UUID): Notice

fun getNoticeByIdAndManagerId(noticeId: UUID, managerId: UUID): Notice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class GetNoticeServiceImpl(
return queryNoticePort.queryAllNoticesBySchoolIdAndOrder(schoolId, orderType)
}

override fun getLatestNoticeBySchoolId(schoolId: UUID): Notice? {
return queryNoticePort.queryLatestNoticeBySchoolId(schoolId)
}

override fun getNoticeById(noticeId: UUID): Notice {
return queryNoticePort.queryNoticeById(noticeId)
?: throw NoticeNotFoundException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ interface QueryNoticePort {

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

fun queryLatestNoticeBySchoolId(schoolId: UUID): Notice?

fun queryNoticeByIdAndManagerId(noticeId: UUID, managerId: UUID): Notice?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package team.aliens.dms.domain.notice.usecase

import team.aliens.dms.common.annotation.ReadOnlyUseCase
import team.aliens.dms.domain.notice.dto.LatestNoticeResponse
import team.aliens.dms.domain.notice.service.NoticeService
import team.aliens.dms.domain.user.service.UserService

@ReadOnlyUseCase
class QueryLatestNoticeUseCase(
private val userService: UserService,
private val noticeService: NoticeService
) {

fun execute(): LatestNoticeResponse? {
val user = userService.getCurrentUser()
val latestNotice = noticeService.getLatestNoticeBySchoolId(user.schoolId)

return latestNotice?.let { LatestNoticeResponse.of(it) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class SecurityConfig(

authorize
// /notices
.requestMatchers(HttpMethod.GET, "/notices/latest").hasAnyAuthority(STUDENT.name, MANAGER.name)
.requestMatchers(HttpMethod.GET, "/notices/status").hasAuthority(STUDENT.name)
.requestMatchers(HttpMethod.GET, "/notices").hasAnyAuthority(STUDENT.name, MANAGER.name)
.requestMatchers(HttpMethod.GET, "/notices/{notice-id}").hasAnyAuthority(STUDENT.name, MANAGER.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class NoticePersistenceAdapter(
}
}

override fun queryLatestNoticeBySchoolId(schoolId: UUID) = noticeMapper.toDomain(
noticeRepository.findFirstByManagerUserSchoolIdOrderByCreatedAtDesc(schoolId)
)

override fun queryNoticeByIdAndManagerId(noticeId: UUID, managerId: UUID) = noticeMapper.toDomain(
noticeRepository.findByIdAndManagerUserId(noticeId, managerId)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ interface NoticeJpaRepository : JpaRepository<NoticeJpaEntity, UUID> {

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

fun findFirstByManagerUserSchoolIdOrderByCreatedAtDesc(schoolId: UUID): NoticeJpaEntity?

fun findByIdAndManagerUserId(id: UUID, managerId: UUID): NoticeJpaEntity?
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.RestController
import team.aliens.dms.domain.notice.dto.LatestNoticeResponse
import team.aliens.dms.domain.notice.dto.NoticeIdResponse
import team.aliens.dms.domain.notice.dto.NoticeResponse
import team.aliens.dms.domain.notice.dto.NoticesResponse
Expand All @@ -23,6 +24,7 @@ import team.aliens.dms.domain.notice.dto.request.WebOrderType
import team.aliens.dms.domain.notice.dto.response.GetNoticeStatusResponse
import team.aliens.dms.domain.notice.usecase.CreateNoticeUseCase
import team.aliens.dms.domain.notice.usecase.QueryAllNoticesUseCase
import team.aliens.dms.domain.notice.usecase.QueryLatestNoticeUseCase
import team.aliens.dms.domain.notice.usecase.QueryNoticeDetailsUseCase
import team.aliens.dms.domain.notice.usecase.QueryNoticeStatusUseCase
import team.aliens.dms.domain.notice.usecase.RemoveNoticeUseCase
Expand All @@ -36,6 +38,7 @@ class NoticeWebAdapter(
private val queryNoticeStatusUseCase: QueryNoticeStatusUseCase,
private val queryNoticeDetailsUseCase: QueryNoticeDetailsUseCase,
private val queryAllNoticesUseCase: QueryAllNoticesUseCase,
private val queryLatestNoticeUseCase: QueryLatestNoticeUseCase,
private val removeNoticeUseCase: RemoveNoticeUseCase,
private val updateNoticeUseCase: UpdateNoticeUseCase,
private val createNoticeUseCase: CreateNoticeUseCase
Expand All @@ -48,6 +51,11 @@ class NoticeWebAdapter(
return GetNoticeStatusResponse(result)
}

@GetMapping("/latest")
fun getLatestNotice(): LatestNoticeResponse? {
return queryLatestNoticeUseCase.execute()
}

@GetMapping("/{notice-id}")
fun getDetails(@PathVariable("notice-id") @NotNull noticeId: UUID): NoticeResponse {
return queryNoticeDetailsUseCase.execute(noticeId)
Expand Down
Loading