Skip to content

Commit

Permalink
[feat] #82 질문 생성 S3 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
kmjenny committed Jun 7, 2024
1 parent 403e283 commit 25d3979
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,8 +29,8 @@ public ResponseEntity<Void> 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(
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/telepigeon/server/domain/Answer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -43,14 +45,17 @@ 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(
final Long userId,
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);
Expand All @@ -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(),
Expand Down

0 comments on commit 25d3979

Please sign in to comment.