Skip to content

Commit

Permalink
refact: reimplement the favorites group update method
Browse files Browse the repository at this point in the history
  • Loading branch information
makinosp committed Oct 6, 2024
1 parent 8a97642 commit 48f6e91
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
3 changes: 2 additions & 1 deletion Sources/VRCKit/Models/Favorite/FavoriteModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ struct RequestToAddFavorite: Codable, Sendable {
let tags: [String]
}

@MemberwiseInit
struct RequestToUpdateFavoriteGroup: Codable, Sendable {
let displayName: String?
let visibility: FavoriteGroup.Visibility?
let tags: [String]
@Init(default: []) let tags: [String]
}
7 changes: 3 additions & 4 deletions Sources/VRCKit/Protocols/FavoriteServiceProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
//

public protocol FavoriteServiceProtocol: Sendable {
typealias FavoriteGroupParams = (type: FavoriteType, name: String, userId: String)
func listFavoriteGroups() async throws -> [FavoriteGroup]
func listFavorites(n: Int, type: FavoriteType, tag: String?) async throws -> [Favorite]
func fetchFavoriteGroupDetails(favoriteGroups: [FavoriteGroup]) async throws -> [FavoriteDetail]
func addFavorite(type: FavoriteType, favoriteId: String, tag: String) async throws -> Favorite
func updateFavoriteGroup(
type: FavoriteType,
params: FavoriteGroupParams,
displayName: String,
visibility: FavoriteGroup.Visibility,
userId: String,
tag: String
visibility: FavoriteGroup.Visibility
) async throws -> SuccessResponse
func removeFavorite(favoriteId: String) async throws -> SuccessResponse
}
22 changes: 14 additions & 8 deletions Sources/VRCKit/Services/FavoriteService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,24 @@ public final actor FavoriteService: APIService, FavoriteServiceProtocol {
return try await Serializer.shared.decode(response.data)
}

/// Updates a favorite group with the given parameters, display name, and visibility.
/// - Parameters:
/// - params: A tuple containing the favorite group's details:
/// - type: The type of the favorite group, defined by `FavoriteType`.
/// - name: The name of the favorite group.
/// - userId: The ID of the user associated with the favorite group.
/// - displayName: The new display name to update the favorite group with.
/// - visibility: The new visibility setting for the favorite group.
/// - Returns: A `SuccessResponse` if the update is successful.
public func updateFavoriteGroup(
type: FavoriteType,
params: FavoriteGroupParams,
displayName: String,
visibility: FavoriteGroup.Visibility,
userId: String,
tag: String
visibility: FavoriteGroup.Visibility
) async throws -> SuccessResponse {
let pathParams = ["favorite", "groups", type.rawValue, displayName, userId]
let pathParams = ["favorite", "groups", params.type.rawValue, params.name, params.userId]
let path = pathParams.joined(separator: "/")
let requestData = try await Serializer.shared.encode(
RequestToUpdateFavoriteGroup(displayName: displayName, visibility: visibility, tags: [tag])
)
let body = RequestToUpdateFavoriteGroup(displayName: displayName, visibility: visibility)
let requestData = try await Serializer.shared.encode(body)
let response = try await client.request(path: path, method: .put, body: requestData)
return try await Serializer.shared.decode(response.data)
}
Expand Down

0 comments on commit 48f6e91

Please sign in to comment.