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

[Issue14] 조회수 기능 구현 #15

Merged
merged 21 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7f03047
refactor: view 엔티티 내에 조회수 필드 추기
May 7, 2024
645d2f2
refactor: import 및 주석 수정
May 8, 2024
e189f00
refactor: view 레디스 캐시로 사용
May 8, 2024
92fbdb4
refactor: import 수정 및 불필요한 필드 삭제
May 8, 2024
35bbd6c
refactor: 조회수 조회 과정에서 조회수 1 증가
May 8, 2024
4cdf3c4
refactor: Redis key expiration event로 원하는 동작을 개발하는 것이 불가능하다
misim3 May 12, 2024
c2018fe
Merge branch 'develop' of https://github.com/f-lab-edu/mitube into is…
misim3 May 12, 2024
9b5f022
refactor: 인기동영상 추천 기능 일시 중지
misim3 May 15, 2024
a8a6102
refactor: SMS 본인 인증 기능 수정
misim3 May 18, 2024
5c00538
refactor: SMS 본인 인증 기능 추가 수정
misim3 May 18, 2024
75d0e75
refactor: SMS 본인 인증 기능 추가 수정
misim3 May 18, 2024
aaf7716
refactor: 회원 가입 기능 수정
misim3 May 18, 2024
fb8d4f1
refactor: 회원 가입시 약관 동의 내역과 본인 인증 내역을 회원 가입 유저와 연결하도록 수정
misim3 May 28, 2024
4e3c219
refactor: 아이디 찾기 기능을 위한 수정
misim3 May 28, 2024
f31fb29
refactor: 비밀번호 초기화 기능을 위한 수정
misim3 May 31, 2024
6fa8594
refactor: 동영상 업로드 기능 수정
misim3 Jun 8, 2024
1943ef6
refactor: 동영상 생성 및 반응 수정
misim3 Jun 9, 2024
b5457e4
refactor: 자바 구글 스타일 가이드 형식 적용
misim3 Jun 12, 2024
408d74b
refactor: 해당 동영상에 대한 View 정보 업데이트 후 가져오는 기능 수정
misim3 Jun 12, 2024
34455cf
refactor: 동영상 시청 정보 저장 기능 수정
misim3 Jun 12, 2024
b86bf41
refactor: 불필요한 import 삭제
misim3 Jun 12, 2024
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 @@ -5,6 +5,7 @@

@SpringBootApplication
public class MitubeAppApplication {

public static void main(String[] args) {
SpringApplication.run(MitubeAppApplication.class, args);
}
Expand Down
1 change: 1 addition & 0 deletions mitube-app/src/main/java/com/misim/config/JpaConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
@Configuration
@EnableJpaAuditing
public class JpaConfig {

}
16 changes: 13 additions & 3 deletions mitube-app/src/main/java/com/misim/config/RedisConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;

@Configuration
public class RedisConfig {
Expand All @@ -26,8 +26,18 @@ public RedisConnectionFactory redisConnectionFactory() {
public RedisTemplate<?, ?> redisTemplate() {
RedisTemplate<?, ?> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory());
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new StringRedisSerializer());
redisTemplate.setKeySerializer(new GenericJackson2JsonRedisSerializer());
redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
return redisTemplate;
}
//
// @Bean
// public RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {
//
// RedisMessageListenerContainer container = new RedisMessageListenerContainer();
// container.setConnectionFactory(connectionFactory);
// container.addMessageListener(listenerAdapter, new PatternTopic("keyspace"));
//
// return container;
// }
}
16 changes: 8 additions & 8 deletions mitube-app/src/main/java/com/misim/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public class SecurityConfig {
@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
return web -> web.ignoring()
.requestMatchers(
"/users/**",
"/terms/**",
"/videos/**",
"/comments/**",
"/channels/**",
"/home"
);
.requestMatchers(
"/users/**",
"/terms/**",
"/videos/**",
"/comments/**",
"/channels/**",
"/home"
);
}

