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

[Refactor] #29 Swagger 코드 스타일과 패키지 네이밍 컨벤션을 맞춰 보아요 #30

Merged
merged 7 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
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
7 changes: 5 additions & 2 deletions src/main/java/team7/inplace/video/domain/Video.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,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{
Copy link
Contributor

Choose a reason for hiding this comment

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

사소하지만 코드 컨벤션에 어긋나요!

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
Comment on lines +20 to +24
Copy link
Contributor

Choose a reason for hiding this comment

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

이거 잘 되나요??? 여기서 선언했을 때 잘 되는지 확인한번만 하고 알려주시면 감사하겠습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

아직 데이터가 들어간게 없어서 로직은 잘 모르겠는데, 포스트맨으로 API 요청했을때는 오류 안나고 잘되었습니다

);

@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 @@ -16,7 +16,6 @@
import team7.inplace.influencer.domain.Influencer;
import team7.inplace.influencer.persistence.InfluencerRepository;
import team7.inplace.place.domain.*;
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
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 @@ -15,7 +15,6 @@
import team7.inplace.influencer.domain.Influencer;
import team7.inplace.place.domain.*;
import team7.inplace.video.domain.Video;
import team7.inplace.video.persistence.VideoRepository;

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