Skip to content

Commit

Permalink
feat : 광고 조회 기능 추가
Browse files Browse the repository at this point in the history
- 인기 급상승 조회 추가
- 내가 찜한 영상 조회 추가
- 파일 저장시 모든 파일은 namespace를 가지도록 변경
  • Loading branch information
tlarbals824 committed Mar 4, 2024
1 parent 5b1a8d1 commit fdc5d42
Show file tree
Hide file tree
Showing 24 changed files with 165 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;

import java.sql.Time;
import java.time.LocalTime;
import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/advertises")
Expand All @@ -31,16 +28,7 @@ public void createAdvertise(AdvertiseCreateRequest request) {
@Operation(summary = "광고 목록 조회")
@GetMapping
public Page<AdvertiseSimpleResponse> getAdvertiseList(Pageable pageable) {
List<AdvertiseSimpleResponse> advertiseList = List.of(
new AdvertiseSimpleResponse(
1L,
"광고 이미지 URL",
"광고 제목",
Time.valueOf(LocalTime.of(0, 4,23)),
List.of("광고 태그1", "광고 태그2")
)
);
return new PageImpl<>(advertiseList, pageable, advertiseList.size());
return advertiseService.getAdvertiseList(PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by("id").descending()));
}

@Operation(summary = "광고 상세 조회")
Expand All @@ -62,4 +50,17 @@ public void likeAdvertise(@PathVariable Long advertiseId) {
public AdvertiseLikeDetailResponse getAdvertiseLikeCount(@PathVariable Long advertiseId) {
return advertiseService.getAdvertiseLikeCount(advertiseId);
}


@Operation(summary = "내가 찜한 영상")
@GetMapping("/saves")
public Page<AdvertiseSimpleResponse> getSaveAdvertises(Pageable pageable){
return advertiseService.getSaveAdvertiseList(pageable);
}

@Operation(summary = "인기 급상승 영상 조회")
@GetMapping("/likes")
public Page<AdvertiseSimpleResponse> getLikeAdvertises(Pageable pageable){
return advertiseService.getLikeAdvertiseList(pageable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import core.kobaco.domain.advertise.service.AdvertiseReader;
import core.kobaco.domain.keyword.service.KeywordFactory;
import core.kobaco.domain.keyword.service.KeywordReader;
import core.kobaco.domain.like.service.AdvertiseLikeReader;
import core.kobaco.domain.user.UserUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -28,6 +30,7 @@ public class AdvertiseService {
private final KeywordReader keywordReader;
private final KeywordFactory keywordFactory;
private final AdvertiseLikeManager advertiseLikeManager;
private final AdvertiseLikeReader advertiseLikeReader;

@Transactional
public void createAdvertise(AdvertiseCreateRequest request){
Expand All @@ -36,15 +39,8 @@ public void createAdvertise(AdvertiseCreateRequest request){
}

public Page<AdvertiseSimpleResponse> getAdvertiseList(Pageable pageable){
// return advertiseReader.getAdvertiseList(pageable)
// .map(advertise -> AdvertiseSimpleResponse.of(
// advertise,
// advertiseReader.getAdvertiseKeyword(advertise.getAdvertiseId())
// .stream()
// .map(keyword -> keywordReader.getKeyword(keyword.getKeywordId()).getKeyword())
// .toList()
// ));
return null;
return advertiseReader.getAllAdvertiseList(pageable)
.map(AdvertiseSimpleResponse::of);
}


Expand Down Expand Up @@ -72,4 +68,19 @@ public AdvertiseLikeDetailResponse getAdvertiseLikeCount(final Long advertiseId)
}


public Page<AdvertiseSimpleResponse> getSaveAdvertiseList(Pageable pageable) {
if(!userUtils.isLogin())
return Page.empty();
return advertiseReader.getSaveAdvertiseList(userUtils.getRequestUserId(), pageable)
.map(AdvertiseSimpleResponse::of);
}

public Page<AdvertiseSimpleResponse> getLikeAdvertiseList(Pageable pageable) {
List<AdvertiseSimpleResponse> advertiseSimpleResponses = advertiseLikeReader.getLikeAdvertiseIdList(pageable).stream()
.map(advertiseReader::getAdvertise)
.map(AdvertiseSimpleResponse::of)
.toList();
return new PageImpl<>(advertiseSimpleResponses, pageable, advertiseSimpleResponses.size());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

import core.kobaco.domain.advertise.Advertisement;
import core.kobaco.domain.advertise.AdvertisementDetail;
import io.swagger.v3.oas.annotations.media.Schema;

import java.sql.Time;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.List;

public record AdvertiseCreateRequest(
String videoUrl,
@Schema(description = "00:00:00 형식", example = "00:00:00", type = "string")
LocalTime videoTime,
String title,
LocalDate uploadDate,
String copy,
Expand All @@ -23,6 +28,7 @@ public Advertisement toDomain(){
return Advertisement.of(
null,
videoUrl,
Time.valueOf(videoTime),
title,
uploadDate,
copy,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package core.kobaco.application.advertise.service.dto;

import core.kobaco.domain.advertise.Advertisement;

import java.sql.Time;
import java.util.List;

Expand All @@ -10,4 +12,13 @@ public record AdvertiseSimpleResponse (
Time videoTime,
List<String> keywordList
){
public static AdvertiseSimpleResponse of(Advertisement advertisement){
return new AdvertiseSimpleResponse(
advertisement.getAdvertiseId(),
advertisement.getVideoUrl(),
advertisement.getTitle(),
advertisement.getVideoTime(),
List.of("키워드1", "키워드2")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public void captureAdvertise(MultipartFile imageFile, Long advertiseId) {
final User user = userUtils.getRequestUser();
final String imageUrl = imageUploader.uploadImage(imageFile);
// final File captureDirectory = fileFactory.createAdvertiseCaptureDirectory(advertiseId, user.getId());
final File captureDirectory = fileFactory.createBasicDirectory(user.getId());
captureAppender.append(captureDirectory.getFileId(), advertiseId, imageUrl);
captureAppender.append(fileFactory.createBasicDirectory(user.getId()), advertiseId, imageUrl);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import core.kobaco.application.file.service.dto.DirectoryUpdateRequest;
import core.kobaco.application.file.service.dto.FileMoveRequest;
import core.kobaco.domain.file.File;
import core.kobaco.domain.file.Namespace;
import core.kobaco.domain.file.service.*;
import core.kobaco.domain.user.UserUtils;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -39,7 +40,8 @@ public DirectoryDetailResponse getFiles(Long directoryId) {

@Transactional
public void createDirectory(Long parentDirectoryId, DirectoryCreateRequest request) {
fileAppender.append(request.toDomain(parentDirectoryId));
final Namespace namespace = fileReader.getNamespaceByUserId(userUtils.getRequestUserId());
fileAppender.append(request.toDomain(parentDirectoryId, namespace.getNamespaceId()));
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
public record DirectoryCreateRequest(
String directoryName
) {
public File toDomain(final Long parentDirectoryId){
public File toDomain(final Long parentDirectoryId, Long namespaceId){
return File.of(
null,
directoryName,
FileType.DIRECTORY,
parentDirectoryId,
null
namespaceId
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.sql.Time;
import java.time.LocalDate;

@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class Advertisement {
private Long advertiseId;
private String videoUrl;
private Time videoTime;
private String title;
private LocalDate uploadDate;
private String copy;
Expand All @@ -19,11 +21,12 @@ public class Advertisement {

public static Advertisement of(Long advertiseId,
String videoUrl,
Time videoTime,
String title,
LocalDate uploadDate,
String copy,
String copyDetail,
AdvertisementDetail advertisementDetail) {
return new Advertisement(advertiseId, videoUrl, title, uploadDate,copy, copyDetail, advertisementDetail);
return new Advertisement(advertiseId, videoUrl, videoTime, title, uploadDate, copy, copyDetail, advertisementDetail);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface AdvertisementRepository {
Advertisement save(Advertisement advertisement);

Page<Advertisement> findAll(Pageable pageable);

Page<Advertisement> findSavedAllByUserId(Pageable pageable, Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ public Page<Advertisement> getAllAdvertiseList(Pageable pageable) {
return advertisementRepository.findAll(pageable);
}

public Page<Advertisement> getSaveAdvertiseList(Long requestUserId, Pageable pageable) {
return advertisementRepository.findSavedAllByUserId(pageable, requestUserId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import core.kobaco.domain.file.File;
import core.kobaco.domain.file.FileRepository;
import core.kobaco.domain.file.FileType;
import core.kobaco.domain.file.service.FileReader;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -13,9 +14,10 @@
public class CaptureAppender {
private final AdvertiseCaptureRepository advertiseCaptureRepository;
private final FileRepository fileRepository;
private final FileReader fileReader;

public void append(Long captureDirectoryId, Long advertiseId,String imageUrl) {
final File imageFile = fileRepository.save(File.of(FileType.IMAGE, captureDirectoryId));
public void append(File directory, Long advertiseId,String imageUrl) {
final File imageFile = fileRepository.save(File.of(FileType.IMAGE, directory.getFileId(), directory.getNamespaceId()));
advertiseCaptureRepository.save(AdvertiseCapture.of(imageUrl, imageFile.getFileId(), advertiseId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class SaveAppender {
private final FileRepository fileRepository;

public void append(Advertisement advertisement, File directory) {
final File savedFile = fileRepository.save(File.of(FileType.ADVERTISE, directory.getFileId()));
final File savedFile = fileRepository.save(File.of(FileType.ADVERTISE, directory.getFileId(), directory.getNamespaceId()));
final AdvertiseSave advertiseSave = AdvertiseSave.of(savedFile.getFileId(),advertisement.getAdvertiseId());
advertiseSaveRepository.save(advertiseSave);
}
Expand Down
8 changes: 6 additions & 2 deletions kobaco/kobaco/src/main/java/core/kobaco/domain/file/File.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ public static File captureDirectory(Long parentFileId) {
return new File(null, CAPTURE_DIRECTORY_NAME, FileType.CAPTURE_DIRECTORY, parentFileId, null);
}

public static File basicDirectory(Long parentFileId) {
return new File(null, BASIC_DIRECTORY_NAME, FileType.BASIC_DIRECTORY, parentFileId, null);
public static File basicDirectory(Long parentFileId, Long namespaceId) {
return new File(null, BASIC_DIRECTORY_NAME, FileType.BASIC_DIRECTORY, parentFileId, namespaceId);
}

public static File of(String fileName, FileType fileType, Long parentFileId) {
return new File(null, fileName, fileType, parentFileId, null);
}

public static File of(FileType fileType, Long parentFileId, Long namespaceId) {
return new File(null, null, fileType, parentFileId, namespaceId);
}

public static File of(FileType fileType, Long parentFileId) {
return new File(null, null, fileType, parentFileId, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public File createRootDirectory(final Long userId) {
.orElseGet(() -> {
final File rootDirectory = fileRepository.save(File.rootDirectory(namespace.getNamespaceId()));
// fileRepository.save(File.captureDirectory(rootDirectory.getFileId()));
fileRepository.save(File.basicDirectory(rootDirectory.getFileId()));
fileRepository.save(File.basicDirectory(rootDirectory.getFileId(), namespace.getNamespaceId()));
return rootDirectory;
}
);
Expand All @@ -42,7 +42,7 @@ public File createAdvertiseCaptureDirectory(final Long advertiseId, final Long u
public File createBasicDirectory(final Long userId) {
final File rootDirectory = createRootDirectory(userId);
return fileRepository.findBasicDirectoryByUserId(userId)
.orElseGet(() -> fileRepository.save(File.basicDirectory(rootDirectory.getFileId())));
.orElseGet(() -> fileRepository.save(File.basicDirectory(rootDirectory.getFileId(), rootDirectory.getNamespaceId())));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import core.kobaco.domain.file.File;
import core.kobaco.domain.file.FileRepository;
import core.kobaco.domain.file.Namespace;
import core.kobaco.domain.file.NamespaceRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -11,6 +13,7 @@
@RequiredArgsConstructor
public class FileReader {
private final FileRepository fileRepository;
private final NamespaceRepository namespaceRepository;

public List<File> getDirectoryFiles(final Long directoryId){
return fileRepository.findAllByFileId(directoryId);
Expand All @@ -26,4 +29,9 @@ public File getCaptureDirectoryByUserId(final Long userId){
.orElseThrow(() -> new IllegalArgumentException("Capture directory not found"));
}

public Namespace getNamespaceByUserId(final Long userId){
return namespaceRepository.findByUserId(userId)
.orElseThrow(() -> new IllegalArgumentException("Namespace not found"));
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package core.kobaco.domain.like;

import javax.swing.text.html.Option;
import org.springframework.data.domain.Pageable;

import java.util.List;
import java.util.Optional;

public interface AdvertiseLikeRepository {
Expand All @@ -13,4 +15,6 @@ public interface AdvertiseLikeRepository {
void delete(AdvertiseLike advertiseLike);

Optional<AdvertiseLike> findByAdvertisementIdAndUserId(Long advertiseId, Long userId);

List<Long> findTopLankAdvertiseId(Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package core.kobaco.domain.like.service;

import core.kobaco.domain.like.AdvertiseLikeRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class AdvertiseLikeReader {
private final AdvertiseLikeRepository likeRepository;


public List<Long> getLikeAdvertiseIdList(Pageable pageable) {
return likeRepository.findTopLankAdvertiseId(pageable);
}
}

This file was deleted.

Loading

0 comments on commit fdc5d42

Please sign in to comment.