Skip to content
Merged
54 changes: 54 additions & 0 deletions FLINT/Data/Sources/DTO/Collection/CollectionDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// CollectionDTO.swift
// Data
//
// Created by 김호성 on 2026.02.09.
//

import Foundation

import Entity

public struct CollectionDTO: Codable {
public let id: String?
public let thumbnailUrl: String?
public let title: String?
public let description: String?
public let imageList: [String]?
public let bookmarkCount: Int?
public let isBookmarked: Bool?
public let userId: String?
public let nickname: String?
public let profileImageUrl: String?
}

extension CollectionDTO {
public var collectionEntity: CollectionEntity {
get throws {
return try CollectionEntity(
id: unwrap(id),
thumbnailUrl: URL(string: thumbnailUrl ?? ""),
title: title ?? "",
description: description ?? "",
imageList: imageList ?? [],
bookmarkCount: bookmarkCount ?? 0,
isBookmarked: isBookmarked ?? false,
userId: unwrap(userId),
nickname: nickname ?? "",
profileImageUrl: URL(string: profileImageUrl ?? "")
)
}
}

public var collectionInfoEntity: CollectionInfoEntity {
get throws {
return try CollectionInfoEntity(
id: unwrap(id),
imageUrl: URL(string: thumbnailUrl ?? ""),
profileImageUrl: URL(string: profileImageUrl ?? ""),
title: title ?? "",
userName: nickname ?? ""
)
}
}
}
8 changes: 4 additions & 4 deletions FLINT/Data/Sources/DTO/Collection/CollectionDetailDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ extension CollectionDetailDTO {
thumbnailUrl: URL(string: thumbnailUrl ?? ""),
createdAt: createdAt ?? "",
isBookmarked: isBookmarked ?? false,
author: author?.entity,
author: unwrap(author?.entity),
contents: contents?.map { try $0.entity } ?? []
)
}
}
}

