Skip to content

Commit fdc5d42

Browse files
committed
feat : 광고 조회 기능 추가
- 인기 급상승 조회 추가 - 내가 찜한 영상 조회 추가 - 파일 저장시 모든 파일은 namespace를 가지도록 변경
1 parent 5b1a8d1 commit fdc5d42

24 files changed

+165
-52
lines changed

kobaco/kobaco/src/main/java/core/kobaco/application/advertise/controller/AdvertiseController.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@
88
import io.swagger.v3.oas.annotations.Operation;
99
import lombok.RequiredArgsConstructor;
1010
import org.springframework.data.domain.Page;
11-
import org.springframework.data.domain.PageImpl;
11+
import org.springframework.data.domain.PageRequest;
1212
import org.springframework.data.domain.Pageable;
13+
import org.springframework.data.domain.Sort;
1314
import org.springframework.web.bind.annotation.*;
1415

15-
import java.sql.Time;
16-
import java.time.LocalTime;
17-
import java.util.List;
18-
1916
@RestController
2017
@RequiredArgsConstructor
2118
@RequestMapping("/api/advertises")
@@ -31,16 +28,7 @@ public void createAdvertise(AdvertiseCreateRequest request) {
3128
@Operation(summary = "광고 목록 조회")
3229
@GetMapping
3330
public Page<AdvertiseSimpleResponse> getAdvertiseList(Pageable pageable) {
34-
List<AdvertiseSimpleResponse> advertiseList = List.of(
35-
new AdvertiseSimpleResponse(
36-
1L,
37-
"광고 이미지 URL",
38-
"광고 제목",
39-
Time.valueOf(LocalTime.of(0, 4,23)),
40-
List.of("광고 태그1", "광고 태그2")
41-
)
42-
);
43-
return new PageImpl<>(advertiseList, pageable, advertiseList.size());
31+
return advertiseService.getAdvertiseList(PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by("id").descending()));
4432
}
4533

4634
@Operation(summary = "광고 상세 조회")
@@ -62,4 +50,17 @@ public void likeAdvertise(@PathVariable Long advertiseId) {
6250
public AdvertiseLikeDetailResponse getAdvertiseLikeCount(@PathVariable Long advertiseId) {
6351
return advertiseService.getAdvertiseLikeCount(advertiseId);
6452
}
53+
54+
55+
@Operation(summary = "내가 찜한 영상")
56+
@GetMapping("/saves")
57+
public Page<AdvertiseSimpleResponse> getSaveAdvertises(Pageable pageable){
58+
return advertiseService.getSaveAdvertiseList(pageable);
59+
}
60+
61+
@Operation(summary = "인기 급상승 영상 조회")
62+
@GetMapping("/likes")
63+
public Page<AdvertiseSimpleResponse> getLikeAdvertises(Pageable pageable){
64+
return advertiseService.getLikeAdvertiseList(pageable);
65+
}
6566
}

