-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from HongikGraduationProject/video
Video
- Loading branch information
Showing
19 changed files
with
206 additions
and
24 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/main/java/com/hongik/graduationproject/config/WebConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.hongik.graduationproject.config; | ||
|
||
import com.hongik.graduationproject.config.converter.MainCategoryRequestConverter; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.format.FormatterRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
public class WebConfig implements WebMvcConfigurer { | ||
@Override | ||
public void addFormatters(FormatterRegistry registry) { | ||
registry.addConverter(new MainCategoryRequestConverter()); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...main/java/com/hongik/graduationproject/config/converter/MainCategoryRequestConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.hongik.graduationproject.config.converter; | ||
|
||
import com.hongik.graduationproject.eum.MainCategory; | ||
import com.hongik.graduationproject.exception.AppException; | ||
import com.hongik.graduationproject.exception.ErrorCode; | ||
import org.springframework.core.convert.ConversionFailedException; | ||
import org.springframework.core.convert.converter.Converter; | ||
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; | ||
|
||
public class MainCategoryRequestConverter implements Converter<String, MainCategory> { | ||
@Override | ||
public MainCategory convert(String source) { | ||
return MainCategory.valueOf(source.toUpperCase()); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/hongik/graduationproject/controller/CategoryController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.hongik.graduationproject.controller; | ||
|
||
import com.hongik.graduationproject.domain.dto.Response; | ||
import com.hongik.graduationproject.domain.dto.category.SubCategoryListResponse; | ||
import com.hongik.graduationproject.domain.dto.video.VideoSummaryListResponse; | ||
import com.hongik.graduationproject.eum.MainCategory; | ||
import com.hongik.graduationproject.service.CategoryService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api") | ||
public class CategoryController { | ||
private final CategoryService categoryService; | ||
|
||
@Operation(summary = "서브 카테고리 목록 조회", description = "사용자의 특정 메인 카테고리에 해당하는 서브 카테고리 목록 조회를 위한 메소드") | ||
@ApiResponse(content = @Content(schema = @Schema(implementation = SubCategoryListResponse.class))) | ||
@ResponseStatus(HttpStatus.OK) | ||
@GetMapping("/categories") | ||
public Response<SubCategoryListResponse> getSubCategoryList(@RequestParam MainCategory mainCategory) { | ||
return Response.createSuccess(categoryService.getSubCategoryList(mainCategory)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/com/hongik/graduationproject/domain/dto/category/SubCategoryListRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.hongik.graduationproject.domain.dto.category; | ||
|
||
import com.hongik.graduationproject.eum.MainCategory; | ||
import lombok.Data; | ||
|
||
public record SubCategoryListRequest( | ||
MainCategory mainCategory | ||
) { | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/hongik/graduationproject/domain/dto/category/SubCategoryListResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.hongik.graduationproject.domain.dto.category; | ||
|
||
import java.util.List; | ||
|
||
public record SubCategoryListResponse( | ||
List<SubCategoryResponse> subCategoryList | ||
) { | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/hongik/graduationproject/domain/dto/category/SubCategoryResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.hongik.graduationproject.domain.dto.category; | ||
|
||
public record SubCategoryResponse ( | ||
String subCategory, | ||
Long categoryId | ||
){ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/com/hongik/graduationproject/domain/dto/video/VideoSummaryListResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.hongik.graduationproject.domain.dto.video; | ||
|
||
|
||
import com.hongik.graduationproject.domain.entity.VideoSummary; | ||
|
||
import java.util.List; | ||
|
||
public record VideoSummaryListResponse( | ||
List<VideoSummaryResponse> videoSummaryList | ||
) { | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/hongik/graduationproject/domain/dto/video/VideoSummaryResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.hongik.graduationproject.domain.dto.video; | ||
|
||
import com.hongik.graduationproject.domain.entity.VideoSummary; | ||
import com.hongik.graduationproject.eum.Platform; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public record VideoSummaryResponse( | ||
String title, | ||
List<String> keywords, | ||
String url, | ||
String address, | ||
Platform platform | ||
) { | ||
public VideoSummaryResponse(VideoSummary videoSummary) { | ||
this( | ||
videoSummary.getTitle(), | ||
Arrays.stream(videoSummary.getKeywords().split(",")).toList(), | ||
videoSummary.getUrl(), | ||
videoSummary.getAddress(), | ||
videoSummary.getPlatform() | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/java/com/hongik/graduationproject/repository/CategoryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
package com.hongik.graduationproject.repository; | ||
|
||
import com.hongik.graduationproject.domain.entity.Category; | ||
import com.hongik.graduationproject.domain.entity.User; | ||
import com.hongik.graduationproject.eum.MainCategory; | ||
import jakarta.validation.constraints.Min; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface CategoryRepository extends JpaRepository<Category, Long> { | ||
@Query("select c from Category c where c.user.id = :userId and c.mainCategory = :mainCategory and c.subCategory = '기타'") | ||
Optional<Category> findDefaultCategoryByUserIdAndMainCategory(Long userId, MainCategory mainCategory); | ||
|
||
List<Category> findAllByMainCategoryAndUser(MainCategory mainCategory, User user); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/main/java/com/hongik/graduationproject/repository/VideoSummaryCategoryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
package com.hongik.graduationproject.repository; | ||
|
||
import com.hongik.graduationproject.domain.entity.Category; | ||
import com.hongik.graduationproject.domain.entity.VideoSummaryCategory; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface VideoSummaryCategoryRepository extends JpaRepository<VideoSummaryCategory, Long> { | ||
List<VideoSummaryCategory> findAllByCategory(Category category); | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/hongik/graduationproject/service/CategoryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.hongik.graduationproject.service; | ||
|
||
import com.hongik.graduationproject.domain.dto.category.SubCategoryListRequest; | ||
import com.hongik.graduationproject.domain.dto.category.SubCategoryListResponse; | ||
import com.hongik.graduationproject.domain.dto.category.SubCategoryResponse; | ||
import com.hongik.graduationproject.domain.entity.User; | ||
import com.hongik.graduationproject.eum.MainCategory; | ||
import com.hongik.graduationproject.repository.CategoryRepository; | ||
import com.hongik.graduationproject.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CategoryService { | ||
private final CategoryRepository categoryRepository; | ||
private final UserRepository userRepository; | ||
|
||
public SubCategoryListResponse getSubCategoryList(MainCategory mainCategory) { | ||
User user = userRepository.getReferenceById(1L); | ||
// MainCategory mainCategory = subCategoryListRequest.mainCategory();/ | ||
|
||
List<SubCategoryResponse> subCategoryList = categoryRepository.findAllByMainCategoryAndUser(mainCategory, user).stream() | ||
.map(category -> new SubCategoryResponse(category.getSubCategory(), category.getId())) | ||
.toList(); | ||
return new SubCategoryListResponse(subCategoryList); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters