feat: Begins breaking database out into it's own module, using dependencies
This commit is contained in:
63
Sources/DatabaseClient/Employees.swift
Normal file
63
Sources/DatabaseClient/Employees.swift
Normal file
@@ -0,0 +1,63 @@
|
||||
import Dependencies
|
||||
import DependenciesMacros
|
||||
import SharedModels
|
||||
|
||||
public extension DatabaseClient {
|
||||
|
||||
@DependencyClient
|
||||
struct Employees: Sendable {
|
||||
public var create: @Sendable (Employee.Create) async throws -> Employee
|
||||
public var delete: @Sendable (Employee.ID) async throws -> Void
|
||||
public var fetchAll: @Sendable (FetchRequest) async throws -> [Employee]
|
||||
public var get: @Sendable (Employee.ID) async throws -> Employee?
|
||||
public var update: @Sendable (Employee.ID, Employee.Update) async throws -> Employee
|
||||
|
||||
public func fetchAll() async throws -> [Employee] {
|
||||
try await fetchAll(.all)
|
||||
}
|
||||
|
||||
public enum FetchRequest {
|
||||
case active
|
||||
case all
|
||||
case inactive
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension DatabaseClient.Employees: TestDependencyKey {
|
||||
public static let testValue = Self()
|
||||
}
|
||||
|
||||
public extension Employee {
|
||||
struct Create: Codable, Sendable {
|
||||
public let firstName: String
|
||||
public let lastName: String
|
||||
public let active: Bool?
|
||||
|
||||
public init(
|
||||
firstName: String,
|
||||
lastName: String,
|
||||
active: Bool? = nil
|
||||
) {
|
||||
self.firstName = firstName
|
||||
self.lastName = lastName
|
||||
self.active = active
|
||||
}
|
||||
}
|
||||
|
||||
struct Update: Codable, Sendable {
|
||||
public let firstName: String?
|
||||
public let lastName: String?
|
||||
public let active: Bool?
|
||||
|
||||
public init(
|
||||
firstName: String? = nil,
|
||||
lastName: String? = nil,
|
||||
active: Bool? = nil
|
||||
) {
|
||||
self.firstName = firstName
|
||||
self.lastName = lastName
|
||||
self.active = active
|
||||
}
|
||||
}
|
||||
}
|
||||
30
Sources/DatabaseClient/Interface.swift
Normal file
30
Sources/DatabaseClient/Interface.swift
Normal file
@@ -0,0 +1,30 @@
|
||||
import Dependencies
|
||||
import DependenciesMacros
|
||||
import FluentKit
|
||||
|
||||
public extension DependencyValues {
|
||||
var database: DatabaseClient {
|
||||
get { self[DatabaseClient.self] }
|
||||
set { self[DatabaseClient.self] = newValue }
|
||||
}
|
||||
}
|
||||
|
||||
@DependencyClient
|
||||
public struct DatabaseClient: Sendable {
|
||||
public var employees: Employees
|
||||
public var migrations: @Sendable () async throws -> [any AsyncMigration]
|
||||
public var purchaseOrders: PurchaseOrders
|
||||
public var users: Users
|
||||
public var vendorBranches: VendorBranches
|
||||
public var vendors: Vendors
|
||||
}
|
||||
|
||||
extension DatabaseClient: TestDependencyKey {
|
||||
public static let testValue: DatabaseClient = Self(
|
||||
employees: .testValue,
|
||||
purchaseOrders: .testValue,
|
||||
users: .testValue,
|
||||
vendorBranches: .testValue,
|
||||
vendors: .testValue
|
||||
)
|
||||
}
|
||||
52
Sources/DatabaseClient/PurchaseOrders.swift
Normal file
52
Sources/DatabaseClient/PurchaseOrders.swift
Normal file
@@ -0,0 +1,52 @@
|
||||
import Dependencies
|
||||
import DependenciesMacros
|
||||
import Fluent
|
||||
import SharedModels
|
||||
|
||||
public extension DatabaseClient {
|
||||
@DependencyClient
|
||||
struct PurchaseOrders: Sendable {
|
||||
public var create: @Sendable (PurchaseOrder.Create, User.ID) async throws -> PurchaseOrder
|
||||
public var fetchAll: @Sendable () async throws -> [PurchaseOrder]
|
||||
public var fetchPage: @Sendable (PageRequest) async throws -> Page<PurchaseOrder>
|
||||
public var get: @Sendable (PurchaseOrder.ID) async throws -> PurchaseOrder?
|
||||
// var update: @Sendable (PurchaseOrder.ID, PurchaseOrder.Update) async throws -> PurchaseOrder
|
||||
public var delete: @Sendable (PurchaseOrder.ID) async throws -> Void
|
||||
}
|
||||
}
|
||||
|
||||
extension DatabaseClient.PurchaseOrders: TestDependencyKey {
|
||||
public static let testValue: DatabaseClient.PurchaseOrders = Self()
|
||||
}
|
||||
|
||||
public extension PurchaseOrder {
|
||||
struct Create: Codable, Sendable {
|
||||
|
||||
public let id: Int?
|
||||
public let workOrder: Int?
|
||||
public let materials: String
|
||||
public let customer: String
|
||||
public let truckStock: Bool?
|
||||
public let createdForID: Employee.ID
|
||||
public let vendorBranchID: VendorBranch.ID
|
||||
|
||||
public init(
|
||||
id: Int? = nil,
|
||||
workOrder: Int? = nil,
|
||||
materials: String,
|
||||
customer: String,
|
||||
truckStock: Bool? = nil,
|
||||
createdForID: Employee.ID,
|
||||
vendorBranchID: VendorBranch.ID
|
||||
) {
|
||||
self.id = id
|
||||
self.workOrder = workOrder
|
||||
self.materials = materials
|
||||
self.customer = customer
|
||||
self.truckStock = truckStock
|
||||
self.createdForID = createdForID
|
||||
self.vendorBranchID = vendorBranchID
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
76
Sources/DatabaseClient/Users.swift
Normal file
76
Sources/DatabaseClient/Users.swift
Normal file
@@ -0,0 +1,76 @@
|
||||
import Dependencies
|
||||
import DependenciesMacros
|
||||
import Foundation
|
||||
import SharedModels
|
||||
|
||||
public extension DatabaseClient {
|
||||
|
||||
@DependencyClient
|
||||
struct Users: Sendable {
|
||||
public var create: @Sendable (User.Create) async throws -> User
|
||||
public var delete: @Sendable (User.ID) async throws -> Void
|
||||
public var fetchAll: @Sendable () async throws -> [User]
|
||||
public var get: @Sendable (User.ID) async throws -> User?
|
||||
public var login: @Sendable (User.Login) async throws -> User.Token
|
||||
public var logout: @Sendable (User.Token.ID) async throws -> Void
|
||||
}
|
||||
}
|
||||
|
||||
extension DatabaseClient.Users: TestDependencyKey {
|
||||
public static let testValue: DatabaseClient.Users = Self()
|
||||
}
|
||||
|
||||
public extension User {
|
||||
|
||||
struct Create: Codable, Sendable {
|
||||
public let username: String
|
||||
public let email: String
|
||||
public let password: String
|
||||
public let confirmPassword: String
|
||||
|
||||
public init(
|
||||
username: String,
|
||||
email: String,
|
||||
password: String,
|
||||
confirmPassword: String
|
||||
) {
|
||||
self.username = username
|
||||
self.email = email
|
||||
self.password = password
|
||||
self.confirmPassword = confirmPassword
|
||||
}
|
||||
}
|
||||
|
||||
struct Login: Codable, Sendable {
|
||||
public let username: String?
|
||||
public let email: String?
|
||||
public let password: String
|
||||
|
||||
public init(
|
||||
username: String?,
|
||||
email: String? = nil,
|
||||
password: String
|
||||
) {
|
||||
self.username = username
|
||||
self.email = email
|
||||
self.password = password
|
||||
}
|
||||
}
|
||||
|
||||
struct Token: Codable, Equatable, Identifiable, Sendable {
|
||||
public let id: UUID
|
||||
public let userID: User.ID
|
||||
public let value: String
|
||||
|
||||
public init(
|
||||
id: UUID,
|
||||
userID: User.ID,
|
||||
value: String
|
||||
) {
|
||||
self.id = id
|
||||
self.userID = userID
|
||||
self.value = value
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
48
Sources/DatabaseClient/VendorBranches.swift
Normal file
48
Sources/DatabaseClient/VendorBranches.swift
Normal file
@@ -0,0 +1,48 @@
|
||||
import Dependencies
|
||||
import DependenciesMacros
|
||||
import SharedModels
|
||||
|
||||
public extension DatabaseClient {
|
||||
@DependencyClient
|
||||
struct VendorBranches: Sendable {
|
||||
public var create: @Sendable (VendorBranch.Create) async throws -> VendorBranch
|
||||
public var delete: @Sendable (VendorBranch.ID) async throws -> Void
|
||||
public var fetchAll: @Sendable (FetchRequest) async throws -> [VendorBranch]
|
||||
public var get: @Sendable (VendorBranch.ID) async throws -> VendorBranch?
|
||||
public var update: @Sendable (VendorBranch.ID, VendorBranch.Update) async throws -> VendorBranch
|
||||
|
||||
public enum FetchRequest: Equatable {
|
||||
case all
|
||||
case `for`(vendorID: Vendor.ID)
|
||||
case withVendor
|
||||
}
|
||||
|
||||
public func fetchAll() async throws -> [VendorBranch] {
|
||||
try await fetchAll(.all)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension DatabaseClient.VendorBranches: TestDependencyKey {
|
||||
public static let testValue: DatabaseClient.VendorBranches = Self()
|
||||
}
|
||||
|
||||
public extension VendorBranch {
|
||||
struct Create: Codable, Sendable {
|
||||
public let name: String
|
||||
public let vendorID: Vendor.ID
|
||||
|
||||
public init(name: String, vendorID: Vendor.ID) {
|
||||
self.name = name
|
||||
self.vendorID = vendorID
|
||||
}
|
||||
}
|
||||
|
||||
struct Update: Codable, Sendable {
|
||||
public let name: String?
|
||||
|
||||
public init(name: String?) {
|
||||
self.name = name
|
||||
}
|
||||
}
|
||||
}
|
||||
55
Sources/DatabaseClient/Vendors.swift
Normal file
55
Sources/DatabaseClient/Vendors.swift
Normal file
@@ -0,0 +1,55 @@
|
||||
import Dependencies
|
||||
import DependenciesMacros
|
||||
import SharedModels
|
||||
|
||||
public extension DatabaseClient {
|
||||
@DependencyClient
|
||||
struct Vendors: Sendable {
|
||||
public var create: @Sendable (Vendor.Create) async throws -> Vendor
|
||||
public var delete: @Sendable (Vendor.ID) async throws -> Void
|
||||
public var fetchAll: @Sendable (FetchRequest) async throws -> [Vendor]
|
||||
public var get: @Sendable (Vendor.ID, GetRequest) async throws -> Vendor?
|
||||
public var update: @Sendable (Vendor.ID, Vendor.Update) async throws -> Vendor
|
||||
|
||||
public enum FetchRequest {
|
||||
case all
|
||||
case withBranches
|
||||
}
|
||||
|
||||
public enum GetRequest {
|
||||
case all
|
||||
case withBranches
|
||||
}
|
||||
|
||||
public func fetchAll() async throws -> [Vendor] {
|
||||
try await fetchAll(.all)
|
||||
}
|
||||
|
||||
public func get(_ id: Vendor.ID) async throws -> Vendor? {
|
||||
try await get(id, .all)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension DatabaseClient.Vendors: TestDependencyKey {
|
||||
public static let testValue: DatabaseClient.Vendors = Self()
|
||||
}
|
||||
|
||||
public extension Vendor {
|
||||
|
||||
struct Create: Codable, Sendable {
|
||||
public let name: String
|
||||
|
||||
public init(name: String) {
|
||||
self.name = name
|
||||
}
|
||||
}
|
||||
|
||||
struct Update: Codable, Sendable {
|
||||
public let name: String?
|
||||
|
||||
public init(name: String?) {
|
||||
self.name = name
|
||||
}
|
||||
}
|
||||
}
|
||||
176
Sources/DatabaseClientLive/Employees.swift
Normal file
176
Sources/DatabaseClientLive/Employees.swift
Normal file
@@ -0,0 +1,176 @@
|
||||
import DatabaseClient
|
||||
import Fluent
|
||||
import Foundation
|
||||
import SharedModels
|
||||
|
||||
public extension DatabaseClient.Employees {
|
||||
|
||||
static func live(database: any Database) -> DatabaseClient.Employees {
|
||||
.init { create in
|
||||
let model = try create.toModel()
|
||||
try await model.save(on: database)
|
||||
return model.toDTO()
|
||||
} delete: { id in
|
||||
guard let model = try await EmployeeModel.find(id, on: database) else {
|
||||
throw NotFoundError()
|
||||
}
|
||||
try await model.delete(on: database)
|
||||
} fetchAll: { request in
|
||||
var query = EmployeeModel.query(on: database)
|
||||
.sort(\.$lastName)
|
||||
|
||||
switch request {
|
||||
case .active:
|
||||
query = query.filter(\.$active == true)
|
||||
case .inactive:
|
||||
query = query.filter(\.$active == false)
|
||||
case .all:
|
||||
break
|
||||
}
|
||||
|
||||
return try await query.all().map { $0.toDTO() }
|
||||
|
||||
} get: { id in
|
||||
try await EmployeeModel.find(id, on: database).map { $0.toDTO() }
|
||||
} update: { id, updates in
|
||||
guard let model = try await EmployeeModel.find(id, on: database) else {
|
||||
throw NotFoundError()
|
||||
}
|
||||
try model.applyUpdate(updates)
|
||||
try await model.save(on: database)
|
||||
return model.toDTO()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension Employee.Create {
|
||||
|
||||
func toModel() throws -> EmployeeModel {
|
||||
try validate()
|
||||
return .init(firstName: firstName, lastName: lastName, active: active ?? true)
|
||||
}
|
||||
|
||||
func validate() throws {
|
||||
guard !firstName.isEmpty else {
|
||||
throw ValidationError(message: "Employee first name should not be empty.")
|
||||
}
|
||||
guard !lastName.isEmpty else {
|
||||
throw ValidationError(message: "Employee first name should not be empty.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Employee.Update {
|
||||
|
||||
func validate() throws {
|
||||
if let firstName {
|
||||
guard !firstName.isEmpty else {
|
||||
throw ValidationError(message: "Employee first name should not be empty.")
|
||||
}
|
||||
}
|
||||
if let lastName {
|
||||
guard !lastName.isEmpty else {
|
||||
throw ValidationError(message: "Employee first name should not be empty.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Employee {
|
||||
|
||||
struct Migrate: AsyncMigration {
|
||||
|
||||
let name = "CreateEmployee"
|
||||
|
||||
func prepare(on database: Database) async throws {
|
||||
try await database.schema(EmployeeModel.schema)
|
||||
.id()
|
||||
.field("first_name", .string, .required)
|
||||
.field("last_name", .string, .required)
|
||||
.field("is_active", .bool, .required)
|
||||
.field("created_at", .datetime)
|
||||
.field("updated_at", .datetime)
|
||||
.unique(on: "first_name", "last_name")
|
||||
.create()
|
||||
}
|
||||
|
||||
func revert(on database: Database) async throws {
|
||||
try await database.schema(EmployeeModel.schema).delete()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// The employee database model.
|
||||
///
|
||||
/// An employee is someone that PO's can be generated for. They can be either a field
|
||||
/// employee / technician, an office employee, or an administrator.
|
||||
///
|
||||
/// # NOTE: Only `User` types can login and generate po's for employees.
|
||||
///
|
||||
final class EmployeeModel: Model, @unchecked Sendable {
|
||||
|
||||
static let schema = "employee"
|
||||
|
||||
// @ID(key: ")
|
||||
// var id: UUID?
|
||||
@ID(key: .id)
|
||||
var id: UUID?
|
||||
|
||||
@Field(key: "first_name")
|
||||
var firstName: String
|
||||
|
||||
@Field(key: "last_name")
|
||||
var lastName: String
|
||||
|
||||
@Field(key: "is_active")
|
||||
var active: Bool
|
||||
|
||||
@Timestamp(key: "created_at", on: .create)
|
||||
var createdAt: Date?
|
||||
|
||||
@Timestamp(key: "updated_at", on: .update)
|
||||
var updatedAt: Date?
|
||||
|
||||
init() {}
|
||||
|
||||
init(
|
||||
id: UUID? = nil,
|
||||
firstName: String,
|
||||
lastName: String,
|
||||
active: Bool,
|
||||
createdAt: Date? = nil,
|
||||
updatedAt: Date? = nil
|
||||
) {
|
||||
self.id = id
|
||||
self.firstName = firstName
|
||||
self.lastName = lastName
|
||||
self.active = active
|
||||
self.createdAt = createdAt
|
||||
self.updatedAt = updatedAt
|
||||
}
|
||||
|
||||
func toDTO() -> Employee {
|
||||
.init(
|
||||
id: id,
|
||||
active: active,
|
||||
createdAt: createdAt,
|
||||
firstName: firstName,
|
||||
lastName: lastName,
|
||||
updatedAt: updatedAt
|
||||
)
|
||||
}
|
||||
|
||||
func applyUpdate(_ updates: Employee.Update) throws {
|
||||
try updates.validate()
|
||||
if let firstName = updates.firstName {
|
||||
self.firstName = firstName
|
||||
}
|
||||
if let lastName = updates.lastName {
|
||||
self.lastName = lastName
|
||||
}
|
||||
if let active = updates.active {
|
||||
self.active = active
|
||||
}
|
||||
}
|
||||
}
|
||||
5
Sources/DatabaseClientLive/Errors.swift
Normal file
5
Sources/DatabaseClientLive/Errors.swift
Normal file
@@ -0,0 +1,5 @@
|
||||
public struct ValidationError: Error {
|
||||
let message: String
|
||||
}
|
||||
|
||||
public struct NotFoundError: Error {}
|
||||
27
Sources/DatabaseClientLive/Live.swift
Normal file
27
Sources/DatabaseClientLive/Live.swift
Normal file
@@ -0,0 +1,27 @@
|
||||
import DatabaseClient
|
||||
import FluentKit
|
||||
import SharedModels
|
||||
|
||||
public extension DatabaseClient {
|
||||
|
||||
/// Create the live database client.
|
||||
static func live(database: any Database) -> Self {
|
||||
.init(
|
||||
employees: .live(database: database),
|
||||
migrations: {
|
||||
[
|
||||
Employee.Migrate(),
|
||||
PurchaseOrder.Migrate(),
|
||||
User.Migrate(),
|
||||
User.Token.Migrate(),
|
||||
VendorBranch.Migrate(),
|
||||
Vendor.Migrate()
|
||||
]
|
||||
},
|
||||
purchaseOrders: .live(database: database),
|
||||
users: .live(database: database),
|
||||
vendorBranches: .live(database: database),
|
||||
vendors: .live(database: database)
|
||||
)
|
||||
}
|
||||
}
|
||||
174
Sources/DatabaseClientLive/PurchaseOrders.swift
Normal file
174
Sources/DatabaseClientLive/PurchaseOrders.swift
Normal file
@@ -0,0 +1,174 @@
|
||||
import DatabaseClient
|
||||
import FluentKit
|
||||
import Foundation
|
||||
import SharedModels
|
||||
|
||||
public extension DatabaseClient.PurchaseOrders {
|
||||
|
||||
static func live(database: any Database) -> Self {
|
||||
.init { create, createdById in
|
||||
let model = try create.toModel(createdByID: createdById)
|
||||
try await model.save(on: database)
|
||||
return try model.toDTO()
|
||||
} fetchAll: {
|
||||
try await PurchaseOrderModel.allQuery(on: database)
|
||||
.all()
|
||||
.map { try $0.toDTO() }
|
||||
} fetchPage: { request in
|
||||
try await PurchaseOrderModel.allQuery(on: database)
|
||||
.paginate(request)
|
||||
.map { try $0.toDTO() }
|
||||
} get: { id in
|
||||
try await PurchaseOrderModel.allQuery(on: database)
|
||||
.filter(\.$id == id)
|
||||
.first()
|
||||
.map { try $0.toDTO() }
|
||||
} delete: { id in
|
||||
guard let model = try await PurchaseOrderModel.find(id, on: database) else {
|
||||
throw NotFoundError()
|
||||
}
|
||||
try await model.delete(on: database)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension PurchaseOrder {
|
||||
struct Migrate: AsyncMigration {
|
||||
|
||||
let name = "CreatePurchaseOrder"
|
||||
|
||||
func prepare(on database: any Database) async throws {
|
||||
try await database.schema(PurchaseOrderModel.schema)
|
||||
.field("id", .int, .identifier(auto: true))
|
||||
.field("work_order", .int)
|
||||
.field("customer", .string, .required)
|
||||
.field("materials", .string, .required)
|
||||
.field("truck_stock", .bool, .required)
|
||||
.field("created_by_id", .uuid, .required, .references(UserModel.schema, "id"))
|
||||
.field("created_for_id", .uuid, .required, .references(EmployeeModel.schema, "id"))
|
||||
.field("vendor_branch_id", .uuid, .required, .references(VendorBranchModel.schema, "id"))
|
||||
.field("created_at", .datetime)
|
||||
.field("updated_at", .datetime)
|
||||
.create()
|
||||
}
|
||||
|
||||
func revert(on database: any Database) async throws {
|
||||
try await database.schema(PurchaseOrderModel.schema).delete()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension PurchaseOrder.Create {
|
||||
|
||||
func toModel(createdByID: User.ID) throws -> PurchaseOrderModel {
|
||||
try validate()
|
||||
return .init(
|
||||
materials: materials,
|
||||
customer: customer,
|
||||
truckStock: truckStock ?? false,
|
||||
createdByID: createdByID,
|
||||
createdForID: createdForID,
|
||||
vendorBranchID: vendorBranchID
|
||||
)
|
||||
}
|
||||
|
||||
func validate() throws {
|
||||
guard !materials.isEmpty else {
|
||||
throw ValidationError(message: "Materials should not be empty.")
|
||||
}
|
||||
guard !customer.isEmpty else {
|
||||
throw ValidationError(message: "Customer should not be empty.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The purchase order database model.
|
||||
///
|
||||
/// # NOTE: An initial purchase order should be created with an `id` higher than our current PO
|
||||
/// so that subsequent PO's are generated with higher values than our current system produces.
|
||||
/// once the first one is set, the rest will auto-increment from there.
|
||||
final class PurchaseOrderModel: Model, Codable, @unchecked Sendable {
|
||||
static let schema = "purchase_order"
|
||||
|
||||
@ID(custom: "id", generatedBy: .database)
|
||||
var id: Int?
|
||||
|
||||
@Field(key: "work_order")
|
||||
var workOrder: Int?
|
||||
|
||||
@Field(key: "materials")
|
||||
var materials: String
|
||||
|
||||
@Field(key: "customer")
|
||||
var customer: String
|
||||
|
||||
@Field(key: "truck_stock")
|
||||
var truckStock: Bool
|
||||
|
||||
@Parent(key: "created_by_id")
|
||||
var createdBy: UserModel
|
||||
|
||||
@Parent(key: "created_for_id")
|
||||
var createdFor: EmployeeModel
|
||||
|
||||
@Parent(key: "vendor_branch_id")
|
||||
var vendorBranch: VendorBranchModel
|
||||
|
||||
@Timestamp(key: "created_at", on: .create)
|
||||
var createdAt: Date?
|
||||
|
||||
@Timestamp(key: "updated_at", on: .update)
|
||||
var updatedAt: Date?
|
||||
|
||||
init() {}
|
||||
|
||||
init(
|
||||
id: Int? = nil,
|
||||
workOrder: Int? = nil,
|
||||
materials: String,
|
||||
customer: String,
|
||||
truckStock: Bool,
|
||||
createdByID: UserModel.IDValue,
|
||||
createdForID: EmployeeModel.IDValue,
|
||||
vendorBranchID: VendorBranchModel.IDValue,
|
||||
createdAt: Date? = nil,
|
||||
updatedAt: Date? = nil
|
||||
) {
|
||||
self.id = id
|
||||
self.workOrder = workOrder
|
||||
self.materials = materials
|
||||
self.customer = customer
|
||||
self.truckStock = truckStock
|
||||
$createdBy.id = createdByID
|
||||
$createdFor.id = createdForID
|
||||
$vendorBranch.id = vendorBranchID
|
||||
self.createdAt = createdAt
|
||||
self.updatedAt = updatedAt
|
||||
}
|
||||
|
||||
func toDTO() throws -> PurchaseOrder {
|
||||
try .init(
|
||||
id: requireID(),
|
||||
workOrder: workOrder,
|
||||
materials: materials,
|
||||
customer: customer,
|
||||
truckStock: truckStock,
|
||||
createdBy: createdBy.toDTO(),
|
||||
createdFor: createdFor.toDTO(),
|
||||
vendorBranch: vendorBranch.toDTO(),
|
||||
createdAt: createdAt,
|
||||
updatedAt: updatedAt
|
||||
)
|
||||
}
|
||||
|
||||
static func allQuery(on db: any Database) -> QueryBuilder<PurchaseOrderModel> {
|
||||
PurchaseOrderModel.query(on: db)
|
||||
.sort(\.$id, .descending)
|
||||
.with(\.$createdBy)
|
||||
.with(\.$createdFor)
|
||||
.with(\.$vendorBranch) { branch in
|
||||
branch.with(\.$vendor)
|
||||
}
|
||||
}
|
||||
}
|
||||
211
Sources/DatabaseClientLive/Users.swift
Normal file
211
Sources/DatabaseClientLive/Users.swift
Normal file
@@ -0,0 +1,211 @@
|
||||
import DatabaseClient
|
||||
import FluentKit
|
||||
import Foundation
|
||||
import HummingbirdBcrypt
|
||||
import SharedModels
|
||||
|
||||
public extension DatabaseClient.Users {
|
||||
|
||||
static func live(database: any Database) -> Self {
|
||||
.init { create in
|
||||
let model = try create.toModel()
|
||||
try await model.save(on: database)
|
||||
return model.toDTO()
|
||||
} delete: { id in
|
||||
guard let model = try await UserModel.find(id, on: database) else {
|
||||
throw NotFoundError()
|
||||
}
|
||||
try await model.delete(on: database)
|
||||
} fetchAll: {
|
||||
try await UserModel.query(on: database).all().map { $0.toDTO() }
|
||||
} get: { id in
|
||||
try await UserModel.find(id, on: database).map { $0.toDTO() }
|
||||
} login: { login in
|
||||
try login.validate()
|
||||
|
||||
var query = UserModel.query(on: database)
|
||||
|
||||
if let username = login.username {
|
||||
query = query.filter(\.$username == username)
|
||||
} else {
|
||||
query = query.filter(\.$email == login.email!)
|
||||
}
|
||||
|
||||
guard let user = try await query.first() else {
|
||||
throw NotFoundError()
|
||||
}
|
||||
|
||||
let token = try user.generateToken()
|
||||
|
||||
try await token.save(on: database)
|
||||
|
||||
return try User.Token(
|
||||
id: token.requireID(),
|
||||
userID: user.requireID(),
|
||||
value: token.value
|
||||
)
|
||||
|
||||
} logout: { id in
|
||||
guard let token = try await UserTokenModel.find(id, on: database)
|
||||
else { return }
|
||||
try await token.delete(on: database)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension User {
|
||||
struct Migrate: AsyncMigration {
|
||||
let name = "CreateUser"
|
||||
|
||||
func prepare(on database: any Database) async throws {
|
||||
try await database.schema(UserModel.schema)
|
||||
.id()
|
||||
.field("username", .string, .required)
|
||||
.field("email", .string, .required)
|
||||
.field("password_hash", .string, .required)
|
||||
.field("created_at", .datetime)
|
||||
.field("updated_at", .datetime)
|
||||
.unique(on: "email", "username")
|
||||
.create()
|
||||
}
|
||||
|
||||
func revert(on database: any Database) async throws {
|
||||
try await database.schema(UserModel.schema).delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension User.Token {
|
||||
struct Migrate: AsyncMigration {
|
||||
let name = "CreateUserToken"
|
||||
|
||||
func prepare(on database: any Database) async throws {
|
||||
try await database.schema(UserTokenModel.schema)
|
||||
.id()
|
||||
.field("value", .string, .required)
|
||||
.field("user_id", .uuid, .required, .references(UserModel.schema, "id"))
|
||||
.unique(on: "value")
|
||||
.create()
|
||||
}
|
||||
|
||||
func revert(on database: any Database) async throws {
|
||||
try await database.schema(UserTokenModel.schema).delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension User.Create {
|
||||
|
||||
func toModel() throws -> UserModel {
|
||||
try validate()
|
||||
return .init(username: username, email: email, passwordHash: Bcrypt.hash(password, cost: 12))
|
||||
}
|
||||
|
||||
func validate() throws {
|
||||
guard !username.isEmpty else {
|
||||
throw ValidationError(message: "Username should not be empty.")
|
||||
}
|
||||
guard !email.isEmpty else {
|
||||
throw ValidationError(message: "Email should not be empty")
|
||||
}
|
||||
guard password.count > 8 else {
|
||||
throw ValidationError(message: "Password should be more than 8 characters long.")
|
||||
}
|
||||
guard password == confirmPassword else {
|
||||
throw ValidationError(message: "Passwords do not match.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension User.Login {
|
||||
|
||||
func validate() throws {
|
||||
guard username != nil || email != nil else {
|
||||
throw ValidationError(message: "Either username or email must be provided to login.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The user database model.
|
||||
///
|
||||
/// A user is someone who is able to login and generate PO's for employees. Generally a user should also
|
||||
/// have an employee profile, but not all employees are users. Users are generally restricted to office workers
|
||||
/// and administrators.
|
||||
///
|
||||
///
|
||||
final class UserModel: Model, @unchecked Sendable {
|
||||
static let schema = "user"
|
||||
|
||||
@ID(key: .id)
|
||||
var id: UUID?
|
||||
|
||||
@Field(key: "username")
|
||||
var username: String
|
||||
|
||||
@Field(key: "email")
|
||||
var email: String
|
||||
|
||||
@Field(key: "password_hash")
|
||||
var passwordHash: String
|
||||
|
||||
@Timestamp(key: "created_at", on: .create)
|
||||
var createdAt: Date?
|
||||
|
||||
@Timestamp(key: "updated_at", on: .update)
|
||||
var updatedAt: Date?
|
||||
|
||||
init() {}
|
||||
|
||||
init(
|
||||
id: UUID? = nil,
|
||||
username: String,
|
||||
email: String,
|
||||
passwordHash: String
|
||||
) {
|
||||
self.id = id
|
||||
self.username = username
|
||||
self.email = email
|
||||
self.passwordHash = passwordHash
|
||||
}
|
||||
|
||||
func toDTO() -> User {
|
||||
.init(
|
||||
id: id,
|
||||
createdAt: createdAt,
|
||||
email: email,
|
||||
updatedAt: updatedAt,
|
||||
username: username
|
||||
)
|
||||
}
|
||||
|
||||
func generateToken() throws -> UserTokenModel {
|
||||
try .init(
|
||||
value: [UInt8].random(count: 16).base64,
|
||||
userID: requireID()
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
final class UserTokenModel: Model, Codable, @unchecked Sendable {
|
||||
|
||||
static let schema = "user_token"
|
||||
|
||||
@ID(key: .id)
|
||||
var id: UUID?
|
||||
|
||||
@Field(key: "value")
|
||||
var value: String
|
||||
|
||||
@Parent(key: "user_id")
|
||||
var user: UserModel
|
||||
|
||||
init() {}
|
||||
|
||||
init(id: UUID? = nil, value: String, userID: UserModel.IDValue) {
|
||||
self.id = id
|
||||
self.value = value
|
||||
$user.id = userID
|
||||
}
|
||||
|
||||
}
|
||||
143
Sources/DatabaseClientLive/VendorBranches.swift
Normal file
143
Sources/DatabaseClientLive/VendorBranches.swift
Normal file
@@ -0,0 +1,143 @@
|
||||
import DatabaseClient
|
||||
import FluentKit
|
||||
import Foundation
|
||||
import SharedModels
|
||||
|
||||
public extension DatabaseClient.VendorBranches {
|
||||
|
||||
static func live(database db: any Database) -> Self {
|
||||
.init { create in
|
||||
let model = try create.toModel()
|
||||
try await model.save(on: db)
|
||||
return model.toDTO()
|
||||
} delete: { id in
|
||||
guard let model = try await VendorBranchModel.find(id, on: db) else {
|
||||
throw NotFoundError()
|
||||
}
|
||||
try await model.delete(on: db)
|
||||
} fetchAll: { request in
|
||||
var query = VendorBranchModel.query(on: db)
|
||||
|
||||
switch request {
|
||||
case .all:
|
||||
break
|
||||
case .withVendor:
|
||||
query = query.with(\.$vendor)
|
||||
case let .for(vendorID: vendorID):
|
||||
let branches = try await VendorModel.query(on: db)
|
||||
.filter(\.$id == vendorID)
|
||||
.with(\.$branches)
|
||||
.first()?
|
||||
.branches
|
||||
.map { $0.toDTO() }
|
||||
|
||||
guard let branches else { throw NotFoundError() }
|
||||
return branches
|
||||
}
|
||||
|
||||
return try await query.all().map { $0.toDTO() }
|
||||
} get: { id in
|
||||
try await VendorBranchModel.find(id, on: db).map { $0.toDTO() }
|
||||
} update: { id, updates in
|
||||
guard let model = try await VendorBranchModel.find(id, on: db) else {
|
||||
throw NotFoundError()
|
||||
}
|
||||
try model.applyUpdates(updates)
|
||||
try await model.save(on: db)
|
||||
return model.toDTO()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension VendorBranch {
|
||||
|
||||
struct Migrate: AsyncMigration {
|
||||
let name = "CreateVendorBranch"
|
||||
|
||||
func prepare(on database: Database) async throws {
|
||||
try await database.schema(VendorBranchModel.schema)
|
||||
.id()
|
||||
.field("name", .string, .required)
|
||||
.field("vendor_id", .uuid, .required)
|
||||
.field("created_at", .datetime)
|
||||
.field("updated_at", .datetime)
|
||||
.foreignKey("vendor_id", references: VendorModel.schema, "id", onDelete: .cascade)
|
||||
.create()
|
||||
}
|
||||
|
||||
func revert(on database: Database) async throws {
|
||||
try await database.schema(VendorBranchModel.schema).delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension VendorBranch.Create {
|
||||
|
||||
func toModel() throws -> VendorBranchModel {
|
||||
try validate()
|
||||
return .init(name: name, vendorId: vendorID)
|
||||
}
|
||||
|
||||
func validate() throws {
|
||||
guard !name.isEmpty else {
|
||||
throw ValidationError(message: "Vendor branch name should not be empty.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension VendorBranch.Update {
|
||||
func validate() throws {
|
||||
if let name {
|
||||
guard !name.isEmpty else {
|
||||
throw ValidationError(message: "Vendor branch name should not be empty.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final class VendorBranchModel: Model, @unchecked Sendable {
|
||||
|
||||
static let schema = "vendor_branch"
|
||||
|
||||
@ID(key: .id)
|
||||
var id: UUID?
|
||||
|
||||
@Field(key: "name")
|
||||
var name: String
|
||||
|
||||
@Timestamp(key: "created_at", on: .create)
|
||||
var createdAt: Date?
|
||||
|
||||
@Timestamp(key: "updated_at", on: .update)
|
||||
var updatedAt: Date?
|
||||
|
||||
@Parent(key: "vendor_id")
|
||||
var vendor: VendorModel
|
||||
|
||||
init() {}
|
||||
|
||||
init(id: UUID? = nil, name: String, vendorId: Vendor.ID) {
|
||||
self.id = id
|
||||
self.name = name
|
||||
$vendor.id = vendorId
|
||||
}
|
||||
|
||||
func toDTO() -> VendorBranch {
|
||||
.init(
|
||||
id: id,
|
||||
name: name,
|
||||
vendorID: $vendor.id,
|
||||
createdAt: createdAt,
|
||||
updatedAt: updatedAt
|
||||
)
|
||||
}
|
||||
|
||||
func applyUpdates(_ updates: VendorBranch.Update) throws {
|
||||
try updates.validate()
|
||||
if let name = updates.name {
|
||||
self.name = name
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
140
Sources/DatabaseClientLive/Vendors.swift
Normal file
140
Sources/DatabaseClientLive/Vendors.swift
Normal file
@@ -0,0 +1,140 @@
|
||||
import DatabaseClient
|
||||
import FluentKit
|
||||
import Foundation
|
||||
import SharedModels
|
||||
|
||||
public extension DatabaseClient.Vendors {
|
||||
|
||||
static func live(database db: any Database) -> Self {
|
||||
.init { create in
|
||||
let model = try create.toModel()
|
||||
try await model.save(on: db)
|
||||
return model.toDTO()
|
||||
} delete: { id in
|
||||
guard let model = try await VendorModel.find(id, on: db) else {
|
||||
throw NotFoundError()
|
||||
}
|
||||
try await model.delete(on: db)
|
||||
} fetchAll: { request in
|
||||
var query = VendorModel.query(on: db).sort(\.$name, .ascending)
|
||||
|
||||
let withBranches = request == .withBranches
|
||||
|
||||
switch request {
|
||||
case .withBranches:
|
||||
query = query.with(\.$branches)
|
||||
case .all:
|
||||
break
|
||||
}
|
||||
|
||||
return try await query.all().map { $0.toDTO(includeBranches: withBranches) }
|
||||
|
||||
} get: { id, request in
|
||||
var query = VendorModel.query(on: db).filter(\.$id == id)
|
||||
let withBranches = request == .withBranches
|
||||
if withBranches {
|
||||
query = query.with(\.$branches)
|
||||
}
|
||||
return try await query.first().map { $0.toDTO(includeBranches: withBranches) }
|
||||
} update: { id, updates in
|
||||
guard let model = try await VendorModel.find(id, on: db) else {
|
||||
throw NotFoundError()
|
||||
}
|
||||
try model.applyUpdates(updates)
|
||||
try await model.save(on: db)
|
||||
return model.toDTO()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Vendor {
|
||||
|
||||
struct Migrate: AsyncMigration {
|
||||
let name = "CreateVendor"
|
||||
|
||||
func prepare(on database: Database) async throws {
|
||||
try await database.schema(VendorModel.schema)
|
||||
.id()
|
||||
.field("name", .string, .required)
|
||||
.field("created_at", .datetime)
|
||||
.field("updated_at", .datetime)
|
||||
.unique(on: "name")
|
||||
.create()
|
||||
}
|
||||
|
||||
func revert(on database: Database) async throws {
|
||||
try await database.schema(VendorModel.schema).delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Vendor.Create {
|
||||
|
||||
func toModel() throws -> VendorModel {
|
||||
try validate()
|
||||
return .init(name: name)
|
||||
}
|
||||
|
||||
func validate() throws {
|
||||
guard !name.isEmpty else {
|
||||
throw ValidationError(message: "Vendor name should not be empty.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Vendor.Update {
|
||||
func validate() throws {
|
||||
if let name {
|
||||
guard !name.isEmpty else {
|
||||
throw ValidationError(message: "Vendor name should not be empty.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The primary database model.
|
||||
final class VendorModel: Model, @unchecked Sendable {
|
||||
|
||||
static let schema = "vendor"
|
||||
|
||||
@ID(key: .id)
|
||||
var id: UUID?
|
||||
|
||||
@Field(key: "name")
|
||||
var name: String
|
||||
|
||||
@Timestamp(key: "created_at", on: .create)
|
||||
var createdAt: Date?
|
||||
|
||||
@Timestamp(key: "updated_at", on: .update)
|
||||
var updatedAt: Date?
|
||||
|
||||
@Children(for: \.$vendor)
|
||||
var branches: [VendorBranchModel]
|
||||
|
||||
init() {}
|
||||
|
||||
init(id: UUID? = nil, name: String) {
|
||||
self.id = id
|
||||
self.name = name
|
||||
}
|
||||
|
||||
func toDTO(includeBranches: Bool? = nil) -> Vendor {
|
||||
.init(
|
||||
id: id,
|
||||
name: name,
|
||||
branches: ($branches.value != nil && $branches.value!.count > 0)
|
||||
? $branches.value!.map { $0.toDTO() }
|
||||
: [],
|
||||
createdAt: createdAt,
|
||||
updatedAt: updatedAt
|
||||
)
|
||||
}
|
||||
|
||||
func applyUpdates(_ updates: Vendor.Update) throws {
|
||||
try updates.validate()
|
||||
if let name = updates.name {
|
||||
self.name = name
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import Dependencies
|
||||
import Foundation
|
||||
|
||||
public struct Employee: Equatable, Identifiable, Sendable {
|
||||
public struct Employee: Codable, Equatable, Identifiable, Sendable {
|
||||
public var id: UUID
|
||||
public var active: Bool
|
||||
public var createdAt: Date
|
||||
@@ -10,7 +10,7 @@ public struct Employee: Equatable, Identifiable, Sendable {
|
||||
public var updatedAt: Date
|
||||
|
||||
public init(
|
||||
id: UUID?,
|
||||
id: UUID? = nil,
|
||||
active: Bool = true,
|
||||
createdAt: Date? = nil,
|
||||
firstName: String,
|
||||
@@ -22,10 +22,20 @@ public struct Employee: Equatable, Identifiable, Sendable {
|
||||
|
||||
self.id = id ?? uuid()
|
||||
self.active = active
|
||||
self.createdAt = createdAt ?? date()
|
||||
self.createdAt = createdAt ?? date.now
|
||||
self.firstName = firstName
|
||||
self.lastName = lastName
|
||||
self.updatedAt = updatedAt ?? date()
|
||||
self.updatedAt = updatedAt ?? date.now
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public extension Employee {
|
||||
static var mocks: [Self] {
|
||||
[
|
||||
.init(firstName: "Michael", lastName: "Housh"),
|
||||
.init(firstName: "Blob", lastName: "Esquire"),
|
||||
.init(firstName: "Testy", lastName: "McTestface")
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
40
Sources/SharedModels/PurchaseOrder.swift
Normal file
40
Sources/SharedModels/PurchaseOrder.swift
Normal file
@@ -0,0 +1,40 @@
|
||||
import Dependencies
|
||||
import Foundation
|
||||
|
||||
public struct PurchaseOrder: Codable, Equatable, Identifiable, Sendable {
|
||||
|
||||
public let id: Int
|
||||
public var workOrder: Int?
|
||||
public var materials: String
|
||||
public var customer: String
|
||||
public var truckStock: Bool
|
||||
public var createdBy: User
|
||||
public var createdFor: Employee
|
||||
public var vendorBranch: VendorBranch
|
||||
public var createdAt: Date?
|
||||
public var updatedAt: Date?
|
||||
|
||||
public init(
|
||||
id: Int,
|
||||
workOrder: Int? = nil,
|
||||
materials: String,
|
||||
customer: String,
|
||||
truckStock: Bool,
|
||||
createdBy: User,
|
||||
createdFor: Employee,
|
||||
vendorBranch: VendorBranch,
|
||||
createdAt: Date?,
|
||||
updatedAt: Date?
|
||||
) {
|
||||
self.id = id
|
||||
self.workOrder = workOrder
|
||||
self.materials = materials
|
||||
self.customer = customer
|
||||
self.truckStock = truckStock
|
||||
self.createdBy = createdBy
|
||||
self.createdFor = createdFor
|
||||
self.vendorBranch = vendorBranch
|
||||
self.createdAt = createdAt
|
||||
self.updatedAt = updatedAt
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import Dependencies
|
||||
import Foundation
|
||||
|
||||
public struct User: Identifiable, Codable, Sendable {
|
||||
public struct User: Codable, Equatable, Identifiable, Sendable {
|
||||
|
||||
public var id: UUID
|
||||
public var createdAt: Date
|
||||
@@ -20,9 +20,9 @@ public struct User: Identifiable, Codable, Sendable {
|
||||
@Dependency(\.uuid) var uuid
|
||||
|
||||
self.id = id ?? uuid()
|
||||
self.createdAt = createdAt ?? date()
|
||||
self.createdAt = createdAt ?? date.now
|
||||
self.email = email
|
||||
self.updatedAt = updatedAt ?? date()
|
||||
self.updatedAt = updatedAt ?? date.now
|
||||
self.username = username
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,38 @@
|
||||
import Dependencies
|
||||
import Foundation
|
||||
|
||||
public struct Vendor: Identifiable, Equatable, Sendable {
|
||||
public struct Vendor: Codable, Equatable, Identifiable, Sendable {
|
||||
public var id: UUID
|
||||
public var createdAt: Date
|
||||
public var name: String
|
||||
public var branches: [VendorBranch]?
|
||||
public var createdAt: Date
|
||||
public var updatedAt: Date
|
||||
|
||||
public init(
|
||||
id: UUID? = nil,
|
||||
createdAt: Date? = nil,
|
||||
name: String,
|
||||
branches: [VendorBranch]? = nil,
|
||||
createdAt: Date? = nil,
|
||||
updatedAt: Date? = nil
|
||||
) {
|
||||
@Dependency(\.date) var date
|
||||
@Dependency(\.uuid) var uuid
|
||||
|
||||
self.id = id ?? uuid()
|
||||
self.createdAt = createdAt ?? date()
|
||||
self.name = name
|
||||
self.updatedAt = updatedAt ?? date()
|
||||
self.branches = branches
|
||||
self.createdAt = createdAt ?? date.now
|
||||
self.updatedAt = updatedAt ?? date.now
|
||||
}
|
||||
}
|
||||
|
||||
public extension Vendor {
|
||||
|
||||
static var mocks: [Self] {
|
||||
[
|
||||
.init(name: "Corken"),
|
||||
.init(name: "Johnstone"),
|
||||
.init(name: "Winstel Controls")
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import Dependencies
|
||||
import Foundation
|
||||
|
||||
public struct VendorBranch: Codable, Equatable, Identifiable, Sendable {
|
||||
public var id: UUID
|
||||
public var name: String
|
||||
public var vendorID: Vendor.ID
|
||||
public var createdAt: Date
|
||||
public var updatedAt: Date
|
||||
|
||||
public init(
|
||||
id: UUID? = nil,
|
||||
name: String,
|
||||
vendorID: Vendor.ID,
|
||||
createdAt: Date? = nil,
|
||||
updatedAt: Date? = nil
|
||||
) {
|
||||
@Dependency(\.date) var date
|
||||
@Dependency(\.uuid) var uuid
|
||||
|
||||
self.id = id ?? uuid()
|
||||
self.name = name
|
||||
self.vendorID = vendorID
|
||||
self.createdAt = createdAt ?? date.now
|
||||
self.updatedAt = updatedAt ?? date.now
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user