From cc14429d3559c032f8fd8f2c5c761c8f0718623f Mon Sep 17 00:00:00 2001 From: gilgeunwoo Date: Tue, 12 Dec 2023 17:19:39 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat=20::=20(#14)=20=EA=B6=8C=ED=95=9C?= =?UTF-8?q?=EB=94=B0=EB=9D=BC=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event_schedule/spi/EventSchedulePort.kt | 2 +- .../QueryEventScheduleDetailUseCase.kt | 19 ++++++++++++++++++- .../EvenSchedulePersistenceAdapter.kt | 18 ++++++++++++++++-- .../global/security/SecurityAdapter.kt | 2 ++ .../global/security/SecurityConfig.kt | 6 +++--- 5 files changed, 40 insertions(+), 7 deletions(-) diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/spi/EventSchedulePort.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/spi/EventSchedulePort.kt index 82f200a..045bb4f 100644 --- a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/spi/EventSchedulePort.kt +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/spi/EventSchedulePort.kt @@ -10,7 +10,7 @@ interface EventSchedulePort : QueryEventSchedulePort, CommandEventSchedulePort { interface QueryEventSchedulePort { fun queryWeeklyEventScheduleById(weeklyEventScheduleId: UUID): WeeklyEventSchedule? - fun queryEventSchedulesByWeeklyEventScheduleId(weeklyEventScheduleId: UUID): List + fun queryEventSchedulesByWeeklyEventScheduleId(weeklyEventScheduleId: UUID, userId: UUID?): List } interface CommandEventSchedulePort { diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/usecase/QueryEventScheduleDetailUseCase.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/usecase/QueryEventScheduleDetailUseCase.kt index 83fcc66..7fc31f5 100644 --- a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/usecase/QueryEventScheduleDetailUseCase.kt +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/usecase/QueryEventScheduleDetailUseCase.kt @@ -1,21 +1,38 @@ package com.kodomo.juganbbojjak.domain.event_schedule.usecase import com.kodomo.juganbbojjak.common.annotation.UseCase +import com.kodomo.juganbbojjak.common.spi.SecurityPort import com.kodomo.juganbbojjak.domain.event_schedule.dto.response.EventDetailResponse import com.kodomo.juganbbojjak.domain.event_schedule.dto.response.QueryEventScheduleDetailResponse import com.kodomo.juganbbojjak.domain.event_schedule.exception.WeeklyEventScheduleNotFoundException import com.kodomo.juganbbojjak.domain.event_schedule.spi.QueryEventSchedulePort +import com.kodomo.juganbbojjak.domain.user.exception.UserNotFoundException +import com.kodomo.juganbbojjak.domain.user.model.Authority +import com.kodomo.juganbbojjak.domain.user.spi.QueryUserPort import java.util.UUID @UseCase class QueryEventScheduleDetailUseCase( private val queryEventSchedulePort: QueryEventSchedulePort, + private val queryUserPort: QueryUserPort, + private val securityPort: SecurityPort, ) { fun execute(weeklyEventScheduleId: UUID): QueryEventScheduleDetailResponse { + val user = queryUserPort.queryUserById(securityPort.getCurrentUserId()) ?: throw UserNotFoundException val weeklyEventSchedule = queryEventSchedulePort.queryWeeklyEventScheduleById(weeklyEventScheduleId) ?: throw WeeklyEventScheduleNotFoundException - val eventSchedules = queryEventSchedulePort.queryEventSchedulesByWeeklyEventScheduleId(weeklyEventSchedule.id) + val eventSchedules = when (user.authority) { + Authority.USER -> queryEventSchedulePort.queryEventSchedulesByWeeklyEventScheduleId( + weeklyEventScheduleId, + user.id, + ) + + Authority.ADMIN -> queryEventSchedulePort.queryEventSchedulesByWeeklyEventScheduleId( + weeklyEventScheduleId, + null, + ) + } return QueryEventScheduleDetailResponse( startDate = weeklyEventSchedule.startDate, diff --git a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/persistence/EvenSchedulePersistenceAdapter.kt b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/persistence/EvenSchedulePersistenceAdapter.kt index fccd327..bed7e21 100644 --- a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/persistence/EvenSchedulePersistenceAdapter.kt +++ b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/persistence/EvenSchedulePersistenceAdapter.kt @@ -10,6 +10,7 @@ import com.kodomo.juganbbojjak.domain.event_schedule.persistence.repository.Even import com.kodomo.juganbbojjak.domain.event_schedule.persistence.repository.WeeklyEventScheduleJpaRepository import com.kodomo.juganbbojjak.domain.event_schedule.spi.EventSchedulePort import com.kodomo.juganbbojjak.global.annotation.Adapter +import com.querydsl.core.types.dsl.BooleanExpression import com.querydsl.jpa.impl.JPAQueryFactory import org.springframework.data.repository.findByIdOrNull import java.util.UUID @@ -28,11 +29,17 @@ class EvenSchedulePersistenceAdapter( weeklyEventScheduleJpaRepository.findByIdOrNull(weeklyEventScheduleId) ) - override fun queryEventSchedulesByWeeklyEventScheduleId(weeklyEventScheduleId: UUID): List { + override fun queryEventSchedulesByWeeklyEventScheduleId( + weeklyEventScheduleId: UUID, + userId: UUID? + ): List { return queryFactory .selectFrom(eventScheduleEntity) .join(eventScheduleEntity.weeklyEventScheduleEntity, weeklyEventScheduleEntity) - .where(weeklyEventScheduleEntity.id.eq(weeklyEventScheduleId)) + .where( + weeklyEventScheduleEntity.id.eq(weeklyEventScheduleId), + eqUserId(userId) + ) .orderBy(eventScheduleEntity.date.asc()) .fetch().stream() .map { eventScheduleMapper.toDomain(it)!! } @@ -42,4 +49,11 @@ class EvenSchedulePersistenceAdapter( override fun saveAllEventSchedule(eventSchedule: List) { eventScheduleJpaRepository.saveAll(eventSchedule.stream().map { eventScheduleMapper.toEntity(it) }.toList()) } + + //==condition==// + + private fun eqUserId(userId: UUID?): BooleanExpression? = + if (userId != null) + eventScheduleEntity.userEntity.id.eq(userId) + else null } \ No newline at end of file diff --git a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/global/security/SecurityAdapter.kt b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/global/security/SecurityAdapter.kt index 5802bf1..c09aa60 100644 --- a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/global/security/SecurityAdapter.kt +++ b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/global/security/SecurityAdapter.kt @@ -1,7 +1,9 @@ package com.kodomo.juganbbojjak.global.security import com.kodomo.juganbbojjak.common.spi.SecurityPort +import com.kodomo.juganbbojjak.domain.user.model.Authority import com.kodomo.juganbbojjak.global.annotation.Adapter +import org.springframework.security.core.authority.SimpleGrantedAuthority import org.springframework.security.core.context.SecurityContextHolder import org.springframework.security.crypto.password.PasswordEncoder import java.util.UUID diff --git a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/global/security/SecurityConfig.kt b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/global/security/SecurityConfig.kt index 35ec4c3..775adc8 100644 --- a/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/global/security/SecurityConfig.kt +++ b/JuGanBbojjak-infrastructure/src/main/kotlin/com/kodomo/juganbbojjak/global/security/SecurityConfig.kt @@ -32,10 +32,10 @@ class SecurityConfig( .authorizeHttpRequests { it .requestMatchers(HttpMethod.POST, "/event_schedules/{weekly-event-schedule-id}").hasAuthority(USER.name) - .requestMatchers(HttpMethod.GET, "/event_schedules/{weekly-event-schedule-id}").hasAuthority(ADMIN.name) - + .requestMatchers(HttpMethod.GET, "/event_schedules/{weekly-event-schedule-id}").hasAnyAuthority(ADMIN.name, USER.name) + .requestMatchers(HttpMethod.POST, "/work_report/{weekly-work-report-id}").hasAuthority(USER.name) - + .anyRequest().permitAll() } .apply(FilterConfig(jwtTokenParser, objectMapper)) From 31569c831e136fd759c415e5b31637f3669efec2 Mon Sep 17 00:00:00 2001 From: gilgeunwoo Date: Tue, 12 Dec 2023 17:25:49 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat=20::=20(#14)=20id=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/response/QueryEventScheduleDetailResponse.kt | 2 ++ .../event_schedule/usecase/QueryEventScheduleDetailUseCase.kt | 1 + 2 files changed, 3 insertions(+) diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/dto/response/QueryEventScheduleDetailResponse.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/dto/response/QueryEventScheduleDetailResponse.kt index 66136c0..845b4ca 100644 --- a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/dto/response/QueryEventScheduleDetailResponse.kt +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/dto/response/QueryEventScheduleDetailResponse.kt @@ -2,6 +2,7 @@ package com.kodomo.juganbbojjak.domain.event_schedule.dto.response import com.kodomo.juganbbojjak.domain.event_schedule.model.EventSchedule import java.time.LocalDate +import java.util.UUID data class QueryEventScheduleDetailResponse( val startDate: LocalDate, @@ -10,6 +11,7 @@ data class QueryEventScheduleDetailResponse( ) data class EventDetailResponse( + val eventScheduleId: UUID, val date: LocalDate, val name: String, val place: String, diff --git a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/usecase/QueryEventScheduleDetailUseCase.kt b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/usecase/QueryEventScheduleDetailUseCase.kt index 7fc31f5..e255399 100644 --- a/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/usecase/QueryEventScheduleDetailUseCase.kt +++ b/JuGanBbojjak-application/src/main/kotlin/com/kodomo/juganbbojjak/domain/event_schedule/usecase/QueryEventScheduleDetailUseCase.kt @@ -40,6 +40,7 @@ class QueryEventScheduleDetailUseCase( eventSchedules = eventSchedules.stream() .map { EventDetailResponse( + eventScheduleId = it.id, date = it.date, name = it.name, place = it.place,