@@ -47,7 +47,10 @@ public struct APIClient: Sendable {
4747 public var markReadForum : @Sendable ( _ id: Int , _ isTopic: Bool ) async throws -> Bool
4848 public var getAnnouncement : @Sendable ( _ id: Int ) async throws -> Announcement
4949 public var getTopic : @Sendable ( _ id: Int , _ page: Int , _ perPage: Int ) async throws -> Topic
50+ public var getTemplate : @Sendable ( _ request: ForumTemplateRequest , _ isTopic: Bool ) async throws -> [ WriteFormFieldType ]
5051 public var getHistory : @Sendable ( _ offset: Int , _ perPage: Int ) async throws -> History
52+ public var previewPost : @Sendable ( _ request: PostPreviewRequest ) async throws -> PostPreview
53+ public var sendPost : @Sendable ( _ request: PostRequest ) async throws -> PostSend
5154
5255 // Favorites
5356 public var getFavorites : @Sendable ( _ request: FavoritesRequest , _ policy: CachePolicy ) async throws -> AsyncThrowingStream < Favorite , any Error >
@@ -224,11 +227,39 @@ extension APIClient: DependencyKey {
224227 let request = TopicRequest ( id: id, offset: offset, itemsPerPage: perPage, showPostMode: 1 )
225228 let response = try await api. get ( ForumCommand . Topic. view ( data: request) )
226229 return try await parser. parseTopic ( response)
230+ } ,
231+ getTemplate: { request, isTopic in
232+ let command = ForumCommand . template (
233+ type: isTopic ? . topic( forumId: request. id) : . post( topicId: request. id) ,
234+ action: request. action. transferType
235+ )
236+ let response = try await api. get ( command)
237+ return try await parser. parseWriteForm ( response)
227238 } ,
228239 getHistory: { offset, perPage in
229240 let response = try await api. get ( MemberCommand . history ( page: offset, perPage: perPage) )
230241 return try await parser. parseHistory ( response)
231242 } ,
243+ previewPost: { request in
244+ let command = ForumCommand . Post. preview ( data: PostSendRequest (
245+ topicId: request. post. topicId,
246+ content: request. post. content,
247+ attaches: request. post. attachments,
248+ flag: request. post. flag
249+ ) , postId: request. id)
250+ let response = try await api. get ( command)
251+ return try await parser. parsePostPreview ( response)
252+ } ,
253+ sendPost: { request in
254+ let command = ForumCommand . Post. send ( data: PostSendRequest (
255+ topicId: request. topicId,
256+ content: request. content,
257+ attaches: request. attachments,
258+ flag: request. flag
259+ ) )
260+ let response = try await api. get ( command)
261+ return try await parser. parsePostSend ( response)
262+ } ,
232263
233264 // MARK: - Favorites
234265
@@ -368,10 +399,19 @@ extension APIClient: DependencyKey {
368399 } ,
369400 getTopic: { _, _, _ in
370401 return . mock
402+ } ,
403+ getTemplate: { _, _ in
404+ return [ . mockTitle, . mockText, . mockEditor]
371405 } ,
372406 getHistory: { _, _ in
373407 return . mock
374408 } ,
409+ previewPost: { _ in
410+ return PostPreview ( content: " Post Content... " , attachmentIds: [ ] )
411+ } ,
412+ sendPost: { _ in
413+ return PostSend ( id: 0 , topicId: 1 , offset: 2 )
414+ } ,
375415 getFavorites: { _, _ in
376416 . finished( )
377417 } ,
0 commit comments