-
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.
- Loading branch information
Showing
14 changed files
with
194 additions
and
89 deletions.
There are no files selected for viewing
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
12 changes: 12 additions & 0 deletions
12
src/main/java/com/sparta/binplay/dto/request/VideoAdRequestDto.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,12 @@ | ||
package com.sparta.binplay.dto.request; | ||
|
||
import com.sparta.binplay.entity.Ads; | ||
import com.sparta.binplay.entity.Videos; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class VideoAdRequestDto { | ||
private Long adViews; | ||
private Videos video; | ||
private Ads ad; | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/sparta/binplay/dto/request/VideoRequestDto.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,10 +1,18 @@ | ||
package com.sparta.binplay.dto.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class VideoRequestDto { | ||
@NotBlank(message = "동영상 제목은 필수입니다.") | ||
private String title; | ||
private String description; | ||
private long videoLength; | ||
|
||
public VideoRequestDto(String title, String description, long videoLength) { | ||
this.title = title; | ||
this.description = description; | ||
this.videoLength = videoLength; | ||
} | ||
} |
24 changes: 14 additions & 10 deletions
24
src/main/java/com/sparta/binplay/dto/response/StreamResponseDto.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,24 +1,28 @@ | ||
package com.sparta.binplay.dto.response; | ||
|
||
import com.sparta.binplay.entity.Streams; | ||
import lombok.Getter; | ||
import lombok.*; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class StreamResponseDto { | ||
private Long streamId; | ||
private Long viewingTime; | ||
private Integer pausedAt; | ||
private int viewingTime; | ||
private int pausedAt; | ||
private LocalDateTime createAt; | ||
private LocalDateTime modifiedAt; | ||
|
||
|
||
public StreamResponseDto(Streams stream) { | ||
this.streamId = stream.getStreamId(); | ||
this.viewingTime = stream.getViewingTime(); | ||
this.pausedAt = stream.getPausedAt(); | ||
this.createAt = stream.getCreatedAt(); | ||
this.modifiedAt = stream.getUpdatedAt(); | ||
public static StreamResponseDto from(Streams stream) { | ||
return StreamResponseDto.builder() | ||
.streamId(stream.getStreamId()) | ||
.viewingTime(stream.getViewingTime()) | ||
.pausedAt(stream.getPausedAt()) | ||
.createAt(stream.getCreatedAt()) | ||
.build(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/sparta/binplay/dto/response/VideoAdResponseDto.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,21 @@ | ||
package com.sparta.binplay.dto.response; | ||
|
||
import com.sparta.binplay.entity.VideoAd; | ||
import lombok.*; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class VideoAdResponseDto { | ||
private Long videoAdId; | ||
private Long adViews; | ||
|
||
public static VideoAdResponseDto from(VideoAd videoAd) { | ||
return VideoAdResponseDto.builder() | ||
.videoAdId(videoAd.getVideoAdId()) | ||
.adViews(videoAd.getAdViews()) | ||
.build(); | ||
} | ||
} |
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
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
36 changes: 36 additions & 0 deletions
36
src/main/java/com/sparta/binplay/service/StreamService.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,36 @@ | ||
package com.sparta.binplay.service; | ||
|
||
import com.sparta.binplay.dto.response.StreamResponseDto; | ||
import com.sparta.binplay.entity.Streams; | ||
import com.sparta.binplay.entity.Users; | ||
import com.sparta.binplay.entity.Videos; | ||
import com.sparta.binplay.repository.StreamRepository; | ||
import com.sparta.binplay.repository.UserRepository; | ||
import com.sparta.binplay.repository.VideoRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class StreamService { | ||
private final StreamRepository streamRepository; | ||
private final VideoRepository videoRepository; | ||
private final UserRepository userRepository; | ||
|
||
// 비디오 중단 시점 업데이트 | ||
public StreamResponseDto stopPosition(Long videoId, int stopTime, String username) { | ||
Videos video = videoRepository.findById(videoId).orElseThrow(() -> new RuntimeException("비디오를 찾을 수 없음")); | ||
Users user = userRepository.findByUsername(username).orElseThrow(() -> new RuntimeException("회원을 찾을 수 없음")); | ||
Streams streams = streamRepository.findByUserAndVideo(user, video).orElse(Streams.builder() | ||
.user(user) | ||
.video(video) | ||
.build()); | ||
|
||
streams.updatePause(stopTime); | ||
streams.updateViewingTime(stopTime); | ||
|
||
streamRepository.save(streams); | ||
|
||
return StreamResponseDto.from(streams); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/sparta/binplay/service/VideoAdService.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,34 @@ | ||
package com.sparta.binplay.service; | ||
|
||
import com.sparta.binplay.dto.response.VideoAdResponseDto; | ||
import com.sparta.binplay.entity.Ads; | ||
import com.sparta.binplay.entity.VideoAd; | ||
import com.sparta.binplay.entity.Videos; | ||
import com.sparta.binplay.repository.AdRepository; | ||
import com.sparta.binplay.repository.VideoAdRepository; | ||
import com.sparta.binplay.repository.VideoRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class VideoAdService { | ||
private final VideoAdRepository videoAdRepository; | ||
private final VideoRepository videoRepository; | ||
private final AdRepository adRepository; | ||
|
||
// 특정 광고 재생 횟수 업데이트 | ||
public VideoAdResponseDto updateAdCount(Long adId, Long videoId) { | ||
Ads ad = adRepository.findById(adId).orElseThrow(() -> new RuntimeException("광고를 찾을 수 없음")); | ||
Videos video = videoRepository.findById(videoId).orElseThrow(() -> new RuntimeException("비디오를 찾을 수 없음")); | ||
VideoAd videoAd = videoAdRepository.findByVideoAndAd(video, ad).orElse(VideoAd.builder() //joincolumn 고칠것!!! | ||
.ad(ad) | ||
.video(video) | ||
.build()); | ||
|
||
videoAd.countAd(); | ||
videoAdRepository.save(videoAd); | ||
|
||
return VideoAdResponseDto.from(videoAd); | ||
} | ||
} |
Oops, something went wrong.