feat: working on detail views.

This commit is contained in:
2025-01-12 17:42:06 -05:00
parent 0e31d2c30c
commit 1ce369e156
27 changed files with 527 additions and 137 deletions

View File

@@ -15,14 +15,19 @@ extension DependencyValues {
@DependencyClient
struct EmployeeDB: Sendable {
var create: @Sendable (Employee.Create) async throws -> Employee.DTO
var fetchAll: @Sendable (Bool) async throws -> [Employee.DTO]
var fetchAll: @Sendable (FetchRequest) async throws -> [Employee.DTO]
var get: @Sendable (Employee.IDValue) async throws -> Employee.DTO?
var update: @Sendable (Employee.IDValue, Employee.Update) async throws -> Employee.DTO
var delete: @Sendable (Employee.IDValue) async throws -> Void
var toggleActive: @Sendable (Employee.IDValue) async throws -> Employee.DTO
enum FetchRequest {
case active
case `default`
}
func fetchAll() async throws -> [Employee.DTO] {
try await fetchAll(false)
try await fetchAll(.default)
}
func get(_ id: String?) async throws -> Employee.DTO? {
@@ -43,12 +48,12 @@ extension EmployeeDB: TestDependencyKey {
try await model.save(on: database)
return model.toDTO()
},
fetchAll: { active in
fetchAll: { request in
var query = Employee.query(on: database)
.sort(\.$lastName)
if active {
query = query.filter(\.$active == active)
if request == .active {
query = query.filter(\.$active == true)
}
return try await query.all().map { $0.toDTO() }