-
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
15 changed files
with
229 additions
and
90 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
19 changes: 19 additions & 0 deletions
19
src/main/java/com/sparta/binplay/dto/request/AdViewRequestDto.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,19 @@ | ||
package com.sparta.binplay.dto.request; | ||
|
||
import com.sparta.binplay.entity.VideoAd; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Getter | ||
public class AdViewRequestDto { | ||
private LocalDate createdAt; | ||
private VideoAd videoAd; | ||
|
||
@Builder | ||
public AdViewRequestDto(LocalDate createdAt, VideoAd videoAd) { | ||
this.createdAt = createdAt; | ||
this.videoAd = videoAd; | ||
} | ||
} |
12 changes: 3 additions & 9 deletions
12
src/main/java/com/sparta/binplay/dto/request/StreamRequestDto.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,21 +1,15 @@ | ||
package com.sparta.binplay.dto.request; | ||
|
||
import com.sparta.binplay.entity.Users; | ||
import com.sparta.binplay.entity.Videos; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class StreamRequestDto { | ||
private int viewingTime; | ||
private int playTime; | ||
private int pausedAt; | ||
private Users user; | ||
private Videos video; | ||
|
||
public StreamRequestDto(int viewingTime, int pausedAt, Users user, Videos video) { | ||
this.viewingTime = viewingTime; | ||
public StreamRequestDto(int viewingTime) { | ||
this.playTime = viewingTime; | ||
this.pausedAt = pausedAt; | ||
this.user = user; | ||
this.video = video; | ||
} | ||
|
||
} |
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
25 changes: 25 additions & 0 deletions
25
src/main/java/com/sparta/binplay/dto/response/AdViewResponseDto.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,25 @@ | ||
package com.sparta.binplay.dto.response; | ||
|
||
import com.sparta.binplay.entity.AdViews; | ||
import lombok.*; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class AdViewResponseDto { | ||
private Long adViewId; | ||
private LocalDate createdAt; | ||
private Long videoAdId; | ||
|
||
public static AdViewResponseDto from(AdViews adView) { | ||
return AdViewResponseDto.builder() | ||
.adViewId(adView.getAdViewId()) | ||
.createdAt(adView.getCreatedAt()) | ||
.videoAdId(adView.getVideoAd().getVideoAdId()) // VideoAd 객체의 ID만 포함 | ||
.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.sparta.binplay.entity; | ||
|
||
import com.sparta.binplay.dto.request.AdViewRequestDto; | ||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.CreationTimestamp; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Set; | ||
|
||
@Entity | ||
@Getter | ||
@Table(name="ad_views") | ||
@NoArgsConstructor | ||
@Builder | ||
@AllArgsConstructor | ||
public class AdViews { | ||
|
||
@Id | ||
@Column(name="ad_view_id") | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long adViewId; | ||
|
||
@CreationTimestamp | ||
@Column(name = "created_at", updatable = false, nullable = false) | ||
private LocalDate createdAt; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "video_ad_id") | ||
private VideoAd videoAd; | ||
|
||
@OneToMany(mappedBy = "adView") | ||
private Set<StatisticAd> statisticsAds; | ||
|
||
@OneToMany(mappedBy = "adView") | ||
private Set<PaymentAd> paymentsAds; | ||
|
||
public AdViews(LocalDate createdAt, VideoAd videoAd) { | ||
this.createdAt = createdAt; | ||
this.videoAd = videoAd; | ||
} | ||
|
||
public static AdViews of(AdViewRequestDto adViewRequestDto) { | ||
return AdViews.builder() | ||
.createdAt(adViewRequestDto.getCreatedAt()) | ||
.videoAd(adViewRequestDto.getVideoAd()) | ||
.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
7 changes: 7 additions & 0 deletions
7
src/main/java/com/sparta/binplay/repository/AdViewRepository.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.sparta.binplay.repository; | ||
|
||
import com.sparta.binplay.entity.AdViews; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface AdViewRepository extends JpaRepository<AdViews, Long> { | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/sparta/binplay/service/AdViewService.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.AdViewResponseDto; | ||
import com.sparta.binplay.entity.AdViews; | ||
import com.sparta.binplay.entity.VideoAd; | ||
import com.sparta.binplay.repository.AdViewRepository; | ||
import com.sparta.binplay.repository.VideoAdRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class AdViewService { | ||
private final AdViewRepository adViewRepository; | ||
private final VideoAdRepository videoAdRepository; | ||
|
||
public AdViewResponseDto saveAdView(Long videoAdId) { | ||
// 비디오 광고를 videoAdId로 조회하고, 존재하지 않으면 예외를 던집니다. | ||
VideoAd videoAd = videoAdRepository.findById(videoAdId) | ||
.orElseThrow(() -> new RuntimeException("비디오 광고를 찾을 수 없음")); | ||
|
||
// 새로운 AdViews 객체를 생성합니다. | ||
AdViews adView = AdViews.builder() | ||
.videoAd(videoAd) | ||
.build(); | ||
|
||
// 생성된 AdViews 객체를 저장합니다. | ||
AdViews savedAdView = adViewRepository.save(adView); | ||
|
||
// 저장된 AdViews 객체를 AdViewResponseDto로 변환하여 반환합니다. | ||
return AdViewResponseDto.from(savedAdView); | ||
} | ||
|
||
} |
Oops, something went wrong.