Skip to content

Commit

Permalink
Modularization
Browse files Browse the repository at this point in the history
  • Loading branch information
grdsdev committed Jan 21, 2023
1 parent 7177e1e commit fecd6a5
Show file tree
Hide file tree
Showing 41 changed files with 1,690 additions and 944 deletions.
1 change: 1 addition & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
--wrapparameters before-first
--extensionacl on-declarations
--maxwidth 100
--header \n {file}\n (c) {created.year} Binary Scraping Co.\n LICENSE: MIT\n

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
BlueprintIdentifier = "7967ACA72956200300C30D93"
BuildableName = "App.app"
BlueprintName = "App"
ReferencedContainer = "container:SupaSlack.xcodeproj">
ReferencedContainer = "container:App.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
Expand Down Expand Up @@ -47,7 +47,7 @@
BlueprintIdentifier = "7967ACA72956200300C30D93"
BuildableName = "App.app"
BlueprintName = "App"
ReferencedContainer = "container:SupaSlack.xcodeproj">
ReferencedContainer = "container:App.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
Expand All @@ -64,7 +64,7 @@
BlueprintIdentifier = "7967ACA72956200300C30D93"
BuildableName = "App.app"
BlueprintName = "App"
ReferencedContainer = "container:SupaSlack.xcodeproj">
ReferencedContainer = "container:App.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
Expand Down
10 changes: 10 additions & 0 deletions App/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// swift-tools-version: 5.7

import PackageDescription

let package = Package(
name: "App",
products: [],
dependencies: [],
targets: []
)
160 changes: 83 additions & 77 deletions App/Sources/APIClient.swift
Original file line number Diff line number Diff line change
@@ -1,78 +1,84 @@
import Dependencies
import Foundation
@preconcurrency import Supabase
import XCTestDynamicOverlay
//
// APIClient.swift
// (c) 2022 Binary Scraping Co.
// LICENSE: MIT
//

struct APIClient {
var fetchChannels: @Sendable () async throws -> [Channel]
var fetchUser: @Sendable (User.ID) async throws -> User
var fetchMessages: @Sendable (Channel.ID) async throws -> [MessageResponse]
var addMessage: @Sendable (String, Channel.ID, User.ID) async throws -> MessageResponse
}

struct AddMessagePayload: Encodable {
let message: String
let channelId: Channel.ID
let userId: User.ID

enum CodingKeys: String, CodingKey {
case message
case channelId = "channel_id"
case userId = "user_id"
}
}

extension APIClient: DependencyKey {
static var liveValue: Self {
@Dependency(\.supabase) var supabase

return Self(
fetchChannels: {
try await supabase.database.from("channels").select().execute().value
},
fetchUser: { id in
try await supabase.database
.from("users")
.select()
.eq(column: "id", value: id.rawValue)
.single()
.execute()
.value
},
fetchMessages: { channelId in
try await supabase.database
.from("messages")
.select(columns: "*, author:user_id(*),channel:channel_id(*)")
.eq(column: "channel_id", value: channelId.rawValue)
.order(column: "inserted_at", ascending: false)
.execute()
.value
},
addMessage: { message, channelId, userId in
try await supabase.database
.from("messages")
.insert(
values: AddMessagePayload(message: message, channelId: channelId, userId: userId),
returning: .representation
)
.single()
.execute()
.value
}
)
}

static let testValue = Self(
fetchChannels: XCTUnimplemented("APIClient.fetchChannels"),
fetchUser: XCTUnimplemented("APIClient.fetchUser"),
fetchMessages: XCTUnimplemented("APIClient.fetchMessages"),
addMessage: XCTUnimplemented("APIClient.addMessage")
)
}

extension DependencyValues {
var api: APIClient {
get { self[APIClient.self] }
set { self[APIClient.self] = newValue }
}
}
// import Dependencies
// import Foundation
// @preconcurrency import Supabase
// import XCTestDynamicOverlay
//
// struct APIClient {
// var fetchChannels: @Sendable () async throws -> [Channel]
// var fetchUser: @Sendable (User.ID) async throws -> User
// var fetchMessages: @Sendable (Channel.ID) async throws -> [MessageResponse]
// var addMessage: @Sendable (String, Channel.ID, User.ID) async throws -> MessageResponse
// }
//
// struct AddMessagePayload: Encodable {
// let message: String
// let channelId: Channel.ID
// let userId: User.ID
//
// enum CodingKeys: String, CodingKey {
// case message
// case channelId = "channel_id"
// case userId = "user_id"
// }
// }
//
// extension APIClient: DependencyKey {
// static var liveValue: Self {
// @Dependency(\.supabase) var supabase
//
// return Self(
// fetchChannels: {
// try await supabase.database.from("channels").select().execute().value
// },
// fetchUser: { id in
// try await supabase.database
// .from("users")
// .select()
// .eq(column: "id", value: id.rawValue)
// .single()
// .execute()
// .value
// },
// fetchMessages: { channelId in
// try await supabase.database
// .from("messages")
// .select(columns: "*, author:user_id(*),channel:channel_id(*)")
// .eq(column: "channel_id", value: channelId.rawValue)
// .order(column: "inserted_at", ascending: false)
// .execute()
// .value
// },
// addMessage: { message, channelId, userId in
// try await supabase.database
// .from("messages")
// .insert(
// values: AddMessagePayload(message: message, channelId: channelId, userId: userId),
// returning: .representation
// )
// .single()
// .execute()
// .value
// }
// )
// }
//
// static let testValue = Self(
// fetchChannels: XCTUnimplemented("APIClient.fetchChannels"),
// fetchUser: XCTUnimplemented("APIClient.fetchUser"),
// fetchMessages: XCTUnimplemented("APIClient.fetchMessages"),
// addMessage: XCTUnimplemented("APIClient.addMessage")
// )
// }
//
// extension DependencyValues {
// var api: APIClient {
// get { self[APIClient.self] }
// set { self[APIClient.self] = newValue }
// }
// }
100 changes: 0 additions & 100 deletions App/Sources/AuthClient.swift

This file was deleted.

Loading

0 comments on commit fecd6a5

Please sign in to comment.