From 496ce8cab7692568b409c0067dc2f91aeff87eed Mon Sep 17 00:00:00 2001 From: makinosp Date: Mon, 7 Oct 2024 11:36:30 +0900 Subject: [PATCH 1/5] feat: add FavoriteGroupParams initializer by FavoriteGroup --- Sources/VRCKit/Models/Favorite/FavoriteGroupModel.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/VRCKit/Models/Favorite/FavoriteGroupModel.swift b/Sources/VRCKit/Models/Favorite/FavoriteGroupModel.swift index 9021843..01a0c62 100644 --- a/Sources/VRCKit/Models/Favorite/FavoriteGroupModel.swift +++ b/Sources/VRCKit/Models/Favorite/FavoriteGroupModel.swift @@ -35,3 +35,9 @@ public struct FavoriteGroupParams: Sendable { public let name: String public let userId: String } + +public extension FavoriteGroupParams { + init(favoriteGroup source: FavoriteGroup) { + self.init(type: source.type, name: source.name, userId: source.ownerId) + } +} From 98755ee413c8a77e72a0fc2a496b49aa58f31753 Mon Sep 17 00:00:00 2001 From: makinosp Date: Mon, 7 Oct 2024 11:44:08 +0900 Subject: [PATCH 2/5] refact: remove unnecessary code --- .../VRCKit/Models/Favorite/FavoriteGroupModel.swift | 13 ------------- .../VRCKit/Protocols/FavoriteServiceProtocol.swift | 2 +- Sources/VRCKit/Services/FavoriteService.swift | 4 ++-- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/Sources/VRCKit/Models/Favorite/FavoriteGroupModel.swift b/Sources/VRCKit/Models/Favorite/FavoriteGroupModel.swift index 01a0c62..f174eff 100644 --- a/Sources/VRCKit/Models/Favorite/FavoriteGroupModel.swift +++ b/Sources/VRCKit/Models/Favorite/FavoriteGroupModel.swift @@ -28,16 +28,3 @@ struct RequestToUpdateFavoriteGroup: Codable, Sendable { let visibility: FavoriteGroup.Visibility? @Init(default: []) let tags: [String] } - -@MemberwiseInit(.public) -public struct FavoriteGroupParams: Sendable { - public let type: FavoriteType - public let name: String - public let userId: String -} - -public extension FavoriteGroupParams { - init(favoriteGroup source: FavoriteGroup) { - self.init(type: source.type, name: source.name, userId: source.ownerId) - } -} diff --git a/Sources/VRCKit/Protocols/FavoriteServiceProtocol.swift b/Sources/VRCKit/Protocols/FavoriteServiceProtocol.swift index af8533f..abf2866 100644 --- a/Sources/VRCKit/Protocols/FavoriteServiceProtocol.swift +++ b/Sources/VRCKit/Protocols/FavoriteServiceProtocol.swift @@ -11,7 +11,7 @@ public protocol FavoriteServiceProtocol: Sendable { func fetchFavoriteList(favoriteGroups: [FavoriteGroup]) async throws -> [FavoriteList] func addFavorite(type: FavoriteType, favoriteId: String, tag: String) async throws -> Favorite func updateFavoriteGroup( - params: FavoriteGroupParams, + source: FavoriteGroup, displayName: String, visibility: FavoriteGroup.Visibility ) async throws -> SuccessResponse diff --git a/Sources/VRCKit/Services/FavoriteService.swift b/Sources/VRCKit/Services/FavoriteService.swift index 64f94bf..da31215 100644 --- a/Sources/VRCKit/Services/FavoriteService.swift +++ b/Sources/VRCKit/Services/FavoriteService.swift @@ -100,11 +100,11 @@ public final actor FavoriteService: APIService, FavoriteServiceProtocol { /// - visibility: The new visibility setting for the favorite group. /// - Returns: A `SuccessResponse` if the update is successful. public func updateFavoriteGroup( - params: FavoriteGroupParams, + source: FavoriteGroup, displayName: String, visibility: FavoriteGroup.Visibility ) async throws -> SuccessResponse { - let pathParams = ["favorite", "groups", params.type.rawValue, params.name, params.userId] + let pathParams = ["favorite", "groups", source.type.rawValue, source.name, source.ownerId] let path = pathParams.joined(separator: "/") let body = RequestToUpdateFavoriteGroup(displayName: displayName, visibility: visibility) let requestData = try await Serializer.shared.encode(body) From e87eee30fc64586e337716ad8f2346bd5d5ab831 Mon Sep 17 00:00:00 2001 From: makinosp Date: Mon, 7 Oct 2024 11:55:50 +0900 Subject: [PATCH 3/5] feat: add FavoriteGroup initializer by updatable values --- .../Models/Favorite/FavoriteGroupModel.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Sources/VRCKit/Models/Favorite/FavoriteGroupModel.swift b/Sources/VRCKit/Models/Favorite/FavoriteGroupModel.swift index f174eff..ceb891d 100644 --- a/Sources/VRCKit/Models/Favorite/FavoriteGroupModel.swift +++ b/Sources/VRCKit/Models/Favorite/FavoriteGroupModel.swift @@ -22,6 +22,21 @@ public struct FavoriteGroup: Codable, Sendable, Identifiable, Hashable { } } +public extension FavoriteGroup { + /// Initialize by updatable values + init(source: FavoriteGroup, displayName: String, visibility: Visibility) { + self.init( + id: source.id, + displayName: displayName, + name: source.name, + ownerId: source.ownerId, + tags: source.tags, + type: source.type, + visibility: visibility + ) + } +} + @MemberwiseInit struct RequestToUpdateFavoriteGroup: Codable, Sendable { let displayName: String? From 42afdddc3fbce8c5897a667ae8d90eb163c31c7d Mon Sep 17 00:00:00 2001 From: makinosp Date: Mon, 7 Oct 2024 14:00:02 +0900 Subject: [PATCH 4/5] fix: path of updating favorite group --- Sources/VRCKit/Services/FavoriteService.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/VRCKit/Services/FavoriteService.swift b/Sources/VRCKit/Services/FavoriteService.swift index da31215..72ef5a6 100644 --- a/Sources/VRCKit/Services/FavoriteService.swift +++ b/Sources/VRCKit/Services/FavoriteService.swift @@ -104,7 +104,7 @@ public final actor FavoriteService: APIService, FavoriteServiceProtocol { displayName: String, visibility: FavoriteGroup.Visibility ) async throws -> SuccessResponse { - let pathParams = ["favorite", "groups", source.type.rawValue, source.name, source.ownerId] + let pathParams = ["favorite", "group", source.type.rawValue, source.name, source.ownerId] let path = pathParams.joined(separator: "/") let body = RequestToUpdateFavoriteGroup(displayName: displayName, visibility: visibility) let requestData = try await Serializer.shared.encode(body) From a91467b19bf18adcf5f347979c30df965c6aa543 Mon Sep 17 00:00:00 2001 From: makinosp Date: Mon, 7 Oct 2024 14:08:03 +0900 Subject: [PATCH 5/5] fix: structure returned by the updating favorite group API --- Sources/VRCKit/Protocols/FavoriteServiceProtocol.swift | 2 +- Sources/VRCKit/Services/FavoriteService.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/VRCKit/Protocols/FavoriteServiceProtocol.swift b/Sources/VRCKit/Protocols/FavoriteServiceProtocol.swift index abf2866..fff1b28 100644 --- a/Sources/VRCKit/Protocols/FavoriteServiceProtocol.swift +++ b/Sources/VRCKit/Protocols/FavoriteServiceProtocol.swift @@ -14,6 +14,6 @@ public protocol FavoriteServiceProtocol: Sendable { source: FavoriteGroup, displayName: String, visibility: FavoriteGroup.Visibility - ) async throws -> SuccessResponse + ) async throws -> FavoriteGroup func removeFavorite(favoriteId: String) async throws -> SuccessResponse } diff --git a/Sources/VRCKit/Services/FavoriteService.swift b/Sources/VRCKit/Services/FavoriteService.swift index 72ef5a6..575f594 100644 --- a/Sources/VRCKit/Services/FavoriteService.swift +++ b/Sources/VRCKit/Services/FavoriteService.swift @@ -98,12 +98,12 @@ public final actor FavoriteService: APIService, FavoriteServiceProtocol { /// - 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. + /// - Returns: A `FavoriteGroup` if the update is successful. public func updateFavoriteGroup( source: FavoriteGroup, displayName: String, visibility: FavoriteGroup.Visibility - ) async throws -> SuccessResponse { + ) async throws -> FavoriteGroup { let pathParams = ["favorite", "group", source.type.rawValue, source.name, source.ownerId] let path = pathParams.joined(separator: "/") let body = RequestToUpdateFavoriteGroup(displayName: displayName, visibility: visibility)