@Bean
Expand Down
41 changes: 21 additions & 20 deletions mitube-app/src/main/java/com/misim/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.misim.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
Expand All @@ -15,53 +16,53 @@ public class SwaggerConfig {
@Bean
public OpenAPI openAPI() {
return new OpenAPI()
.components(new Components())
.info(apiInfo());
.components(new Components())
.info(apiInfo());
}

private Info apiInfo() {
return new Info()
.title("Mitube Api")
.description("Youtube 클론 프로젝트")
.version("1.0.0");
.title("Mitube Api")
.description("Youtube 클론 프로젝트")
.version("1.0.0");
}

@Bean
public GroupedOpenApi userGroup() {
List<Tag> tags = List.of(
new Tag().name("유저 API").description("유저 정보 관련 API")
new Tag().name("유저 API").description("유저 정보 관련 API")
);

return GroupedOpenApi.builder()
.group("유저 API")
.pathsToMatch("/users/**")
.addOpenApiCustomizer(openApi -> openApi.setTags(tags))
.build();
.group("유저 API")
.pathsToMatch("/users/**")
.addOpenApiCustomizer(openApi -> openApi.setTags(tags))
.build();
}

@Bean
public GroupedOpenApi termGroup() {
List<Tag> tags = List.of(
new Tag().name("약관 API").description("약관 정보 제공 API")
new Tag().name("약관 API").description("약관 정보 제공 API")
);

return GroupedOpenApi.builder()
.group("약관 API")
.pathsToMatch("/terms/**")
.addOpenApiCustomizer(openApi -> openApi.setTags(tags))
.build();
.group("약관 API")
.pathsToMatch("/terms/**")
.addOpenApiCustomizer(openApi -> openApi.setTags(tags))
.build();
}

@Bean
public GroupedOpenApi videoGroup() {
List<Tag> tags = List.of(
new Tag().name("동영상 API").description("동영상 정보 관련 API")
new Tag().name("동영상 API").description("동영상 정보 관련 API")
);

return GroupedOpenApi.builder()
.group("동영상 API")
.pathsToMatch("/videos/**")
.addOpenApiCustomizer(openApi -> openApi.setTags(tags))
.build();
.group("동영상 API")
.pathsToMatch("/videos/**")
.addOpenApiCustomizer(openApi -> openApi.setTags(tags))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class ChannelController {
@Operation(summary = "채널 구독", description = "채널을 구독합니다.")
@Parameter(name = "SubscribingRequest", description = "채널 구독 요청을 위한 정보", required = true)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "채널 구독 성공"),
@ApiResponse(responseCode = "400", description = "요청이 올바르지 않습니다.", content = @Content(schema = @Schema(implementation = CommonResponse.class)))
@ApiResponse(responseCode = "200", description = "채널 구독 성공"),
@ApiResponse(responseCode = "400", description = "요청이 올바르지 않습니다.", content = @Content(schema = @Schema(implementation = CommonResponse.class)))
})
@PostMapping("/subscribe")
public void subscribing(@RequestBody SubscribingRequest request) {
Expand All @@ -41,8 +41,8 @@ public void subscribing(@RequestBody SubscribingRequest request) {
@Operation(summary = "채널 구독 취소", description = "채널 구독을 취소합니다.")
@Parameter(name = "SubscribingRequest", description = "채널 구독 취소 요청을 위한 정보", required = true)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "채널 구독 취소 성공"),
@ApiResponse(responseCode = "400", description = "요청이 올바르지 않습니다.", content = @Content(schema = @Schema(implementation = CommonResponse.class)))
@ApiResponse(responseCode = "200", description = "채널 구독 취소 성공"),
@ApiResponse(responseCode = "400", description = "요청이 올바르지 않습니다.", content = @Content(schema = @Schema(implementation = CommonResponse.class)))
})
@PostMapping("/unsubscribe")
public void unsubscribing(@RequestBody SubscribingRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.misim.controller.model.Request.CreateCommentRequest;
import com.misim.controller.model.Request.UpdateCommentRequest;
import com.misim.controller.model.Response.CommentListResponse;
import com.misim.controller.model.Response.CommentResponse;
import com.misim.controller.model.Response.CreateCommentResponse;
import com.misim.exception.CommonResponse;
import com.misim.exception.MitubeErrorCode;
Expand All @@ -18,9 +17,6 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.hibernate.sql.Update;
import org.springframework.data.domain.Slice;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
Expand Down Expand Up @@ -48,46 +44,56 @@ public class CommentController {
// commentService 메소드 호출 전, scrollDirection 데이터 검사
@Operation(summary = "댓글 목록 요청", description = "동영상의 댓글 목록 10개 전달")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "댓글 목록 요청 성공"),
@ApiResponse(responseCode = "400", description = "요청이 올바르지 않습니다.", content = @Content(schema = @Schema(implementation = CommonResponse.class)))
@ApiResponse(responseCode = "200", description = "댓글 목록 요청 성공"),
@ApiResponse(responseCode = "400", description = "요청이 올바르지 않습니다.", content = @Content(schema = @Schema(implementation = CommonResponse.class)))
})
@GetMapping("/{videoId}")
public CommonResponse<CommentListResponse> getParentComments(@PathVariable @Parameter(name = "videoId", description = "시청할 동영상 식별 정보", required = true) Long videoId, @RequestParam @Parameter(name = "idx", description = "댓글의 인덱스 정보") Long idx, @RequestParam @Parameter(name = "scrollDirection", description = "댓글 목록 스크롤 방향으로 up, down만 가능하다.") String scrollDirection) {
public CommonResponse<CommentListResponse> getParentComments(
@PathVariable @Parameter(name = "videoId", description = "시청할 동영상 식별 정보", required = true) Long videoId,
@RequestParam @Parameter(name = "idx", description = "댓글의 인덱스 정보") Long idx,
@RequestParam @Parameter(name = "scrollDirection", description = "댓글 목록 스크롤 방향으로 up, down만 가능하다.") String scrollDirection) {

checkRequests(idx, scrollDirection);

CommentListResponse comments = commentService.getParentComments(videoId, idx, scrollDirection);
CommentListResponse comments = commentService.getParentComments(videoId, idx,
scrollDirection);

return CommonResponse.<CommentListResponse>builder()
.body(comments)
.build();
.body(comments)
.build();
}

@Operation(summary = "대댓글 목록 요청", description = "동영상 댓글의 대댓글 목록 10개 전달")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "대댓글 목록 요청 성공"),
@ApiResponse(responseCode = "400", description = "요청이 올바르지 않습니다.", content = @Content(schema = @Schema(implementation = CommonResponse.class)))
@ApiResponse(responseCode = "200", description = "대댓글 목록 요청 성공"),
@ApiResponse(responseCode = "400", description = "요청이 올바르지 않습니다.", content = @Content(schema = @Schema(implementation = CommonResponse.class)))
})
@GetMapping("/{videoId}/{parentCommentId}")
public CommonResponse<CommentListResponse> getChildComments(@PathVariable @Parameter(name = "videoId", description = "시청할 동영상 식별 정보", required = true) Long videoId, @PathVariable @Parameter(name = "parentCommentId", description = "대댓글이 달린 댓글의 식별 정보") Long parentCommentId, @RequestParam @Parameter(name = "idx", description = "댓글의 인덱스 정보") Long idx, @RequestParam @Parameter(name = "scrollDirection", description = "댓글 목록 스크롤 방향으로 up, down만 가능하다.") String scrollDirection) {
public CommonResponse<CommentListResponse> getChildComments(
@PathVariable @Parameter(name = "videoId", description = "시청할 동영상 식별 정보", required = true) Long videoId,
@PathVariable @Parameter(name = "parentCommentId", description = "대댓글이 달린 댓글의 식별 정보") Long parentCommentId,
@RequestParam @Parameter(name = "idx", description = "댓글의 인덱스 정보") Long idx,
@RequestParam @Parameter(name = "scrollDirection", description = "댓글 목록 스크롤 방향으로 up, down만 가능하다.") String scrollDirection) {

checkRequests(idx, scrollDirection);

CommentListResponse comments = commentService.getChildComments(videoId, parentCommentId, idx, scrollDirection);
CommentListResponse comments = commentService.getChildComments(videoId, parentCommentId,
idx, scrollDirection);

return CommonResponse.<CommentListResponse>builder()
.body(comments)
.build();
.body(comments)
.build();
}

@Operation(summary = "댓글 생성", description = "동영상 댓글을 생성합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "댓글 생성 성공"),
@ApiResponse(responseCode = "400", description = "요청이 올바르지 않습니다.", content = @Content(schema = @Schema(implementation = CommonResponse.class)))
@ApiResponse(responseCode = "200", description = "댓글 생성 성공"),
@ApiResponse(responseCode = "400", description = "요청이 올바르지 않습니다.", content = @Content(schema = @Schema(implementation = CommonResponse.class)))
})
@PostMapping("/create")
public CommonResponse<CreateCommentResponse> createComments(@RequestBody CreateCommentRequest request) {

public CommonResponse<CreateCommentResponse> createComments(
@RequestBody CreateCommentRequest request) {

request.check();

CreateCommentResponse response = commentService.createComments(request);
Expand All @@ -97,8 +103,8 @@ public CommonResponse<CreateCommentResponse> createComments(@RequestBody CreateC

@Operation(summary = "댓글 수정", description = "동영상 댓글을 수정합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "댓글 수정 성공"),
@ApiResponse(responseCode = "400", description = "요청이 올바르지 않습니다.", content = @Content(schema = @Schema(implementation = CommonResponse.class)))
@ApiResponse(responseCode = "200", description = "댓글 수정 성공"),
@ApiResponse(responseCode = "400", description = "요청이 올바르지 않습니다.", content = @Content(schema = @Schema(implementation = CommonResponse.class)))
})
@PostMapping("/update")
public void updateComments(@RequestBody UpdateCommentRequest request) {
Expand All @@ -110,8 +116,8 @@ public void updateComments(@RequestBody UpdateCommentRequest request) {

@Operation(summary = "댓글 삭제", description = "동영상 댓글을 삭제합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "댓글 삭제 성공"),
@ApiResponse(responseCode = "400", description = "요청이 올바르지 않습니다.", content = @Content(schema = @Schema(implementation = CommonResponse.class)))
@ApiResponse(responseCode = "200", description = "댓글 삭제 성공"),
@ApiResponse(responseCode = "400", description = "요청이 올바르지 않습니다.", content = @Content(schema = @Schema(implementation = CommonResponse.class)))
})
@PostMapping("/delete")
public void deleteComments(@RequestBody CommentDto request) {
Expand All @@ -124,7 +130,7 @@ public void deleteComments(@RequestBody CommentDto request) {
private void checkRequests(Long idx, String scrollDirection) {

if (idx < 1) {
throw new MitubeException(MitubeErrorCode.INVALID_COMMENT_INDEX);
throw new MitubeException(MitubeErrorCode.INVALID_COMMENT_INDEX);
}

if (scrollDirection.isBlank() || !scroll.contains(scrollDirection)) {
Expand Down
19 changes: 8 additions & 11 deletions mitube-app/src/main/java/com/misim/controller/MainController.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.misim.controller;

import com.misim.controller.model.Response.HomeResponse;
import com.misim.entity.VideoCategory;
import com.misim.exception.CommonResponse;
import com.misim.service.HomeService;
import com.misim.service.VideoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
Expand All @@ -16,27 +14,26 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

@RestController
@RequiredArgsConstructor
public class MainController {

private final HomeService homeService;

@Operation(summary = "메인 화면 데이터 전송", description = "메인 화면에 필요한 데이터 전송")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "메인 화면 데이터 전송 성공"),
@ApiResponse(responseCode = "400", description = "요청이 올바르지 않습니다.", content = @Content(schema = @Schema(implementation = CommonResponse.class)))
@ApiResponse(responseCode = "200", description = "메인 화면 데이터 전송 성공"),
@ApiResponse(responseCode = "400", description = "요청이 올바르지 않습니다.", content = @Content(schema = @Schema(implementation = CommonResponse.class)))
})
@GetMapping("/home")
public CommonResponse<HomeResponse> home(@RequestParam @Parameter(name = "userId", description = "Mitube에 접속한 유저 식별 정보로, 비로그인 사용자의 경우 null로 요청된다.") Long userId) {
public CommonResponse<HomeResponse> home(
@RequestParam @Parameter(name = "userId", description = "Mitube에 접속한 유저 식별 정보로, 비로그인 사용자의 경우 null로 요청된다.") Long userId) {

HomeResponse response = homeService.getHome(userId);

return CommonResponse
.<HomeResponse>builder()
.body(response)
.build();
.<HomeResponse>builder()
.body(response)
.build();
}
}
Loading
Loading