diff --git a/src/main/java/com/telepigeon/server/controller/AnswerController.java b/src/main/java/com/telepigeon/server/controller/AnswerController.java index 969bcc2..8ae202d 100644 --- a/src/main/java/com/telepigeon/server/controller/AnswerController.java +++ b/src/main/java/com/telepigeon/server/controller/AnswerController.java @@ -13,6 +13,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.io.IOException; import java.net.URI; import java.time.LocalDate; import java.time.YearMonth; @@ -28,8 +29,8 @@ public ResponseEntity postAnswer( @UserId final Long userId, @PathVariable final Long roomId, @PathVariable final Long questionId, - @RequestBody @Valid final AnswerCreateDto answerCreateDto - ) { + @ModelAttribute @Valid final AnswerCreateDto answerCreateDto + ) throws IOException { return ResponseEntity.created( URI.create( "/answers/" + answerService.create( diff --git a/src/main/java/com/telepigeon/server/domain/Answer.java b/src/main/java/com/telepigeon/server/domain/Answer.java index 8640276..b4a6103 100644 --- a/src/main/java/com/telepigeon/server/domain/Answer.java +++ b/src/main/java/com/telepigeon/server/domain/Answer.java @@ -39,14 +39,15 @@ public class Answer { private Profile profile; public static Answer create( - AnswerCreateDto answerCreateDto, + String content, + String image, Double emotion, Question question, Profile profile ){ return new Answer( - answerCreateDto.content(), - answerCreateDto.image(), + content, + image, emotion, question, profile); diff --git a/src/main/java/com/telepigeon/server/dto/answer/request/AnswerCreateDto.java b/src/main/java/com/telepigeon/server/dto/answer/request/AnswerCreateDto.java index b8fe346..b098265 100644 --- a/src/main/java/com/telepigeon/server/dto/answer/request/AnswerCreateDto.java +++ b/src/main/java/com/telepigeon/server/dto/answer/request/AnswerCreateDto.java @@ -2,11 +2,12 @@ import jakarta.annotation.Nullable; import jakarta.validation.constraints.NotBlank; +import org.springframework.web.multipart.MultipartFile; public record AnswerCreateDto( @NotBlank String content, @Nullable - String image + MultipartFile image ) { } diff --git a/src/main/java/com/telepigeon/server/service/answer/AnswerService.java b/src/main/java/com/telepigeon/server/service/answer/AnswerService.java index 57ffbf1..36cb282 100644 --- a/src/main/java/com/telepigeon/server/service/answer/AnswerService.java +++ b/src/main/java/com/telepigeon/server/service/answer/AnswerService.java @@ -11,6 +11,7 @@ import com.telepigeon.server.dto.naverCloud.ConfidenceDto; import com.telepigeon.server.dto.room.response.RoomStateDto; import com.telepigeon.server.dto.type.FcmContent; +import com.telepigeon.server.service.external.S3Service; import com.telepigeon.server.service.fcm.FcmService; import com.telepigeon.server.service.external.NaverCloudService; import com.telepigeon.server.service.user.UserRetriever; @@ -23,6 +24,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.io.IOException; import java.time.LocalDate; import java.time.YearMonth; import java.util.Collections; @@ -43,6 +45,9 @@ public class AnswerService { private final HurryRetriever hurryRetriever; private final NaverCloudService naverCloudService; private final FcmService fcmService; + private final S3Service s3Service; + + private static String ANSWER_S3_UPLOAD_FOLDER = "/answer"; @Transactional public Answer create( @@ -50,7 +55,7 @@ public Answer create( final Long roomId, final Long questionId, final AnswerCreateDto answerCreateDto - ){ + ) throws IOException { User user = userRetriever.findById(userId); Room room = roomRetriever.findById(roomId); Profile profile = profileRetriever.findByUserAndRoom(user, room); @@ -60,8 +65,11 @@ public Answer create( ); Double emotion = (confidence.positive() - confidence.negative()) * 0.01; Answer answer = answerSaver.create( - Answer.create(answerCreateDto, emotion, question, profile) + Answer.create(answerCreateDto.content(), + s3Service.uploadImage(ANSWER_S3_UPLOAD_FOLDER, answerCreateDto.image()), + emotion, question, profile) ); + profile.updateEmotion( CalculateEmotion( profile.getEmotion(),