kobaco/kobaco/src/main/java/core/kobaco/application/advertise/service/AdvertiseService.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
import core.kobaco.domain.advertise.service.AdvertiseReader;
1010
import core.kobaco.domain.keyword.service.KeywordFactory;
1111
import core.kobaco.domain.keyword.service.KeywordReader;
12+
import core.kobaco.domain.like.service.AdvertiseLikeReader;
1213
import core.kobaco.domain.user.UserUtils;
1314
import lombok.RequiredArgsConstructor;
1415
import org.springframework.data.domain.Page;
16+
import org.springframework.data.domain.PageImpl;
1517
import org.springframework.data.domain.Pageable;
1618
import org.springframework.stereotype.Service;
1719
import org.springframework.transaction.annotation.Transactional;
@@ -28,6 +30,7 @@ public class AdvertiseService {
2830
private final KeywordReader keywordReader;
2931
private final KeywordFactory keywordFactory;
3032
private final AdvertiseLikeManager advertiseLikeManager;
33+
private final AdvertiseLikeReader advertiseLikeReader;
3134

3235
@Transactional
3336
public void createAdvertise(AdvertiseCreateRequest request){
@@ -36,15 +39,8 @@ public void createAdvertise(AdvertiseCreateRequest request){
3639
}
3740

3841
public Page<AdvertiseSimpleResponse> getAdvertiseList(Pageable pageable){
39-
// return advertiseReader.getAdvertiseList(pageable)
40-
// .map(advertise -> AdvertiseSimpleResponse.of(
41-
// advertise,
42-
// advertiseReader.getAdvertiseKeyword(advertise.getAdvertiseId())
43-
// .stream()
44-
// .map(keyword -> keywordReader.getKeyword(keyword.getKeywordId()).getKeyword())
45-
// .toList()
46-
// ));
47-
return null;
42+
return advertiseReader.getAllAdvertiseList(pageable)
43+
.map(AdvertiseSimpleResponse::of);
4844
}
4945

5046

@@ -72,4 +68,19 @@ public AdvertiseLikeDetailResponse getAdvertiseLikeCount(final Long advertiseId)
7268
}
7369

7470

71+
public Page<AdvertiseSimpleResponse> getSaveAdvertiseList(Pageable pageable) {
72+
if(!userUtils.isLogin())
73+
return Page.empty();
74+
return advertiseReader.getSaveAdvertiseList(userUtils.getRequestUserId(), pageable)
75+
.map(AdvertiseSimpleResponse::of);
76+
}
77+
78+
public Page<AdvertiseSimpleResponse> getLikeAdvertiseList(Pageable pageable) {
79+
List<AdvertiseSimpleResponse> advertiseSimpleResponses = advertiseLikeReader.getLikeAdvertiseIdList(pageable).stream()
80+
.map(advertiseReader::getAdvertise)
81+
.map(AdvertiseSimpleResponse::of)
82+
.toList();
83+
return new PageImpl<>(advertiseSimpleResponses, pageable, advertiseSimpleResponses.size());
84+
85+
}
7586
}

kobaco/kobaco/src/main/java/core/kobaco/application/advertise/service/dto/AdvertiseCreateRequest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22

33
import core.kobaco.domain.advertise.Advertisement;
44
import core.kobaco.domain.advertise.AdvertisementDetail;
5+
import io.swagger.v3.oas.annotations.media.Schema;
56

7+
import java.sql.Time;
68
import java.time.LocalDate;
9+
import java.time.LocalTime;
710
import java.util.List;
811

