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 @@ -60,10 +60,10 @@ class FeedController(
@AuthUser user: CustomUserDetails,
@PathVariable @Parameter(description = "챌린지 id", example = "1") challengeId: Long,
@RequestBody @Valid request: RegisterFeedRequest,
): ResponseEntity<StringSuccessResponse> {
feedService.registerFeed(user.getUserId(), challengeId, request.toServiceDto())
return ResponseEntity.status(CREATED)
.body(StringSuccessResponse("피드 인증이 완료되었습니다."))
): ResponseEntity<RegisterFeedResponse> {
val feed = feedService.registerFeed(user.getUserId(), challengeId, request.toServiceDto())
val response = RegisterFeedResponse.of(feed)
return ResponseEntity.status(CREATED).body(response)
}

@DeleteMapping("/{challengeId}/{feedId}")
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = "피드 등록 요청 객체")
Expand All @@ -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 = "?"
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
) {

Expand All @@ -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!!)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down