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

feat : 광고 조회 기능 추가 #43

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -8,12 +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
Expand All @@ -28,19 +27,18 @@ public void createAdvertise(AdvertiseCreateRequest request) {
advertiseService.createAdvertise(request);
}

@Operation(summary = "광고 목록 조회")
@Operation(summary = "광고 목록 조회", description = """
query param을 통해서 검색어를 전달받아 검색어에 해당하는 광고 목록을 조회합니다.
컨셉, 상업군 상관없이 keywordList에 전달하면 됩니다.
""")
@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")
)
public Page<AdvertiseSimpleResponse> getAdvertiseList(
Pageable pageable,
@RequestParam(required = false) List<String> keywordList) {
return advertiseService.getAdvertiseList(
PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by("id").descending()),
keywordList
);
return new PageImpl<>(advertiseList, pageable, advertiseList.size());
}

@Operation(summary = "광고 상세 조회")
Expand All @@ -62,4 +60,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 @@ -5,13 +5,17 @@
import core.kobaco.application.advertise.service.dto.AdvertiseLikeDetailResponse;
import core.kobaco.application.advertise.service.dto.AdvertiseSimpleResponse;
import core.kobaco.domain.advertise.service.AdvertiseAppender;
import core.kobaco.domain.advertise.service.AdvertiseKeywordReader;
import core.kobaco.domain.advertise.service.AdvertiseLikeManager;
import core.kobaco.domain.advertise.service.AdvertiseReader;
import core.kobaco.domain.keyword.Keyword;
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,23 +32,25 @@ public class AdvertiseService {
private final KeywordReader keywordReader;
private final KeywordFactory keywordFactory;
private final AdvertiseLikeManager advertiseLikeManager;
private final AdvertiseLikeReader advertiseLikeReader;
private final AdvertiseKeywordReader advertiseKeywordReader;


@Transactional
public void createAdvertise(AdvertiseCreateRequest request){
final List<Long> keywordIdList = keywordFactory.upsert(request.keywordList());
advertiseAppender.append(request.toDomain(), keywordIdList);
}

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;
public Page<AdvertiseSimpleResponse> getAdvertiseList(Pageable pageable, List<String> keywordList) {
return advertiseReader.getAllAdvertiseList(pageable, keywordList)
.map(advertise -> {
List<String> advertiseKeywordList = keywordReader.getKeywordList(advertiseKeywordReader.getKeywordIds(advertise.getAdvertiseId()))
.stream()
.map(Keyword::getKeyword)
.toList();
return AdvertiseSimpleResponse.of(advertise, advertiseKeywordList);
});
}


Expand Down Expand Up @@ -72,4 +78,31 @@ 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(advertise -> {
List<String> advertiseKeywordList = keywordReader.getKeywordList(advertiseKeywordReader.getKeywordIds(advertise.getAdvertiseId()))
.stream()
.map(Keyword::getKeyword)
.toList();
return AdvertiseSimpleResponse.of(advertise, advertiseKeywordList);
});
}

public Page<AdvertiseSimpleResponse> getLikeAdvertiseList(Pageable pageable) {
List<AdvertiseSimpleResponse> advertiseSimpleResponses = advertiseLikeReader.getLikeAdvertiseIdList(pageable).stream()
.map(advertiseReader::getAdvertise)
.map(advertise -> {
List<String> advertiseKeywordList = keywordReader.getKeywordList(advertiseKeywordReader.getKeywordIds(advertise.getAdvertiseId()))
.stream()
.map(Keyword::getKeyword)
.toList();
return AdvertiseSimpleResponse.of(advertise, advertiseKeywordList);
})
.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, List<String> keywordList){
return new AdvertiseSimpleResponse(
advertisement.getAdvertiseId(),
advertisement.getVideoUrl(),
advertisement.getTitle(),
advertisement.getVideoTime(),
keywordList
);
}
}
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 @@ -3,6 +3,7 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

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

public interface AdvertisementRepository {
Expand All @@ -11,4 +12,8 @@ public interface AdvertisementRepository {
Advertisement save(Advertisement advertisement);

Page<Advertisement> findAll(Pageable pageable);

Page<Advertisement> findSavedAllByUserId(Pageable pageable, Long userId);

Page<Advertisement> findAllWithKeyword(Pageable pageable, List<String> keywordList);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package core.kobaco.domain.advertise.service;

import core.kobaco.domain.advertise.AdvertisementKeyword;
import core.kobaco.domain.advertise.AdvertisementKeywordRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class AdvertiseKeywordReader {
private final AdvertisementKeywordRepository advertisementKeywordRepository;

public List<Long> getKeywordIds(Long advertiseId) {
return advertisementKeywordRepository.findAllByAdvertiseId(advertiseId)
.stream()
.map(AdvertisementKeyword::getKeywordId)
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import core.kobaco.domain.advertise.AdvertisementKeyword;
import core.kobaco.domain.advertise.AdvertisementKeywordRepository;
import core.kobaco.domain.advertise.AdvertisementRepository;
import jakarta.annotation.Nullable;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -26,8 +27,12 @@ public List<AdvertisementKeyword> getAdvertiseKeyword(Long advertiseId) {
return advertisementKeywordRepository.findAllByAdvertiseId(advertiseId);
}

public Page<Advertisement> getAllAdvertiseList(Pageable pageable) {
return advertisementRepository.findAll(pageable);
public Page<Advertisement> getAllAdvertiseList(Pageable pageable, @Nullable List<String> keywordList) {
// return advertisementRepository.findAll(pageable);
return advertisementRepository.findAllWithKeyword(pageable, keywordList);
}

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
Loading
Loading