feat: implement VirtualEntity and DispatchLog models with corresponding tests and configuration
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package com.condado.newsletter.model
|
||||
|
||||
import jakarta.persistence.Column
|
||||
import jakarta.persistence.Entity
|
||||
import jakarta.persistence.EnumType
|
||||
import jakarta.persistence.Enumerated
|
||||
import jakarta.persistence.FetchType
|
||||
import jakarta.persistence.GeneratedValue
|
||||
import jakarta.persistence.GenerationType
|
||||
import jakarta.persistence.Id
|
||||
import jakarta.persistence.JoinColumn
|
||||
import jakarta.persistence.ManyToOne
|
||||
import jakarta.persistence.Table
|
||||
import java.time.LocalDateTime
|
||||
import java.util.UUID
|
||||
|
||||
/**
|
||||
* Records every AI generation and email send attempt for a given [VirtualEntity].
|
||||
* Stores the prompt sent, the AI response, parsed subject/body, send status, and timestamp.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "dispatch_logs")
|
||||
class DispatchLog(
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "entity_id", nullable = false)
|
||||
val virtualEntity: VirtualEntity,
|
||||
|
||||
@Column(name = "prompt_sent", columnDefinition = "TEXT")
|
||||
val promptSent: String? = null,
|
||||
|
||||
@Column(name = "ai_response", columnDefinition = "TEXT")
|
||||
val aiResponse: String? = null,
|
||||
|
||||
@Column(name = "email_subject")
|
||||
val emailSubject: String? = null,
|
||||
|
||||
@Column(name = "email_body", columnDefinition = "TEXT")
|
||||
val emailBody: String? = null,
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Column(nullable = false)
|
||||
val status: DispatchStatus = DispatchStatus.PENDING,
|
||||
|
||||
@Column(name = "error_message")
|
||||
val errorMessage: String? = null,
|
||||
|
||||
@Column(name = "dispatched_at", nullable = false)
|
||||
val dispatchedAt: LocalDateTime = LocalDateTime.now()
|
||||
) {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.UUID)
|
||||
var id: UUID? = null
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.condado.newsletter.model
|
||||
|
||||
/**
|
||||
* Represents the dispatch status of an AI-generated email send attempt.
|
||||
*/
|
||||
enum class DispatchStatus {
|
||||
PENDING,
|
||||
SENT,
|
||||
FAILED
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.condado.newsletter.model
|
||||
|
||||
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 org.hibernate.annotations.CreationTimestamp
|
||||
import java.time.LocalDateTime
|
||||
import java.util.UUID
|
||||
|
||||
/**
|
||||
* Represents a fictional employee of "Condado Abaixo da Média SA".
|
||||
* Each entity has a scheduled time to send AI-generated emails, a personality description,
|
||||
* and a context window for reading recent emails via IMAP.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "virtual_entities")
|
||||
class VirtualEntity(
|
||||
@Column(nullable = false)
|
||||
val name: String,
|
||||
|
||||
@Column(unique = true, nullable = false)
|
||||
val email: String,
|
||||
|
||||
@Column(name = "job_title", nullable = false)
|
||||
val jobTitle: String,
|
||||
|
||||
@Column(columnDefinition = "TEXT")
|
||||
val personality: String? = null,
|
||||
|
||||
@Column(name = "schedule_cron")
|
||||
val scheduleCron: String? = null,
|
||||
|
||||
@Column(name = "context_window_days")
|
||||
val contextWindowDays: Int = 3,
|
||||
|
||||
@Column(nullable = false)
|
||||
val active: Boolean = true
|
||||
) {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.UUID)
|
||||
var id: UUID? = null
|
||||
|
||||
@CreationTimestamp
|
||||
@Column(name = "created_at", updatable = false)
|
||||
var createdAt: LocalDateTime? = null
|
||||
}
|
||||
Reference in New Issue
Block a user