Skip to content

Commit

Permalink
Merge pull request #30 from kakao-tech-campus-2nd-step3/refactor/#29-…
Browse files Browse the repository at this point in the history
…swaggerAndConvention

[Refactor] #29 Swagger 코드 스타일과 패키지 네이밍 컨벤션을 맞춰 보아요
  • Loading branch information
sanghee0820 authored Oct 4, 2024
2 parents 7738f1d + f5862b1 commit 5f76bdf
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public final class AliasUtil {
private final Template template;
public static String makeAlias(String influencerName, Category category){
String alias = mapTemplateToCategory(category);
return influencerName + " " + alias;
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/team7/inplace/video/application/Template.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package team7.inplace.video.application;

import lombok.Getter;
import team7.inplace.place.domain.Category;

import java.util.*;

@Getter
public enum Template {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class VideoService {
private final InfluencerRepository influencerRepository;
private final PlaceRepository placeRepository;

public List<VideoInfo> findByInfluencer(List<String> influencers) {
public List<VideoInfo> getByVideosInfluencer(List<String> influencers) {
// 인플루언서 정보 처리
List<Long> influencerIds = influencerRepository.findByNameIn(influencers).stream()
.map(Influencer::getId)
Expand All @@ -37,15 +37,15 @@ public List<VideoInfo> findByInfluencer(List<String> influencers) {
return videoToInfo(savedVideos);
}

public List<VideoInfo> findAllDesc() {
public List<VideoInfo> getAllVideosDesc() {
// id를 기준으로 내림차순 정렬하여 비디오 정보 불러오기
List<Video> savedVideos = videoRepository.findAllByOrderByIdDesc();

// DTO 형식에 맞게 대입
return videoToInfo(savedVideos);
}

public List<VideoInfo> findBySurround(VideoSearchParams videoSearchParams, Pageable pageable) {
public List<VideoInfo> getVideosBySurround(VideoSearchParams videoSearchParams, Pageable pageable) {
Page<Place> placesByDistance = placeRepository.getPlacesByDistance(
videoSearchParams.longitude(),
videoSearchParams.latitude(),
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/team7/inplace/video/domain/Video.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
Expand All @@ -14,13 +13,16 @@
import team7.inplace.influencer.domain.Influencer;
import team7.inplace.place.domain.Place;

import static lombok.AccessLevel.PROTECTED;
import static jakarta.persistence.GenerationType.IDENTITY;

@Entity
@Getter
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
@NoArgsConstructor(access = PROTECTED)
@RequiredArgsConstructor // 테스팅을 위한 부분 추가, 협의 하에 다른 방식 채택 가능
public class Video {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@GeneratedValue(strategy = IDENTITY)
private Long id;
@Column(name = "video_url", nullable = false, columnDefinition = "TEXT")
@NonNull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package team7.inplace.video.presentation;

import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.PageRequest;
Expand All @@ -19,15 +18,11 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/videos")
public class VideoController {
public class VideoController implements VideoControllerApiSpec{
private final VideoService videoService;

// 토큰 필요 메서드
@GetMapping()
@Operation(
summary = "내 인플루언서가 방문한 or 내 주변 그곳 ",
description = "토큰의 유무에 따라 다른 동작을 수행합니다."
)
public ResponseEntity<List<VideoResponse>> readVideos(
HttpServletRequest request,
@RequestParam(name = "influencer", required = false) List<String> influencers,
Expand All @@ -50,29 +45,27 @@ public ResponseEntity<List<VideoResponse>> readVideos(
}

private ResponseEntity<List<VideoResponse>> readByInfluencer(List<String> influencers){
List<VideoInfo> videoInfos = videoService.findByInfluencer(influencers);
List<VideoInfo> videoInfos = videoService.getByVideosInfluencer(influencers);
List<VideoResponse> videoResponses = videoInfos.stream().map(VideoResponse::from).toList();
return new ResponseEntity<>(videoResponses, HttpStatus.OK);
}

private ResponseEntity<List<VideoResponse>> readBySurround(VideoSearchParams searchParams, int page, int size) {
Pageable pageable = PageRequest.of(page, size);
List<VideoInfo> videoInfos = videoService.findBySurround(searchParams, pageable);
List<VideoInfo> videoInfos = videoService.getVideosBySurround(searchParams, pageable);
List<VideoResponse> videoResponses = videoInfos.stream().map(VideoResponse::from).toList();
return new ResponseEntity<>(videoResponses, HttpStatus.OK);
}

@GetMapping("/new")
@Operation(summary = "새로 등록된 그 곳", description = "id를 기준으로 내림차순 정렬한 Video 정보를 조회합니다.")
public ResponseEntity<List<VideoResponse>> readByNew() {
List<VideoInfo> videoInfos = videoService.findAllDesc();
List<VideoInfo> videoInfos = videoService.getAllVideosDesc();
List<VideoResponse> videoResponses = videoInfos.stream().map(VideoResponse::from).toList();
return new ResponseEntity<>(videoResponses, HttpStatus.OK);
}

// 조회수 반환 기능 개발 시 개발
@GetMapping("/cool")
@Operation(summary = "쿨한 그 곳", description = "조회수를 기준으로 내림차순 정렬한 Video 정보를 조회합니다.")
public ResponseEntity<List<VideoResponse>> readByCool() {
List<VideoResponse> videoResponses = new ArrayList<>();
return new ResponseEntity<>(videoResponses, HttpStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package team7.inplace.video.presentation;

import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestParam;
import team7.inplace.video.presentation.dto.VideoResponse;
import team7.inplace.video.presentation.dto.VideoSearchParams;

import java.util.List;


public interface VideoControllerApiSpec {
@Operation(
summary = "내 인플루언서가 방문한 or 내 주변 그곳 ",
description = "토큰의 유무에 따라 다른 동작을 수행합니다."
)
public ResponseEntity<List<VideoResponse>> readVideos(
HttpServletRequest request,
@RequestParam(name = "influencer", required = false) List<String> influencers,
@ModelAttribute VideoSearchParams searchParams,
@RequestParam(defaultValue = "0", required = false) int page,
@RequestParam(defaultValue = "10", required = false) int size
);

@Operation(summary = "새로 등록된 그 곳", description = "id를 기준으로 내림차순 정렬한 Video 정보를 조회합니다.")
public ResponseEntity<List<VideoResponse>> readByNew();

@Operation(summary = "쿨한 그 곳", description = "조회수를 기준으로 내림차순 정렬한 Video 정보를 조회합니다.")
public ResponseEntity<List<VideoResponse>> readByCool();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package team7.inplace.video.service;
package team7.inplace.video.application;

import static org.mockito.BDDMockito.given;

Expand All @@ -21,7 +21,6 @@
import team7.inplace.place.domain.Menu;
import team7.inplace.place.domain.Place;
import team7.inplace.place.domain.PlaceOpenTime;
import team7.inplace.video.application.VideoService;
import team7.inplace.video.application.dto.VideoInfo;
import team7.inplace.video.domain.Video;
import team7.inplace.video.persistence.VideoRepository;
Expand Down Expand Up @@ -85,7 +84,7 @@ void test1() {
invocation -> savedVideos);

// when
List<VideoInfo> savedVideoData = videoService.findByInfluencer(names);
List<VideoInfo> savedVideoData = videoService.getByVideosInfluencer(names);
// then
Assertions.assertThat(savedVideoData.get(0).place().placeName()).isEqualTo(place.getName());
Assertions.assertThat(savedVideoData.get(0).videoUrl()).isEqualTo("url");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package team7.inplace.video.repository;
package team7.inplace.video.persistence;

import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
Expand All @@ -20,7 +20,6 @@
import team7.inplace.place.domain.Place;
import team7.inplace.place.domain.PlaceOpenTime;
import team7.inplace.video.domain.Video;
import team7.inplace.video.persistence.VideoRepository;

@DataJpaTest
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) // 각 메서드 실행마다 이전 결과 초기화
Expand Down

0 comments on commit 5f76bdf

Please sign in to comment.