Skip to content

Commit

Permalink
스트리밍 서비스 - 광고
Browse files Browse the repository at this point in the history
  • Loading branch information
chobeebee committed Jun 29, 2024
1 parent dcbbb95 commit 7680293
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/main/java/com/sparta/binplay/entity/Ads.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

@Entity
@Getter
@Table(name="ads")
Expand All @@ -16,6 +14,7 @@ public class Ads extends Timestamped{
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long adId;

@OneToMany(mappedBy = "ad")
private List<VideoAd> videoAds;
@ManyToOne
@JoinColumn(name = "video_id", nullable = false)
private Videos video;
}
13 changes: 11 additions & 2 deletions src/main/java/com/sparta/binplay/entity/VideoAd.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
package com.sparta.binplay.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;


@Entity
@Getter
@Table(name="video_ads")
@NoArgsConstructor
@Builder
@AllArgsConstructor
public class VideoAd {
@Id
@Column(name = "video_ad_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long videoAdId;

@Column(name = "ad_views", nullable = false)
private int adViews;
@Column(name = "ad_views")
private Long adViews = 0L;

@ManyToOne
@JoinColumn(name = "video_id", nullable = false)
Expand All @@ -24,4 +29,8 @@ public class VideoAd {
@ManyToOne
@JoinColumn(name = "ad_id", nullable = false)
private Ads ad;

public void countAd() {
this.adViews++;
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/sparta/binplay/repository/AdRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.sparta.binplay.repository;


import com.sparta.binplay.entity.Ads;
import org.springframework.data.jpa.repository.JpaRepository;

public interface AdRepository extends JpaRepository<Ads, Long> {
}
12 changes: 12 additions & 0 deletions src/main/java/com/sparta/binplay/repository/VideoAdRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.sparta.binplay.repository;

import com.sparta.binplay.entity.Ads;
import com.sparta.binplay.entity.VideoAd;
import com.sparta.binplay.entity.Videos;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface VideoAdRepository extends JpaRepository<VideoAd, Long> {
Optional<VideoAd> findByVideosAndAds(Videos videos, Ads ads);
}

0 comments on commit 7680293

Please sign in to comment.