78 lines
2.4 KiB
Java
78 lines
2.4 KiB
Java
package com.hlab.yanalyst.domain.upload;
|
|
|
|
import jakarta.persistence.Column;
|
|
import jakarta.persistence.Entity;
|
|
import jakarta.persistence.GeneratedValue;
|
|
import jakarta.persistence.GenerationType;
|
|
import jakarta.persistence.Id;
|
|
import jakarta.persistence.Table;
|
|
import lombok.AccessLevel;
|
|
import lombok.Getter;
|
|
import lombok.NoArgsConstructor;
|
|
import org.springframework.data.annotation.CreatedDate;
|
|
import org.springframework.data.annotation.LastModifiedDate;
|
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
|
import jakarta.persistence.EntityListeners;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
@Entity
|
|
@Table(name = "youtube_upload_connections")
|
|
@Getter
|
|
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
|
@EntityListeners(AuditingEntityListener.class)
|
|
public class YoutubeConnection {
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
private Long id;
|
|
|
|
@Column(nullable = false, unique = true, length = 64)
|
|
private String channelId;
|
|
|
|
@Column(nullable = false)
|
|
private String channelTitle;
|
|
|
|
private String channelHandle;
|
|
|
|
@Column(length = 2083)
|
|
private String thumbnailUrl;
|
|
|
|
@Column(nullable = false, columnDefinition = "TEXT")
|
|
private String encryptedRefreshToken;
|
|
|
|
@Column(nullable = false, length = 20)
|
|
private String tokenStatus = "ACTIVE";
|
|
|
|
private LocalDateTime lastSyncedAt;
|
|
|
|
@CreatedDate
|
|
@Column(updatable = false)
|
|
private LocalDateTime createdAt;
|
|
|
|
@LastModifiedDate
|
|
private LocalDateTime updatedAt;
|
|
|
|
public YoutubeConnection(String channelId, String channelTitle, String channelHandle,
|
|
String thumbnailUrl, String encryptedRefreshToken) {
|
|
this.channelId = channelId;
|
|
update(channelTitle, channelHandle, thumbnailUrl, encryptedRefreshToken);
|
|
}
|
|
|
|
public void update(String channelTitle, String channelHandle, String thumbnailUrl,
|
|
String encryptedRefreshToken) {
|
|
this.channelTitle = channelTitle;
|
|
this.channelHandle = channelHandle;
|
|
this.thumbnailUrl = thumbnailUrl;
|
|
if (encryptedRefreshToken != null && !encryptedRefreshToken.isBlank()) {
|
|
this.encryptedRefreshToken = encryptedRefreshToken;
|
|
}
|
|
this.tokenStatus = "ACTIVE";
|
|
this.lastSyncedAt = LocalDateTime.now();
|
|
}
|
|
|
|
public void markSynced() {
|
|
this.lastSyncedAt = LocalDateTime.now();
|
|
this.tokenStatus = "ACTIVE";
|
|
}
|
|
}
|