From eccc95316cd9d98901774f1bdf12fdd8ecbd5ede Mon Sep 17 00:00:00 2001 From: 210-reverof Date: Mon, 5 Aug 2024 02:55:27 +0900 Subject: [PATCH] feat: Create visiting API --- .../applicationService/EventApplicationService.kt | 8 ++++++++ .../dto/MarkEventVisitedServiceRequest.kt | 15 +++++++++++++++ .../pic/event/controller/EventController.kt | 12 ++++++++++++ .../controller/dto/MarkEventVisitedRequest.kt | 5 +++++ .../controller/dto/MarkEventVisitedResponse.kt | 5 +++++ .../com/mashup/pic/domain/event/EventService.kt | 9 +++++++++ 6 files changed, 54 insertions(+) create mode 100644 pic-api/src/main/kotlin/com/mashup/pic/event/applicationService/dto/MarkEventVisitedServiceRequest.kt create mode 100644 pic-api/src/main/kotlin/com/mashup/pic/event/controller/dto/MarkEventVisitedRequest.kt create mode 100644 pic-api/src/main/kotlin/com/mashup/pic/event/controller/dto/MarkEventVisitedResponse.kt diff --git a/pic-api/src/main/kotlin/com/mashup/pic/event/applicationService/EventApplicationService.kt b/pic-api/src/main/kotlin/com/mashup/pic/event/applicationService/EventApplicationService.kt index 0191bdb..2c3a002 100644 --- a/pic-api/src/main/kotlin/com/mashup/pic/event/applicationService/EventApplicationService.kt +++ b/pic-api/src/main/kotlin/com/mashup/pic/event/applicationService/EventApplicationService.kt @@ -3,8 +3,10 @@ package com.mashup.pic.event.applicationService import com.mashup.pic.domain.event.EventService import com.mashup.pic.domain.event.UploadService import com.mashup.pic.event.applicationService.dto.CreateEventServiceRequest +import com.mashup.pic.event.applicationService.dto.MarkEventVisitedServiceRequest import com.mashup.pic.event.applicationService.dto.UploadImageServiceRequest import com.mashup.pic.event.controller.dto.CreateEventResponse +import com.mashup.pic.event.controller.dto.MarkEventVisitedResponse import com.mashup.pic.event.controller.dto.UploadImageResponse import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @@ -46,4 +48,10 @@ class EventApplicationService( return UploadImageResponse(request.eventId) } + + @Transactional + fun markEventVisit(request: MarkEventVisitedServiceRequest): MarkEventVisitedResponse { + eventService.markVisited(request.userId, request.eventId) + return MarkEventVisitedResponse(true) + } } diff --git a/pic-api/src/main/kotlin/com/mashup/pic/event/applicationService/dto/MarkEventVisitedServiceRequest.kt b/pic-api/src/main/kotlin/com/mashup/pic/event/applicationService/dto/MarkEventVisitedServiceRequest.kt new file mode 100644 index 0000000..7f109bc --- /dev/null +++ b/pic-api/src/main/kotlin/com/mashup/pic/event/applicationService/dto/MarkEventVisitedServiceRequest.kt @@ -0,0 +1,15 @@ +package com.mashup.pic.event.applicationService.dto + +import com.mashup.pic.event.controller.dto.MarkEventVisitedRequest + +data class MarkEventVisitedServiceRequest( + val userId: Long, + val eventId: Long +) + +fun MarkEventVisitedRequest.toServiceRequest(userId: Long): MarkEventVisitedServiceRequest { + return MarkEventVisitedServiceRequest( + userId = userId, + eventId = this.eventId + ) +} diff --git a/pic-api/src/main/kotlin/com/mashup/pic/event/controller/EventController.kt b/pic-api/src/main/kotlin/com/mashup/pic/event/controller/EventController.kt index ac4e556..b388817 100644 --- a/pic-api/src/main/kotlin/com/mashup/pic/event/controller/EventController.kt +++ b/pic-api/src/main/kotlin/com/mashup/pic/event/controller/EventController.kt @@ -5,6 +5,8 @@ import com.mashup.pic.event.applicationService.EventApplicationService import com.mashup.pic.event.applicationService.dto.toServiceRequest import com.mashup.pic.event.controller.dto.CreateEventRequest import com.mashup.pic.event.controller.dto.CreateEventResponse +import com.mashup.pic.event.controller.dto.MarkEventVisitedRequest +import com.mashup.pic.event.controller.dto.MarkEventVisitedResponse import com.mashup.pic.event.controller.dto.UploadImageRequest import com.mashup.pic.event.controller.dto.UploadImageResponse import com.mashup.pic.event.controller.dto.toServiceRequest @@ -14,6 +16,7 @@ import io.swagger.v3.oas.annotations.tags.Tag import jakarta.validation.Valid import org.springframework.security.core.annotation.AuthenticationPrincipal import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.PutMapping import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController @@ -45,4 +48,13 @@ class EventController( eventApplicationService.uploadImages(uploadImageRequest.toServiceRequest(user.id)) ) } + + @PutMapping("/visit") + @Operation(summary = "이벤트 방문 표시") + fun markVisited( + @AuthenticationPrincipal user: UserInfo, + @Valid @RequestBody request: MarkEventVisitedRequest + ): ApiResponse { + return ApiResponse.success(eventApplicationService.markEventVisit(request.toServiceRequest(user.id))) + } } diff --git a/pic-api/src/main/kotlin/com/mashup/pic/event/controller/dto/MarkEventVisitedRequest.kt b/pic-api/src/main/kotlin/com/mashup/pic/event/controller/dto/MarkEventVisitedRequest.kt new file mode 100644 index 0000000..0868433 --- /dev/null +++ b/pic-api/src/main/kotlin/com/mashup/pic/event/controller/dto/MarkEventVisitedRequest.kt @@ -0,0 +1,5 @@ +package com.mashup.pic.event.controller.dto + +data class MarkEventVisitedRequest( + val eventId: Long +) diff --git a/pic-api/src/main/kotlin/com/mashup/pic/event/controller/dto/MarkEventVisitedResponse.kt b/pic-api/src/main/kotlin/com/mashup/pic/event/controller/dto/MarkEventVisitedResponse.kt new file mode 100644 index 0000000..00d9d4e --- /dev/null +++ b/pic-api/src/main/kotlin/com/mashup/pic/event/controller/dto/MarkEventVisitedResponse.kt @@ -0,0 +1,5 @@ +package com.mashup.pic.event.controller.dto + +data class MarkEventVisitedResponse( + val visited: Boolean +) diff --git a/pic-domain/src/main/kotlin/com/mashup/pic/domain/event/EventService.kt b/pic-domain/src/main/kotlin/com/mashup/pic/domain/event/EventService.kt index eaaab3e..4fb4a9f 100644 --- a/pic-domain/src/main/kotlin/com/mashup/pic/domain/event/EventService.kt +++ b/pic-domain/src/main/kotlin/com/mashup/pic/domain/event/EventService.kt @@ -90,6 +90,15 @@ class EventService( return events.map { it.toDto() } } + @Transactional + fun markVisited( + userId: Long, + eventId: Long + ) { + val eventJoin = getEventJoinByUserIdAndEventId(userId, eventId) + eventJoin.isVisited = true + } + private fun createEventJoinsByGroup( eventId: Long, groupId: Long