Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] #5 videoAlias 정보를 랜덤하게 매핑해주는 기능을 구현했어요! #16

Merged
merged 19 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 16 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
26 changes: 26 additions & 0 deletions src/main/java/team7/inplace/influencer/entity/Influencer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package team7.inplace.influencer.entity;

import jakarta.persistence.*;
import lombok.*;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@RequiredArgsConstructor // 테스팅을 위한 부분 추가, 협의 하에 다른 방식 채택 가능
public class Influencer {
/*
* 더미 데이터 입니다 !!!
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column
@NonNull
private String name;
@Column
@NonNull
private String job;
@Column
@NonNull
private String imgUrl;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package team7.inplace.video.repository;
package team7.inplace.influencer.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import team7.inplace.video.entity.Influencer;
import team7.inplace.influencer.entity.Influencer;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package team7.inplace.video.DTO;
package team7.inplace.place.dto;

public record PlaceForVideo(Long placeId, String placeName) {
}
4 changes: 0 additions & 4 deletions src/main/java/team7/inplace/video/DTO/VideoData.java

This file was deleted.

7 changes: 0 additions & 7 deletions src/main/java/team7/inplace/video/DTO/VideoResponse.java

This file was deleted.

78 changes: 78 additions & 0 deletions src/main/java/team7/inplace/video/application/VideoService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package team7.inplace.video.application;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import team7.inplace.place.domain.Category;
import team7.inplace.place.dto.PlaceForVideo;
import team7.inplace.video.application.dto.VideoInfo;
import team7.inplace.influencer.entity.Influencer;
import team7.inplace.video.domain.Video;
import team7.inplace.influencer.repository.InfluencerRepository;
import team7.inplace.video.persistence.VideoRepository;

import java.util.*;

@Service
@RequiredArgsConstructor
public class VideoService {
private static final Map<Category, List<String>> template = new HashMap<>();
private final VideoRepository videoRepository;
private final InfluencerRepository influencerRepository;

// 더 나은 로직이 존재하면 건의 부탁합니다
static {
template.put(Category.CAFE, Arrays.asList(
"이(가) 방문한 카페에서 따뜻한 커피를 즐겨보세요!",
"이(가) 방문했던 카페에서 여유로운 시간을 보내보세요!",
"이(가) 추천하는 사진 명소 예쁜 카페에 방문해보세요!"
));

template.put(Category.WESTERN, Arrays.asList(
"이(가) 추천! 맛있는 서양 음식을 즐길 수 있는 곳!",
"이(가) 추천하는 고급스러운 서양 요리를 맛볼 수 있습니다.",
"이(가) 극찬! 서양식 디저트를 꼭 한 번 시도해보세요!"
));

template.put(Category.JAPANESE, Arrays.asList(
"피셜, 현지와 다름없는 정통 일본 요리 레스토랑.",
"이(가) 추천하는 맛있는 일본 초밥과 라멘을 즐겨보세요.",
"이(가) 극찬! 일본 요리의 정수를 느껴보세요."
));

template.put(Category.KOREAN, Arrays.asList(
"이(가) 전통 한식을 맛볼 수 있는 한식당입니다.",
"이(가) 추천하는 가게에서 정성스럽게 준비된 한식으로 든든한 한 끼를!",
"이(가) 극찬! 한식의 깊은 맛을 느껴보세요."
));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어떻게 하면 좋을 진 잘 모르겠으나 template을 클래스로 분리해서 makeAlias()를 Service에서 분리하는게 어떨까 싶네요.
Service에서 해야할 일이 아닌것 같아요.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

듣고보니 그런 것 같습니다 분리하겠습니당


public List<VideoInfo> findByInfluencer(List<String> influencers) {
// 인플루언서 정보 처리
List<Long> influencerIds = influencerRepository.findByNameIn(influencers).stream()
BaeJunH0 marked this conversation as resolved.
Show resolved Hide resolved
.map(Influencer::getId)
.toList();

// 인플루언서 정보로 필터링한 비디오 정보 불러오기
List<Video> savedVideos = videoRepository.findVideosByInfluencerIdIn(influencerIds);
Comment on lines +24 to +29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

나중에 Join해서 한번에 가져와도 괜찮을 것 같아요!


// 변수명 변경 가능
List<VideoInfo> videoInfos = new ArrayList<>();

// DTO 형식에 맞게 대입
for (Video savedVideo : savedVideos) {
PlaceForVideo placeForVideo = new PlaceForVideo(savedVideo.getPlace().getPlaceId(), savedVideo.getPlace().getName());
String alias = makeAlias(savedVideo.getInfluencer().getName(), savedVideo.getPlace().getCategory());
videoInfos.add(new VideoInfo(savedVideo.getId(), alias, savedVideo.getVideoUrl(), placeForVideo));
}

return videoInfos;
}

private String makeAlias(String influencerName, Category category) {
List<String> syntax = template.get(category);

Random random = new Random();
int randomNumber = random.nextInt(syntax.size());
return influencerName + " " + syntax.get(randomNumber);
}
}
12 changes: 12 additions & 0 deletions src/main/java/team7/inplace/video/application/dto/VideoInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package team7.inplace.video.application.dto;

import team7.inplace.place.dto.PlaceForVideo;

// Video 도메인의 Controller와 Service 사이의 정보 전달을 담당하는 클래스 ( Service Return )
public record VideoInfo(
Long videoId,
String videoAlias,
String videoUrl,
PlaceForVideo place
) {
}
32 changes: 0 additions & 32 deletions src/main/java/team7/inplace/video/controller/VideoController.java

This file was deleted.

30 changes: 30 additions & 0 deletions src/main/java/team7/inplace/video/domain/Video.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package team7.inplace.video.domain;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import team7.inplace.influencer.entity.Influencer;
import team7.inplace.place.domain.Place;

@Entity
@Getter
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static 으로 나중에 변경할게요~!

@RequiredArgsConstructor // 테스팅을 위한 부분 추가, 협의 하에 다른 방식 채택 가능
public class Video {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "video_url", nullable = false, columnDefinition = "TEXT")
@NonNull
private String videoUrl;
@ManyToOne
@JoinColumn(name = "influencer_id", nullable = false)
@NonNull
private Influencer influencer;
@ManyToOne
@JoinColumn(name = "place_id", nullable = false)
@NonNull
private Place place;
}
26 changes: 0 additions & 26 deletions src/main/java/team7/inplace/video/entity/Influencer.java

This file was deleted.

22 changes: 0 additions & 22 deletions src/main/java/team7/inplace/video/entity/Place.java

This file was deleted.

22 changes: 0 additions & 22 deletions src/main/java/team7/inplace/video/entity/Video.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package team7.inplace.video.repository;
package team7.inplace.video.persistence;

import org.springframework.data.jpa.repository.JpaRepository;
import team7.inplace.video.entity.Video;
import team7.inplace.video.domain.Video;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package team7.inplace.video.presentation;

import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import team7.inplace.video.application.dto.VideoInfo;
import team7.inplace.video.presentation.dto.VideoResponse;
import team7.inplace.video.application.VideoService;

import java.util.List;

@RestController
@RequiredArgsConstructor
public class VideoController {
private final VideoService videoService;

// 내 인플루언서가 방문한 그 곳 ( 토큰 0 )
@GetMapping("/video")
public ResponseEntity<List<VideoResponse>> readByInfluencer(
@RequestParam(name = "influencer", required = false) List<String> influencers
) {
List<VideoInfo> videoInfos = videoService.findByInfluencer(influencers);
List<VideoResponse> videoResponses = videoInfos.stream().map(VideoResponse::new).toList();
return new ResponseEntity<>(videoResponses, HttpStatus.OK);
}
}
Comment on lines +17 to +29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swagger에 대한 명세가 존재하지 않네요!!

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package team7.inplace.video.presentation.dto;

import team7.inplace.place.dto.PlaceForVideo;
import team7.inplace.video.application.dto.VideoInfo;

// Video 엔티티의 Controller Response 정보 전달을 담당하는 클래스
public record VideoResponse(
Long videoId,
String videoAlias,
String videoUrl,
PlaceForVideo place
) {
public VideoResponse(VideoInfo videoData) {
this(videoData.videoId(), videoData.videoAlias(), videoData.videoUrl(), videoData.place());
}
BaeJunH0 marked this conversation as resolved.
Show resolved Hide resolved
}
45 changes: 0 additions & 45 deletions src/main/java/team7/inplace/video/service/VideoService.java

This file was deleted.

Loading
Loading