-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
1,690 additions
and
944 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
256 changes: 30 additions & 226 deletions
256
App/SupaSlack.xcodeproj/project.pbxproj → App/App.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: [] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
// } | ||
// } |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.