912
public record AdvertiseCreateRequest(
1013
String videoUrl,
14+
@Schema(description = "00:00:00 형식", example = "00:00:00", type = "string")
15+
LocalTime videoTime,
1116
String title,
1217
LocalDate uploadDate,
1318
String copy,
@@ -23,6 +28,7 @@ public Advertisement toDomain(){
2328
return Advertisement.of(
2429
null,
2530
videoUrl,
31+
Time.valueOf(videoTime),
2632
title,
2733
uploadDate,
2834
copy,

kobaco/kobaco/src/main/java/core/kobaco/application/advertise/service/dto/AdvertiseSimpleResponse.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package core.kobaco.application.advertise.service.dto;
22

3+
import core.kobaco.domain.advertise.Advertisement;
4+
35
import java.sql.Time;
46
import java.util.List;
57

@@ -10,4 +12,13 @@ public record AdvertiseSimpleResponse (
1012
Time videoTime,
1113
List<String> keywordList
1214
){
15+
public static AdvertiseSimpleResponse of(Advertisement advertisement){
16+
return new AdvertiseSimpleResponse(
17+
advertisement.getAdvertiseId(),
18+
advertisement.getVideoUrl(),
19+
advertisement.getTitle(),
20+
advertisement.getVideoTime(),
21+
List.of("키워드1", "키워드2")
22+
);
23+
}
1324
}

kobaco/kobaco/src/main/java/core/kobaco/application/advertisesave/service/AdvertiseSaveService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public void captureAdvertise(MultipartFile imageFile, Long advertiseId) {
4141
final User user = userUtils.getRequestUser();
4242
final String imageUrl = imageUploader.uploadImage(imageFile);
4343
// final File captureDirectory = fileFactory.createAdvertiseCaptureDirectory(advertiseId, user.getId());
44-
final File captureDirectory = fileFactory.createBasicDirectory(user.getId());
45-
captureAppender.append(captureDirectory.getFileId(), advertiseId, imageUrl);
44+
captureAppender.append(fileFactory.createBasicDirectory(user.getId()), advertiseId, imageUrl);
4645
}
4746
}

kobaco/kobaco/src/main/java/core/kobaco/application/file/service/FileService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import core.kobaco.application.file.service.dto.DirectoryUpdateRequest;
66
import core.kobaco.application.file.service.dto.FileMoveRequest;
77
import core.kobaco.domain.file.File;
8+
import core.kobaco.domain.file.Namespace;
89
import core.kobaco.domain.file.service.*;
910
import core.kobaco.domain.user.UserUtils;
1011
import lombok.RequiredArgsConstructor;
@@ -39,7 +40,8 @@ public DirectoryDetailResponse getFiles(Long directoryId) {
3940

4041
@Transactional
4142
public void createDirectory(Long parentDirectoryId, DirectoryCreateRequest request) {
42-
fileAppender.append(request.toDomain(parentDirectoryId));
43+
final Namespace namespace = fileReader.getNamespaceByUserId(userUtils.getRequestUserId());
44+
fileAppender.append(request.toDomain(parentDirectoryId, namespace.getNamespaceId()));
4345
}
4446

4547
@Transactional

kobaco/kobaco/src/main/java/core/kobaco/application/file/service/dto/DirectoryCreateRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
public record DirectoryCreateRequest(
77
String directoryName
88
) {
9-
public File toDomain(final Long parentDirectoryId){
9+
public File toDomain(final Long parentDirectoryId, Long namespaceId){
1010
return File.of(
1111
null,
1212
directoryName,
1313
FileType.DIRECTORY,
1414
parentDirectoryId,
15-
null
15+
namespaceId
1616
);
1717
}
1818
}

kobaco/kobaco/src/main/java/core/kobaco/domain/advertise/Advertisement.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
import lombok.AllArgsConstructor;
55
import lombok.Getter;
66

7+
import java.sql.Time;
78
import java.time.LocalDate;
89

910
@Getter
1011
@AllArgsConstructor(access = AccessLevel.PRIVATE)
1112
public class Advertisement {
1213
private Long advertiseId;
1314
private String videoUrl;
15+
private Time videoTime;
1416
private String title;
1517
private LocalDate uploadDate;
1618
private String copy;
@@ -19,11 +21,12 @@ public class Advertisement {
1921

2022
public static Advertisement of(Long advertiseId,
2123
String videoUrl,
24+
Time videoTime,
2225
String title,
2326
LocalDate uploadDate,
2427
String copy,
2528
String copyDetail,
2629
AdvertisementDetail advertisementDetail) {
27-
return new Advertisement(advertiseId, videoUrl, title, uploadDate,copy, copyDetail, advertisementDetail);
30+
return new Advertisement(advertiseId, videoUrl, videoTime, title, uploadDate, copy, copyDetail, advertisementDetail);
2831
}
2932
}

kobaco/kobaco/src/main/java/core/kobaco/domain/advertise/AdvertisementRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ public interface AdvertisementRepository {
1111
Advertisement save(Advertisement advertisement);
1212

1313
Page<Advertisement> findAll(Pageable pageable);
14+
15+
Page<Advertisement> findSavedAllByUserId(Pageable pageable, Long userId);
1416
}

kobaco/kobaco/src/main/java/core/kobaco/domain/advertise/service/AdvertiseReader.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,7 @@ public Page<Advertisement> getAllAdvertiseList(Pageable pageable) {
3030
return advertisementRepository.findAll(pageable);
3131
}
3232

33+
public Page<Advertisement> getSaveAdvertiseList(Long requestUserId, Pageable pageable) {
34+
return advertisementRepository.findSavedAllByUserId(pageable, requestUserId);
35+
}
3336
}

0 commit comments

Comments
 (0)