108 lines
2.9 KiB
Swift
108 lines
2.9 KiB
Swift
//
|
|
// CampusModel.swift
|
|
// ExodaiAcademy
|
|
//
|
|
// Created by Exodai on 23/01/2026.
|
|
//
|
|
|
|
import Fluent
|
|
|
|
final class CampusModel: Model, @unchecked Sendable {
|
|
static let schema: String = Database.campuses.rawValue
|
|
|
|
// MARK: - ID
|
|
|
|
@ID(key: .id)
|
|
var id: UUID?
|
|
|
|
// MARK: - Data
|
|
|
|
@OptionalField(key: FieldKeys.title)
|
|
var title: String?
|
|
|
|
@OptionalField(key: FieldKeys.description)
|
|
var description: String?
|
|
|
|
@OptionalField(key: FieldKeys.slug)
|
|
var slug: String?
|
|
|
|
@OptionalField(key: FieldKeys.content)
|
|
var content: String?
|
|
|
|
@Enum(key: FieldKeys.status)
|
|
var status: Status
|
|
|
|
@Field(key: FieldKeys.instructorID)
|
|
var instructorID: UserModel.IDValue
|
|
|
|
@OptionalField(key: FieldKeys.price)
|
|
var price: Double?
|
|
|
|
@OptionalField(key: FieldKeys.tags)
|
|
var tags: [TagModel.IDValue]?
|
|
|
|
@OptionalField(key: FieldKeys.categories)
|
|
var categories: [CategoryModel.IDValue]?
|
|
|
|
// MARK: - Timestamps
|
|
|
|
@Timestamp(key: FieldKeys.createdAt, on: .create)
|
|
var createdAt: Date?
|
|
|
|
@Timestamp(key: FieldKeys.updatedAt, on: .update)
|
|
var updatedAt: Date?
|
|
|
|
@Field(key: FieldKeys.publishDate)
|
|
var publishDate: Date?
|
|
|
|
// MARK: - Initializers
|
|
|
|
init() {}
|
|
}
|
|
|
|
extension CampusModel {
|
|
struct FieldKeys {
|
|
static var title: FieldKey { "title" }
|
|
static var description: FieldKey { "description" }
|
|
static var slug: FieldKey {"slug"}
|
|
static var content: FieldKey { "content" }
|
|
static var status: FieldKey { "status" }
|
|
static var instructorID: FieldKey { "instructorID" }
|
|
static var price: FieldKey { "price" }
|
|
static var tags: FieldKey { "tags" }
|
|
static var categories: FieldKey { "categories" }
|
|
static var createdAt: FieldKey { "createdAt" }
|
|
static var updatedAt: FieldKey { "updatedAt" }
|
|
static var publishDate: FieldKey { "publishDate" }
|
|
}
|
|
}
|
|
|
|
import Fluent
|
|
|
|
extension CampusModel {
|
|
struct Migration: AsyncMigration {
|
|
|
|
func prepare(on database: any FluentKit.Database) async throws {
|
|
try await database.schema(CampusModel.schema)
|
|
.id()
|
|
.field(FieldKeys.title, .string)
|
|
.field(FieldKeys.description, .string)
|
|
.field(FieldKeys.slug, .string)
|
|
.field(FieldKeys.content, .string)
|
|
.field(FieldKeys.status, .string, .required)
|
|
.field(FieldKeys.instructorID, .uuid, .required)
|
|
.field(FieldKeys.price, .double)
|
|
.field(FieldKeys.tags, .array(of: .uuid))
|
|
.field(FieldKeys.categories, .array(of: .uuid))
|
|
.field(FieldKeys.createdAt, .datetime)
|
|
.field(FieldKeys.updatedAt, .datetime)
|
|
.field(FieldKeys.publishDate, .datetime)
|
|
.create()
|
|
}
|
|
|
|
func revert(on database: any FluentKit.Database) async throws {
|
|
try await database.schema(CampusModel.schema).delete()
|
|
}
|
|
}
|
|
}
|