-
Notifications
You must be signed in to change notification settings - Fork 2
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
Changes from 16 commits
46ceedd
3360ca7
4ae6052
cdac49b
5e97e5e
021d8e5
8e9e4ba
9658684
3cce303
9d6f36d
bd94b61
21c15f6
edd50b4
8f13bc9
8ed9e3f
7a93e84
52f1845
a935c53
c3dcb5f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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,4 +1,4 @@ | ||
package team7.inplace.video.DTO; | ||
package team7.inplace.place.dto; | ||
|
||
public record PlaceForVideo(Long placeId, String placeName) { | ||
} |
This file was deleted.
This file was deleted.
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( | ||
"이(가) 전통 한식을 맛볼 수 있는 한식당입니다.", | ||
"이(가) 추천하는 가게에서 정성스럽게 준비된 한식으로 든든한 한 끼를!", | ||
"이(가) 극찬! 한식의 깊은 맛을 느껴보세요." | ||
)); | ||
} | ||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
} |
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 | ||
) { | ||
} |
This file was deleted.
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} |
This file was deleted.
This file was deleted.
This file was deleted.
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
어떻게 하면 좋을 진 잘 모르겠으나 template을 클래스로 분리해서 makeAlias()를 Service에서 분리하는게 어떨까 싶네요.
Service에서 해야할 일이 아닌것 같아요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
듣고보니 그런 것 같습니다 분리하겠습니당