extension CollectionDetailDTO.AuthorDTO {
public var entity: CollectionAuthorEntity {
public var entity: UserProfileEntity {
get throws {
return try CollectionAuthorEntity(
return try UserProfileEntity(
id: unwrap(id),
nickname: nickname ?? "",
profileImageUrl: URL(string: profileImageUrl ?? ""),
userRole: userRole ?? ""
role: unwrap(UserRole(rawValue: userRole ?? ""))
)
}
}
Expand Down
20 changes: 20 additions & 0 deletions FLINT/Data/Sources/DTO/Collection/CreateCollectionDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// CreateCollectionDTO.swift
// DTO
//
// Created by 소은 on 1/23/26.
//

import Foundation

public struct CreateCollectionDTO: Codable {
public let collectionId: String?
}

extension CreateCollectionDTO {
public var createdCollectionId: Int64 {
get throws {
return try unwrap(Int64(collectionId ?? ""))
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,10 @@ public struct HomeRecommendedCollectionsDTO: Codable {
public let collections: [CollectionDTO]?
}

extension HomeRecommendedCollectionsDTO {
public struct CollectionDTO: Codable {
public let id: String?
public let thumbnailUrl: String?
public let title: String?
public let description: String?
public let imageList: [String]?
public let bookmarkCount: Int?
public let isBookmarked: Bool?
public let userId: String?
public let nickname: String?
public let profileUrl: String?
}
}

extension HomeRecommendedCollectionsDTO {
public var entities: [CollectionInfoEntity] {
get throws {
return try collections?.map { try $0.entity } ?? []
}
}
}

extension HomeRecommendedCollectionsDTO.CollectionDTO {
public var entity: CollectionInfoEntity {
get throws {
return try CollectionInfoEntity(
id: unwrap(id),
imageUrlString: thumbnailUrl ?? "",
profileImageUrlString: profileUrl ?? "",
title: title ?? "",
userName: nickname ?? ""
)
return try collections?.map { try $0.collectionInfoEntity } ?? []
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extension PagedCollectionsDTO {
get throws {
return try CollectionPagingEntity(
collections: data?.map({ try $0.entity }) ?? [],
cursor: unwrap(UInt(unwrap(meta?.nextCursor)))
cursor: unwrap(Int64(meta?.nextCursor ?? ""))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,14 @@ import Foundation

import Entity

// TODO: - RecentViewedCollectionsDTO & HomeRecommendedCollectionsDTO & UserCollectionsDTO 유사

public struct RecentViewedCollectionsDTO: Codable {
public let collections: [CollectionDTO]?
}

extension RecentViewedCollectionsDTO {
public struct CollectionDTO: Codable {
public let id: String?
public let thumbnailUrl: String?
public let title: String?
public let description: String?
public let imageList: [String]?
public let bookmarkCount: Int?
public let isBookmarked: Bool?
public let userId: String?
public let nickname: String?
public let profileImageUrl: String?
}
}

extension RecentViewedCollectionsDTO {
public var entities: [CollectionEntity] {
get throws {
return try collections?.compactMap { try $0.entity } ?? []
}
}
}

extension RecentViewedCollectionsDTO.CollectionDTO {
public var entity: CollectionEntity {
get throws {
return try CollectionEntity(
id: unwrap(id),
thumbnailUrl: thumbnailUrl ?? "",
title: title ?? "",
description: description ?? "",
imageList: imageList ?? [],
bookmarkCount: bookmarkCount ?? 0,
isBookmarked: isBookmarked ?? false,
userId: unwrap(userId),
nickname: nickname ?? "",
profileImageUrl: profileImageUrl ?? ""
)
return try collections?.compactMap { try $0.collectionEntity } ?? []
}
}
}
36 changes: 1 addition & 35 deletions FLINT/Data/Sources/DTO/Collection/UserCollectionsDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,10 @@ public struct UserCollectionsDTO: Codable {
public let collections: [CollectionDTO]?
}

extension UserCollectionsDTO {
public struct CollectionDTO: Codable {
public let id: String?
public let thumbnailUrl: String?
public let title: String?
public let description: String?
public let imageList: [String]?
public let bookmarkCount: Int?
public let isBookmarked: Bool?
public let userId: String?
public let nickname: String?
public let profileImageUrl: String?
}
}

extension UserCollectionsDTO {
public var entities: [CollectionEntity] {
get throws {
return try collections?.map { try $0.entity } ?? []
}
}
}

extension UserCollectionsDTO.CollectionDTO {
public var entity: CollectionEntity {
get throws {
return try CollectionEntity(
id: unwrap(id),
thumbnailUrl: thumbnailUrl ?? "",
title: title ?? "",
description: description ?? "",
imageList: imageList ?? [],
bookmarkCount: bookmarkCount ?? 0,
isBookmarked: isBookmarked ?? false,
userId: unwrap(userId),
nickname: nickname ?? "",
profileImageUrl: profileImageUrl ?? ""
)
return try collections?.map { try $0.collectionEntity } ?? []
}
}
}
12 changes: 6 additions & 6 deletions FLINT/Data/Sources/Networking/API/UserAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public enum UserAPI {
case fetchUserProfile(userId: Int64)
case fetchUserBookmarkedCollections(userId: Int64)
case fetchUserBookmarkedContents(userId: Int64)
case fetchUserCollections(userId: Int64)
case fetchUserCreatedCollections(userId: Int64)
case fetchUserKeywords(userId: Int64)

case fetchMyProfile
case fetchMyBookmarkedCollections
case fetchMyCollections
case fetchMyCreatedCollections
case fetchMyKeywords
case recalculateMyKeywords

Expand All @@ -34,7 +34,7 @@ extension UserAPI: TargetType {
return "/api/v1/users/\(userId)/bookmarked-collections"
case let .fetchUserBookmarkedContents(userId):
return "/api/v1/users/\(userId)/bookmarked-contents"
case let .fetchUserCollections(userId):
case let .fetchUserCreatedCollections(userId):
return "/api/v1/users/\(userId)/collections"
case let .fetchUserKeywords(userId):
return "/api/v1/users/\(userId)/keywords"
Expand All @@ -43,7 +43,7 @@ extension UserAPI: TargetType {
return "/api/v1/users/me"
case .fetchMyBookmarkedCollections:
return "/api/v1/users/me/bookmarked-collections"
case .fetchMyCollections:
case .fetchMyCreatedCollections:
return "/api/v1/users/me/collections"
case .fetchMyKeywords:
return "/api/v1/users/me/keywords"
Expand All @@ -57,7 +57,7 @@ extension UserAPI: TargetType {

public var method: Moya.Method {
switch self {
case .fetchUserProfile, .fetchUserBookmarkedCollections, .fetchUserBookmarkedContents, .fetchUserCollections, .fetchUserKeywords, .fetchMyProfile, .fetchMyBookmarkedCollections, .fetchMyCollections, .fetchMyKeywords, .checkNickname:
case .fetchUserProfile, .fetchUserBookmarkedCollections, .fetchUserBookmarkedContents, .fetchUserCreatedCollections, .fetchUserKeywords, .fetchMyProfile, .fetchMyBookmarkedCollections, .fetchMyCreatedCollections, .fetchMyKeywords, .checkNickname:
return .get
case .recalculateMyKeywords:
return .patch
Expand All @@ -71,7 +71,7 @@ extension UserAPI: TargetType {
parameters: ["nickname": nickname],
encoding: URLEncoding.queryString
)
case .fetchUserProfile, .fetchUserBookmarkedCollections, .fetchUserBookmarkedContents, .fetchUserCollections, .fetchUserKeywords, .fetchMyProfile, .fetchMyBookmarkedCollections, .fetchMyCollections, .fetchMyKeywords, .recalculateMyKeywords:
case .fetchUserProfile, .fetchUserBookmarkedCollections, .fetchUserBookmarkedContents, .fetchUserCreatedCollections, .fetchUserKeywords, .fetchMyProfile, .fetchMyBookmarkedCollections, .fetchMyCreatedCollections, .fetchMyKeywords, .recalculateMyKeywords:
return .requestPlain
}
}
Expand Down
5 changes: 2 additions & 3 deletions FLINT/Data/Sources/Networking/Service/CollectionService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import DTO

public protocol CollectionService {
func fetchCollections(cursor: Int64?, size: Int32) -> AnyPublisher<PagedCollectionsDTO, Error>
func createCollection(collectionInfo: CreateCollectionEntity) -> AnyPublisher<Void, Error>
func createCollection(collectionInfo: CreateCollectionEntity) -> AnyPublisher<CreateCollectionDTO, Error>
func fetchCollectionDetail(collectionId: Int64) -> AnyPublisher<CollectionDetailDTO, Error>
func fetchRecentViewedCollections() -> AnyPublisher<RecentViewedCollectionsDTO, Error>
}
Expand All @@ -34,10 +34,9 @@ public final class DefaultCollectionService: CollectionService {
.mapBaseResponseData(PagedCollectionsDTO.self)
}

public func createCollection(collectionInfo: CreateCollectionEntity) -> AnyPublisher<Void, Error> {
public func createCollection(collectionInfo: CreateCollectionEntity) -> AnyPublisher<CreateCollectionDTO, Error> {
return collectionAPIProvider.requestPublisher(.createCollection(collectionInfo: collectionInfo))
.mapBaseResponseData(CreateCollectionResponseDTO.self)
.map { _ in () }
.eraseToAnyPublisher()
}

Expand Down
12 changes: 6 additions & 6 deletions FLINT/Data/Sources/Networking/Service/UserService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public protocol UserService {
func fetchUserProfile(userId: Int64) -> AnyPublisher<UserProfileDTO, Error>
func fetchUserBookmarkedCollections(userId: Int64) -> AnyPublisher<UserCollectionsDTO, Error>
func fetchUserBookmarkedContents(userId: Int64) -> AnyPublisher<ContentsDTO, Error>
func fetchUserCollections(userId: Int64) -> AnyPublisher<UserCollectionsDTO, Error>
func fetchUserCreatedCollections(userId: Int64) -> AnyPublisher<UserCollectionsDTO, Error>
func fetchUserKeywords(userId: Int64) -> AnyPublisher<KeywordsDTO, Error>

func fetchMyProfile() -> AnyPublisher<UserProfileDTO, Error>
func fetchMyBookmarkedCollections() -> AnyPublisher<UserCollectionsDTO, Error>
func fetchMyCollections() -> AnyPublisher<UserCollectionsDTO, Error>
func fetchMyCreatedCollections() -> AnyPublisher<UserCollectionsDTO, Error>
func fetchMyKeywords() -> AnyPublisher<KeywordsDTO, Error>
func recalculateMyKeywords() -> AnyPublisher<Void, Error>

Expand Down Expand Up @@ -57,8 +57,8 @@ public final class DefaultUserService: UserService {
.mapBaseResponseData(KeywordsDTO.self)
}

public func fetchUserCollections(userId: Int64) -> AnyPublisher<UserCollectionsDTO, Error> {
return userAPIProvider.requestPublisher(.fetchUserCollections(userId: userId))
public func fetchUserCreatedCollections(userId: Int64) -> AnyPublisher<UserCollectionsDTO, Error> {
return userAPIProvider.requestPublisher(.fetchUserCreatedCollections(userId: userId))
.mapBaseResponseData(UserCollectionsDTO.self)
}

Expand All @@ -72,8 +72,8 @@ public final class DefaultUserService: UserService {
.mapBaseResponseData(UserCollectionsDTO.self)
}

public func fetchMyCollections() -> AnyPublisher<UserCollectionsDTO, Error> {
return userAPIProvider.requestPublisher(.fetchMyCollections)
public func fetchMyCreatedCollections() -> AnyPublisher<UserCollectionsDTO, Error> {
return userAPIProvider.requestPublisher(.fetchMyCreatedCollections)
.mapBaseResponseData(UserCollectionsDTO.self)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ public final class DefaultCollectionRepository: CollectionRepository {
.eraseToAnyPublisher()
}

public func createCollection(collectionInfo: CreateCollectionEntity) -> AnyPublisher<Void, Error> {
public func createCollection(collectionInfo: CreateCollectionEntity) -> AnyPublisher<Int64, Error> {
return collectionService.createCollection(collectionInfo: collectionInfo)
.tryMap { try $0.createdCollectionId }
.eraseToAnyPublisher()
}

public func fetchCollectionDetail(collectionId: Int64) -> AnyPublisher<CollectionDetailEntity, Error> {
Expand Down
Loading