Skip to content

Commit c57b936

Browse files
committed
refact: update doc of FavoriteServiceProtocol
1 parent b2c6886 commit c57b936

File tree

2 files changed

+39
-34
lines changed

2 files changed

+39
-34
lines changed

Sources/VRCKit/Protocols/FavoriteServiceProtocol.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,52 @@
66
//
77

88
public protocol FavoriteServiceProtocol: Sendable {
9+
/// Asynchronously retrieves a list of favorite groups from the server.
10+
/// - Returns: An array of `FavoriteGroup` objects.
911
func listFavoriteGroups() async throws -> [FavoriteGroup]
12+
13+
/// Lists a user's all favorites with the specified parameters.
14+
/// - Parameter type: The type of favorite (e.g., friend, world).
15+
/// - Returns: An array of `Favorite` objects.
1016
func listFavorites(type: FavoriteType) async throws -> [Favorite]
17+
18+
/// Lists a user's favorites with the specified parameters.
19+
/// - Parameters:
20+
/// - n: The number of favorites to retrieve. Default is `60`.
21+
/// - offset: Offset value of favorites to retrive. Default is `0`.
22+
/// - type: The type of favorite (e.g., friend, world).
23+
/// - tag: An optional tag to filter favorites.
24+
/// - Returns: An array of `Favorite` objects.
25+
func listFavorites(n: Int, offset: Int, type: FavoriteType, tag: String?) async throws -> [Favorite]
26+
27+
/// Fetches details of favorite groups asynchronously.
28+
/// - Parameters:
29+
/// - favoriteGroups: An array of `FavoriteGroup` objects.
30+
/// - type: The type of favorite (e.g., friend, world).
31+
/// - Returns: An array of `FavoriteList` objects containing detailed information about the favorite groups.
1132
func fetchFavoriteList(favoriteGroups: [FavoriteGroup], type: FavoriteType) async throws -> [FavoriteList]
33+
34+
/// Adds a new favorite to a specific group.
35+
/// - Parameters:
36+
/// - type: The type of favorite (e.g., friend, world).
37+
/// - favoriteId: The ID of the item to favorite.
38+
/// - tag: The tag to associate with the favorite.
39+
/// - Returns: The newly added `Favorite` object.
1240
func addFavorite(type: FavoriteType, favoriteId: String, tag: String) async throws -> Favorite
41+
42+
/// Updates a favorite group with the given parameters, display name, and visibility.
43+
/// - Parameters:
44+
/// - source: An object containing the favorite group's details.
45+
/// - displayName: The new display name to update the favorite group with.
46+
/// - visibility: The new visibility setting for the favorite group.
1347
func updateFavoriteGroup(
1448
source: FavoriteGroup,
1549
displayName: String,
1650
visibility: FavoriteGroup.Visibility
1751
) async throws
52+
53+
/// Asynchronously remove favorite.
54+
/// - Parameter favoriteId: The ID of the favorite to remove.
55+
/// - Returns: A `SuccessResponse` objects.
1856
func removeFavorite(favoriteId: String) async throws -> SuccessResponse
1957
}

Sources/VRCKit/Services/FavoriteService.swift

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,12 @@ public final actor FavoriteService: APIService, FavoriteServiceProtocol {
1414
private let limit = 100
1515
private let maxCount = 400
1616

17-
/// Asynchronously retrieves a list of favorite groups from the server.
18-
/// - Returns: An array of `FavoriteGroup` objects.
1917
public func listFavoriteGroups() async throws -> [FavoriteGroup] {
2018
let path = "favorite/groups"
2119
let response = try await client.request(path: path, method: .get)
2220
return try Serializer.shared.decode(response.data)
2321
}
2422

25-
/// Lists a user's all favorites with the specified parameters.
26-
/// - Parameter type: The type of favorite (e.g., friend, world).
27-
/// - Returns: An array of `Favorite` objects.
2823
public func listFavorites(type: FavoriteType) async throws -> [Favorite] {
2924
try await withThrowingTaskGroup(of: [Favorite].self) { taskGroup in
3025
for offset in stride(from: .zero, to: maxCount, by: limit) {
@@ -41,13 +36,7 @@ public final actor FavoriteService: APIService, FavoriteServiceProtocol {
4136
}
4237
}
4338

44-
/// Lists a user's favorites with the specified parameters.
45-
/// - Parameters:
46-
/// - n: The number of favorites to retrieve. Default is `60``.
47-
/// - type: The type of favorite (e.g., friend, world).
48-
/// - tag: An optional tag to filter favorites.
49-
/// - Returns: An array of `Favorite` objects.
50-
private func listFavorites(
39+
public func listFavorites(
5140
n: Int = 100,
5241
offset: Int = 0,
5342
type: FavoriteType,
@@ -66,11 +55,6 @@ public final actor FavoriteService: APIService, FavoriteServiceProtocol {
6655
return try Serializer.shared.decode(response.data)
6756
}
6857

69-
/// Fetches details of favorite groups asynchronously.
70-
/// - Parameters:
71-
/// - favoriteGroups: An array of `FavoriteGroup` objects.
72-
/// - type: The type of favorite (e.g., friend, world).
73-
/// - Returns: An array of `FavoriteDetail` objects containing detailed information about the favorite groups.
7458
public func fetchFavoriteList(favoriteGroups: [FavoriteGroup], type: FavoriteType) async throws -> [FavoriteList] {
7559
try await withThrowingTaskGroup(of: FavoriteList.self) { taskGroup in
7660
for favoriteGroup in favoriteGroups.filter({ $0.type == type }) {
@@ -88,12 +72,6 @@ public final actor FavoriteService: APIService, FavoriteServiceProtocol {
8872
}
8973
}
9074

91-
/// Adds a new favorite to a specific group.
92-
/// - Parameters:
93-
/// - type: The type of favorite (e.g., friend, world).
94-
/// - favoriteId: The ID of the item to favorite.
95-
/// - tag: The tag to associate with the favorite.
96-
/// - Returns: The newly added `Favorite` object.
9775
public func addFavorite(
9876
type: FavoriteType,
9977
favoriteId: String,
@@ -107,14 +85,6 @@ public final actor FavoriteService: APIService, FavoriteServiceProtocol {
10785
return try Serializer.shared.decode(response.data)
10886
}
10987

110-
/// Updates a favorite group with the given parameters, display name, and visibility.
111-
/// - Parameters:
112-
/// - params: A tuple containing the favorite group's details:
113-
/// - type: The type of the favorite group, defined by `FavoriteType`.
114-
/// - name: The name of the favorite group.
115-
/// - userId: The ID of the user associated with the favorite group.
116-
/// - displayName: The new display name to update the favorite group with.
117-
/// - visibility: The new visibility setting for the favorite group.
11888
public func updateFavoriteGroup(
11989
source: FavoriteGroup,
12090
displayName: String,
@@ -127,9 +97,6 @@ public final actor FavoriteService: APIService, FavoriteServiceProtocol {
12797
_ = try await client.request(path: path, method: .put, body: requestData)
12898
}
12999

130-
/// Asynchronously remove favorite.
131-
/// - Parameter favoriteId: The ID of the favorite to remove.
132-
/// - Returns: A `SuccessResponse` objects.
133100
public func removeFavorite(favoriteId: String) async throws -> SuccessResponse {
134101
let path = "favorites/\(favoriteId)"
135102
let response = try await client.request(path: path, method: .delete)

0 commit comments

Comments
 (0)