初始提交
This commit is contained in:
78
suixinkan/Features/Account/API/AccountContextAPI.swift
Normal file
78
suixinkan/Features/Account/API/AccountContextAPI.swift
Normal file
@ -0,0 +1,78 @@
|
||||
//
|
||||
// AccountContextAPI.swift
|
||||
// suixinkan
|
||||
//
|
||||
// Created by Codex on 2026/6/22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Observation
|
||||
|
||||
@MainActor
|
||||
/// 账号上下文服务协议,抽象权限、景区、门店和景点读取能力以便测试替换。
|
||||
protocol AccountContextServing {
|
||||
/// 获取当前账号的角色权限列表。
|
||||
func rolePermissions() async throws -> [RolePermissionResponse]
|
||||
|
||||
/// 获取当前账号可访问的景区列表。
|
||||
func scenicListAll() async throws -> ScenicListAllResponse
|
||||
|
||||
/// 获取当前账号可访问的门店列表。
|
||||
func storeAll() async throws -> ListPayload<StoreItem>
|
||||
|
||||
/// 获取指定景区下的景点或打卡点列表。
|
||||
func scenicSpotListAll(scenicId: Int) async throws -> ListPayload<ScenicSpotItem>
|
||||
}
|
||||
|
||||
@MainActor
|
||||
@Observable
|
||||
/// 账号上下文 API,封装角色权限、景区、门店和景点读取接口。
|
||||
final class AccountContextAPI: AccountContextServing {
|
||||
@ObservationIgnored private let client: APIClient
|
||||
|
||||
/// 初始化账号上下文 API,并注入共享网络客户端。
|
||||
init(client: APIClient) {
|
||||
self.client = client
|
||||
}
|
||||
|
||||
/// 获取当前账号的角色权限列表。
|
||||
func rolePermissions() async throws -> [RolePermissionResponse] {
|
||||
try await client.send(
|
||||
APIRequest(
|
||||
method: .get,
|
||||
path: "/api/yf-handset-app/role-permission"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/// 获取当前账号可访问的景区列表。
|
||||
func scenicListAll() async throws -> ScenicListAllResponse {
|
||||
try await client.send(
|
||||
APIRequest(
|
||||
method: .get,
|
||||
path: "/api/yf-handset-app/photog/scenic/list-all"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/// 获取当前账号可访问的门店列表。
|
||||
func storeAll() async throws -> ListPayload<StoreItem> {
|
||||
try await client.send(
|
||||
APIRequest(
|
||||
method: .get,
|
||||
path: "/api/app/store/all"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/// 获取指定景区下的景点或打卡点列表。
|
||||
func scenicSpotListAll(scenicId: Int) async throws -> ListPayload<ScenicSpotItem> {
|
||||
try await client.send(
|
||||
APIRequest(
|
||||
method: .get,
|
||||
path: "/api/yf-handset-app/photog/scenic-spot/list-all",
|
||||
queryItems: [URLQueryItem(name: "scenic_id", value: "\(scenicId)")]
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user