SynthReel/SynthReel/Base/API/SRHomeApi.swift
2025-11-24 16:49:59 +08:00

123 lines
4.4 KiB
Swift

//
// SRHomeApi.swift
// SynthReel
//
// Created by on 2025/11/14.
// Copyright © 2025 SR. All rights reserved.
//
import UIKit
import Alamofire
struct SRHomeApi {
static func requestCategoryList() async -> [SRCategoryModel]? {
await withCheckedContinuation { continuation in
var param = SRNetwork.Parameters(path: "/getCategories")
param.method = .get
SRNetwork.request(parameters: param) { (response: SRNetwork.Response<SRNetwork.List<SRCategoryModel>>) in
continuation.resume(returning: response.data?.list)
}
}
}
static func requestHomeModulesData() async -> [SRHomeModuleItem]? {
await withCheckedContinuation { continuation in
var param = SRNetwork.Parameters(path: "/home/all-modules")
param.method = .get
SRNetwork.request(parameters: param) { (response: SRNetwork.Response<SRNetwork.List<SRHomeModuleItem>>) in
continuation.resume(returning: response.data?.list)
}
}
}
static func requestCategoryVideoData(_ id: String, page: Int) async -> [SRShortModel]? {
await withCheckedContinuation { continuation in
var param = SRNetwork.Parameters(path: "/videoList")
param.method = .get
param.parameters = [
"category_id" : id,
"current_page" : page,
"page_size" : 20
]
SRNetwork.request(parameters: param) { (response: SRNetwork.Response<SRNetwork.List<SRShortModel>>) in
continuation.resume(returning: response.data?.list)
}
}
}
static func requestHotSearchData() async -> [SRShortModel]? {
await withCheckedContinuation { continuation in
var param = SRNetwork.Parameters(path: "/search/hots")
param.method = .get
SRNetwork.request(parameters: param) { (response: SRNetwork.Response<SRNetwork.List<SRShortModel>>) in
continuation.resume(returning: response.data?.list)
}
}
}
static func requestSearch(_ text: String) async -> [SRShortModel]? {
await withCheckedContinuation { continuation in
var param = SRNetwork.Parameters(path: "/search")
param.method = .get
param.parameters = [
"search" : text
]
SRNetwork.request(parameters: param) { (response: SRNetwork.Response<SRNetwork.List<SRShortModel>>) in
continuation.resume(returning: response.data?.list)
}
}
}
static func requestHomeRecommendData(page: Int) async -> [SRShortModel]? {
await withCheckedContinuation { continuation in
var param = SRNetwork.Parameters(path: "/getRecommands")
param.method = .get
param.parameters = [
"page_size" : 20,
"current_page" : page
]
SRNetwork.request(parameters: param) { (response: SRNetwork.Response<SRNetwork.List<SRShortModel>>) in
continuation.resume(returning: response.data?.list)
}
}
}
static func requestHistoryData(page: Int) async -> [SRShortModel]? {
await withCheckedContinuation { continuation in
var param = SRNetwork.Parameters(path: "/myHistorys")
param.method = .get
param.parameters = [
"page_size" : 20,
"current_page" : page
]
SRNetwork.request(parameters: param) { (response: SRNetwork.Response<SRNetwork.List<SRShortModel>>) in
continuation.resume(returning: response.data?.list)
}
}
}
static func requestFavoritesData(page: Int) async -> [SRShortModel]? {
await withCheckedContinuation { continuation in
var param = SRNetwork.Parameters(path: "/myCollections")
param.method = .get
param.parameters = [
"page_size" : 20,
"current_page" : page
]
SRNetwork.request(parameters: param) { (response: SRNetwork.Response<SRNetwork.List<SRShortModel>>) in
continuation.resume(returning: response.data?.list)
}
}
}
}