Skip to content

Commit

Permalink
[fix] #98 fix api to create answer without image
Browse files Browse the repository at this point in the history
  • Loading branch information
tkdwns414 committed Jun 7, 2024
1 parent a66b041 commit 2b09dac
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.springframework.data.util.Pair;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.time.LocalDate;
Expand All @@ -47,7 +48,7 @@ public class AnswerService {
private final FcmService fcmService;
private final S3Service s3Service;

private static String ANSWER_S3_UPLOAD_FOLDER = "/answer/";
private static String ANSWER_S3_UPLOAD_FOLDER = "answer/";

@Transactional
public Answer create(
Expand All @@ -64,10 +65,14 @@ public Answer create(
ConfidenceCreateDto.of(answerCreateDto.content())
);
Double emotion = (confidence.positive() - confidence.negative()) * 0.01;

Answer answer = answerSaver.create(
Answer.create(answerCreateDto.content(),
s3Service.uploadImage(ANSWER_S3_UPLOAD_FOLDER, answerCreateDto.image()),
emotion, question, profile)
Answer.create(
answerCreateDto.content(),
uploadImage(answerCreateDto.image()),
emotion,
question,
profile)
);

profile.updateEmotion(
Expand Down Expand Up @@ -212,4 +217,10 @@ private double CalculateEmotion(
) {
return totEmotion * 0.9 + emotion * 0.1;
}

private String uploadImage(MultipartFile image) throws IOException {
if (image != null)
return s3Service.uploadImage(ANSWER_S3_UPLOAD_FOLDER, image);
return null;
}
}

0 comments on commit 2b09dac

Please sign in to comment.