diff --git a/photi-apis/enduser/src/main/kotlin/com/photi/apis/enduser/controller/feed/FeedController.kt b/photi-apis/enduser/src/main/kotlin/com/photi/apis/enduser/controller/feed/FeedController.kt index a9520c3d..6281e815 100644 --- a/photi-apis/enduser/src/main/kotlin/com/photi/apis/enduser/controller/feed/FeedController.kt +++ b/photi-apis/enduser/src/main/kotlin/com/photi/apis/enduser/controller/feed/FeedController.kt @@ -60,10 +60,10 @@ class FeedController( @AuthUser user: CustomUserDetails, @PathVariable @Parameter(description = "챌린지 id", example = "1") challengeId: Long, @RequestBody @Valid request: RegisterFeedRequest, - ): ResponseEntity { - feedService.registerFeed(user.getUserId(), challengeId, request.toServiceDto()) - return ResponseEntity.status(CREATED) - .body(StringSuccessResponse("피드 인증이 완료되었습니다.")) + ): ResponseEntity { + val feed = feedService.registerFeed(user.getUserId(), challengeId, request.toServiceDto()) + val response = RegisterFeedResponse.of(feed) + return ResponseEntity.status(CREATED).body(response) } @DeleteMapping("/{challengeId}/{feedId}") diff --git a/photi-apis/enduser/src/main/kotlin/com/photi/apis/enduser/controller/feed/dto/request/RegisterFeedRequest.kt b/photi-apis/enduser/src/main/kotlin/com/photi/apis/enduser/controller/feed/dto/request/RegisterFeedRequest.kt index a74094e1..c44450b6 100644 --- a/photi-apis/enduser/src/main/kotlin/com/photi/apis/enduser/controller/feed/dto/request/RegisterFeedRequest.kt +++ b/photi-apis/enduser/src/main/kotlin/com/photi/apis/enduser/controller/feed/dto/request/RegisterFeedRequest.kt @@ -1,6 +1,6 @@ package com.photi.apis.enduser.controller.feed.dto.request -import com.photi.core.domain.feed.dto.RegisterFeedDto +import com.photi.core.domain.feed.dto.RegisterFeedRequestDto import io.swagger.v3.oas.annotations.media.Schema @Schema(description = "피드 등록 요청 객체") @@ -10,7 +10,7 @@ data class RegisterFeedRequest( val preSignedUrl: String, ) { - fun toServiceDto() = RegisterFeedDto(preSignedUrl.substringBefore(SUFFIX)) + fun toServiceDto() = RegisterFeedRequestDto(preSignedUrl.substringBefore(SUFFIX)) companion object { private const val SUFFIX = "?" diff --git a/photi-apis/enduser/src/main/kotlin/com/photi/apis/enduser/controller/feed/dto/response/RegisterFeedResponse.kt b/photi-apis/enduser/src/main/kotlin/com/photi/apis/enduser/controller/feed/dto/response/RegisterFeedResponse.kt new file mode 100644 index 00000000..d32d4f80 --- /dev/null +++ b/photi-apis/enduser/src/main/kotlin/com/photi/apis/enduser/controller/feed/dto/response/RegisterFeedResponse.kt @@ -0,0 +1,32 @@ +package com.photi.apis.enduser.controller.feed.dto.response + +import com.photi.core.domain.feed.dto.RegisterFeedDto +import io.swagger.v3.oas.annotations.media.Schema +import java.time.LocalDateTime + +@Schema(description = "피드 인증 응답 객체") +data class RegisterFeedResponse( + + @Schema(description = "피드 id", example = "1") + val id: Long, + + @Schema(description = "피드 이미지", example = "https://url.kr/5MhHhD") + val imageUrl: String, + + @Schema(description = "피드 인증 날짜") + val createdDateTime: LocalDateTime, + + @Schema(description = "피드 좋아요 여부", example = "true") + val isLike: Boolean, +) { + + companion object { + + fun of(feed: RegisterFeedDto) = RegisterFeedResponse( + feed.id, + feed.imageUrl, + feed.createdDateTime, + feed.isLike, + ) + } +} diff --git a/photi-core/domain/src/main/kotlin/com/photi/core/domain/common/model/BaseTimeEntity.kt b/photi-core/domain/src/main/kotlin/com/photi/core/domain/common/model/BaseTimeEntity.kt index fbbe8138..f3f011d8 100644 --- a/photi-core/domain/src/main/kotlin/com/photi/core/domain/common/model/BaseTimeEntity.kt +++ b/photi-core/domain/src/main/kotlin/com/photi/core/domain/common/model/BaseTimeEntity.kt @@ -14,7 +14,7 @@ abstract class BaseTimeEntity( @Column(updatable = false) @CreatedDate - private var createdDateTime: LocalDateTime? = null, + var createdDateTime: LocalDateTime? = null, @LastModifiedDate private var lastModifiedDateTime: LocalDateTime? = null, diff --git a/photi-core/domain/src/main/kotlin/com/photi/core/domain/feed/dto/RegisterFeedDto.kt b/photi-core/domain/src/main/kotlin/com/photi/core/domain/feed/dto/RegisterFeedDto.kt index f2f254cf..cd0f6c97 100644 --- a/photi-core/domain/src/main/kotlin/com/photi/core/domain/feed/dto/RegisterFeedDto.kt +++ b/photi-core/domain/src/main/kotlin/com/photi/core/domain/feed/dto/RegisterFeedDto.kt @@ -1,8 +1,9 @@ package com.photi.core.domain.feed.dto import com.photi.core.domain.feed.model.Feed +import java.time.LocalDateTime -data class RegisterFeedDto( +data class RegisterFeedRequestDto( val imageUrl: String, ) { @@ -13,3 +14,16 @@ data class RegisterFeedDto( imageUrl = imageUrl, ) } + +data class RegisterFeedDto( + val id: Long, + val imageUrl: String, + val createdDateTime: LocalDateTime, + val isLike: Boolean = false, +) { + + companion object { + + fun of(feed: Feed) = RegisterFeedDto(feed.id!!, feed.imageUrl, feed.createdDateTime!!) + } +} diff --git a/photi-core/domain/src/main/kotlin/com/photi/core/domain/feed/service/FeedService.kt b/photi-core/domain/src/main/kotlin/com/photi/core/domain/feed/service/FeedService.kt index cc00dbd7..b3fdd839 100644 --- a/photi-core/domain/src/main/kotlin/com/photi/core/domain/feed/service/FeedService.kt +++ b/photi-core/domain/src/main/kotlin/com/photi/core/domain/feed/service/FeedService.kt @@ -5,6 +5,7 @@ import com.photi.core.domain.common.consts.DirectoryType import com.photi.core.domain.feed.dto.FindImagePreSignedUrlDto import com.photi.core.domain.feed.dto.FindTodayFeedMemberCountDto import com.photi.core.domain.feed.dto.RegisterFeedDto +import com.photi.core.domain.feed.dto.RegisterFeedRequestDto import com.photi.core.domain.feed.exception.FeedException import com.photi.core.domain.feed.model.SortType import com.photi.core.domain.feed.port.* @@ -32,12 +33,17 @@ class FeedService( s3Port.getPreSignedUrl(dto.imageName, DirectoryType.FEEDS) @Transactional - fun registerFeed(userId: Long, challengeId: Long, dto: RegisterFeedDto) { + fun registerFeed( + userId: Long, + challengeId: Long, + dto: RegisterFeedRequestDto, + ): RegisterFeedDto { val challengeMemberId = getChallengeMemberIdBy(userId, challengeId) feedValidator.validateExistsTodayFeedBy(challengeMemberId) userChallengeHistoryPort.increaseFeed(userId) - val feedId = feedCommandService.createFeed(dto, userId, challengeMemberId, challengeId) - feedHistoryPort.createFeedHistory(feedId) + val feed = feedCommandService.createFeed(dto, userId, challengeMemberId, challengeId) + feedHistoryPort.createFeedHistory(feed.id) + return feed } @Transactional diff --git a/photi-core/domain/src/main/kotlin/com/photi/core/domain/feed/service/command/FeedCommandService.kt b/photi-core/domain/src/main/kotlin/com/photi/core/domain/feed/service/command/FeedCommandService.kt index d4a4c370..f06a033f 100644 --- a/photi-core/domain/src/main/kotlin/com/photi/core/domain/feed/service/command/FeedCommandService.kt +++ b/photi-core/domain/src/main/kotlin/com/photi/core/domain/feed/service/command/FeedCommandService.kt @@ -1,6 +1,7 @@ package com.photi.core.domain.feed.service.command import com.photi.core.domain.feed.dto.RegisterFeedDto +import com.photi.core.domain.feed.dto.RegisterFeedRequestDto import com.photi.core.domain.feed.model.repository.FeedRepository import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @@ -11,8 +12,15 @@ class FeedCommandService( private val feedRepository: FeedRepository, ) { - fun createFeed(dto: RegisterFeedDto, userId: Long, challengeMemberId: Long, challengeId: Long) = - feedRepository.save(dto.toEntity(userId, challengeMemberId, challengeId)).id!! + fun createFeed( + dto: RegisterFeedRequestDto, + userId: Long, + challengeMemberId: Long, + challengeId: Long, + ): RegisterFeedDto { + val feed = feedRepository.save(dto.toEntity(userId, challengeMemberId, challengeId)) + return RegisterFeedDto.of(feed) + } fun deleteFeed(feedId: Long) { feedRepository.deleteById(feedId)