Skip to content

Commit

Permalink
✨ Feature: 그림 및 감정 더미데이터 추가 (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnsugyeong authored May 26, 2024
1 parent 92642a6 commit e058f36
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public ResponseDto<JwtResponse> signUp(@RequestBody SignInRequest request) {
})
@Operation(summary = "이메일 사용 가능 여부 확인", description = "제공된 이메일이 등록에 사용 가능한지 확인합니다.")
@GetMapping("/check-email")
public ResponseDto<Boolean> checkEmailAvailability(@RequestParam String email) {
public ResponseDto<Boolean> checkEmailAvailability(@RequestParam("email") String email) {
return ResponseDto.onSuccess(authFacade.isEmailAvailable(email));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import zzangdol.diary.presentation.dto.response.DiaryListResponse;
import zzangdol.diary.presentation.dto.response.DiaryResponse;
import zzangdol.diary.presentation.dto.response.ImageListResponse;
import zzangdol.emotion.dao.querydsl.EmotionQueryRepository;
import zzangdol.emotion.domain.Emotion;
import zzangdol.user.domain.User;

Expand All @@ -22,20 +23,25 @@ public class DiaryFacade {

private final DiaryCommandService diaryCommandService;
private final DiaryQueryService diaryQueryService;
private final EmotionQueryRepository emotionQueryRepository; // TODO 구현 후 제거
// private final TextEmotionAnalysisModelClient textEmotionAnalysisModelClient;
// private final Text2ImageModelClient text2ImageModelClient;
private final ImageColorAnalyzer imageColorAnalyzer;

public Long createDiary(User user, DiaryCreateRequest request) {
// TODO List<Emotion> emotions = textEmotionAnalysisModelClient.analyzeEmotion(request.getContent());
List<Emotion> emotions = new ArrayList<>();
List<Emotion> emotions = emotionQueryRepository.findRandomEmotions(3);
String color = imageColorAnalyzer.analyzeAverageColorAsHex(request.getImageUrl());
return diaryCommandService.createDiary(user, request, color, emotions).getId();
}

public ImageListResponse createDiaryImage(User user, ImageCreateRequest request) {
// List<String> imageUrls = text2ImageModelClient.generateImage(request.getContent());
List<String> imageUrls = new ArrayList<>();
imageUrls.add("https://moodoodle-diary-image.s3.ap-northeast-2.amazonaws.com/diary_image_1.png");
imageUrls.add("https://moodoodle-diary-image.s3.ap-northeast-2.amazonaws.com/diary_image_2.png");
imageUrls.add("https://moodoodle-diary-image.s3.ap-northeast-2.amazonaws.com/diary_image_3.png");
imageUrls.add("https://moodoodle-diary-image.s3.ap-northeast-2.amazonaws.com/diary_image_4.png");
return DiaryMapper.toImageResponse(imageUrls);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,24 @@
import zzangdol.diary.presentation.dto.response.DiaryResponse;
import zzangdol.diary.presentation.dto.response.DiarySummaryResponse;
import zzangdol.diary.presentation.dto.response.ImageListResponse;
import zzangdol.emotion.business.EmotionMapper;
import zzangdol.emotion.presentation.dto.response.EmotionResponse;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class DiaryMapper {

public static DiaryResponse toDiaryResponse(Diary diary) {
List<EmotionResponse> emotions = diary.getDiaryEmotions().stream()
.map(diaryEmotion -> EmotionMapper.toEmotionResponse(diaryEmotion.getEmotion()))
.collect(Collectors.toList());

return DiaryResponse.builder()
.id(diary.getId())
.date(diary.getDate())
.content(diary.getContent())
.imageUrl(diary.getPainting().getImageUrl())
.color(diary.getPainting().getColor())
.emotions(emotions)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import java.time.LocalDate;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -16,6 +15,6 @@ public class ImageCreateRequest {

@Schema(example = "오늘은 오랜만에 친구들과 놀이공원에 다녀왔다. 정말 신나는 하루였다. 집에 돌아오는 길에는 조금 허전하고 아쉬운 마음도 들었지만, 오늘 하루 친구들과 함께 할 수 있어서 정말 행복했다.")
@NotEmpty(message = "content는 필수값입니다.")
private LocalDate content;
private String content;

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package zzangdol.diary.presentation.dto.response;

import java.time.LocalDate;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import zzangdol.emotion.presentation.dto.response.EmotionResponse;

@Builder
@Getter
Expand All @@ -17,5 +19,6 @@ public class DiaryResponse {
private String content;
private String imageUrl;
private String color;
private List<EmotionResponse> emotions;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package zzangdol.emotion.business;

import zzangdol.emotion.domain.Emotion;
import zzangdol.emotion.presentation.dto.response.EmotionResponse;

public class EmotionMapper {

public static EmotionResponse toEmotionResponse(Emotion emotion) {
return EmotionResponse.builder()
.name(emotion.getName())
.imageUrl(emotion.getImageUrl())
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package zzangdol.emotion.presentation.dto.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class EmotionResponse {

private String name;
private String imageUrl;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package zzangdol.emotion.dao.querydsl;

import java.util.List;
import zzangdol.emotion.domain.Emotion;

public interface EmotionQueryRepository {

List<Emotion> findRandomEmotions(int limit);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package zzangdol.emotion.dao.querydsl;

import static zzangdol.emotion.domain.QEmotion.emotion;

import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
import zzangdol.emotion.domain.Emotion;

@RequiredArgsConstructor
@Repository
public class EmotionQueryRepositoryImpl implements EmotionQueryRepository {

private final JPAQueryFactory queryFactory;

@Override
public List<Emotion> findRandomEmotions(int limit) {
return queryFactory.selectFrom(emotion)
.orderBy(com.querydsl.core.types.dsl.Expressions.numberTemplate(Double.class, "function('RAND')").asc())
.limit(limit)
.fetch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ public class Emotion extends BaseTimeEntity {

private String name;

private String imageUrl;

@Enumerated(EnumType.STRING)
private EmotionPolarity polarity;

@Builder
public Emotion(String name, EmotionPolarity polarity) {
public Emotion(String name, String imageUrl, EmotionPolarity polarity) {
this.name = name;
this.imageUrl = imageUrl;
this.polarity = polarity;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.redis.core.RedisHash;
import org.springframework.data.redis.core.TimeToLive;
import org.springframework.data.redis.core.index.Indexed;

@Getter
@NoArgsConstructor
@RedisHash(value = "emailVerificationToken")
public class EmailVerificationToken {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.redis.core.RedisHash;
import org.springframework.data.redis.core.TimeToLive;
import org.springframework.data.redis.core.index.Indexed;

@Getter
@NoArgsConstructor
@RedisHash(value = "refreshToken")
public class RefreshToken {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.redis.core.RedisHash;
import org.springframework.data.redis.core.TimeToLive;
import org.springframework.data.redis.core.index.Indexed;

@Getter
@NoArgsConstructor
@RedisHash(value = "verificationCode")
public class VerificationCode {

Expand Down

0 comments on commit e058f36

Please sign in to comment.