Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions MLS/.swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,15 @@ function_body_length:
disabled_rules:
- force_cast
- blanket_disable_command

function_parameter_count:
warning: 5
error: 10

identifier_name:
min_length: 2
max_length: 40

type_name:
min_length: 3
max_length: 60
24 changes: 12 additions & 12 deletions MLS/Data/Data/Network/DTO/AlarmDTO/AlarmResponseDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@ public struct AlarmResponseDTO: Decodable {
case normal(NormalContent)
case all(AllContent)

public struct NormalContent: Decodable {
public let type: String
public let title: String
public let link: String
public let date: [Int]
}

public struct AllContent: Decodable {
public let alrim: NormalContent
public let alreadyRead: Bool
}

public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()

Expand All @@ -42,6 +30,18 @@ public struct AlarmResponseDTO: Decodable {
)
}
}

public struct NormalContent: Decodable {
public let type: String
public let title: String
public let link: String
public let date: [Int]
}

public struct AllContent: Decodable {
public let alrim: NormalContent
public let alreadyRead: Bool
}
}

public extension AlarmResponseDTO {
Expand Down
55 changes: 52 additions & 3 deletions MLS/Data/Data/Network/Endpoints/CollectionEndPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,68 @@ import DomainInterface
public enum CollectionEndPoint {
static let base = "https://api.mapleland.kro.kr"

public static func fetchCollectionList() -> ResponsableEndPoint<[CollectionListResponseDTO]> {
.init(baseURL: base, path: "/api/v1/collections", method: .GET)
public static func fetchCollectionList(query: Encodable) -> ResponsableEndPoint<[CollectionListResponseDTO]> {
.init(
baseURL: base,
path: "/api/v1/collections",
method: .GET,
query: query
)
}

public static func createCollectionList(body: Encodable) -> EndPoint {
.init(baseURL: base, path: "/api/v1/collections", method: .POST, body: body)
}

public static func fetchCollection(id: Int) -> ResponsableEndPoint<[BookmarkDTO]> {
.init(
baseURL: base,
path: "/api/v1/collections/\(id)/bookmarks",
method: .GET
)
}

public static func addBookmarksToCollection(id: Int, body: Encodable) -> EndPoint {
.init(
baseURL: base,
path: "/api/v1/collections/\(id)/bookmarks",
method: .POST,
body: body
)
}

public static func addCollectionsToBookmark(id: Int, body: Encodable) -> EndPoint {
.init(
baseURL: base,
path: "/api/v1/bookmarks/\(id)/collections",
method: .POST,
body: body
)
}

public static func setCollectionName(id: Int, body: Encodable) -> EndPoint {
.init(
baseURL: base,
path: "/api/v1/collections/\(id)",
method: .PUT,
body: body
)
}

public static func deleteCollection(id: Int) -> EndPoint {
.init(
baseURL: base,
path: "/api/v1/collections/\(id)",
method: .DELETE
)
}

public static func addCollectionAndBookmark(body: Encodable) -> EndPoint {
.init(
baseURL: base,
path: "/api/v1/bookmark-collections",
method: .POST,
body: body
)
}
}
15 changes: 12 additions & 3 deletions MLS/Data/Data/Network/Endpoints/DictionaryListEndPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public enum DictionaryListEndPoint {
}
// 몬스터 리스트
public static func fetchMonsterList(keyword: String?, minLevel: Int?, maxLevel: Int?, page: Int, size: Int, sort: String?) -> ResponsableEndPoint<PagedListResponseDTO<DictionaryMonsterDTO>> {
let query = DictionaryListQuery(keyword: keyword ?? "", page: page, size: size, sort: sort, minLevel: minLevel, maxLevel: maxLevel)
let query = DictionaryListQuery(keyword: keyword ?? "", page: page, size: size, sort: sort, minLevel: minLevel ?? 1, maxLevel: maxLevel ?? 200)
return .init(baseURL: base, path: "/api/v1/monsters", method: .GET, query: query
)
}
Expand All @@ -34,11 +34,20 @@ public enum DictionaryListEndPoint {
)
}
// 아이템 리스트
public static func fetchItemList(keyword: String? = nil, jobId: [Int]? = nil, minLevel: Int? = nil, maxLevel: Int? = nil, categoryIds: [Int]? = nil, page: Int? = nil, size: Int? = nil, sort: String? = nil) -> ResponsableEndPoint<PagedListResponseDTO<DictionaryItemDTO>> {
public static func fetchItemList(
keyword: String? = nil,
jobId: [Int]? = nil,
minLevel: Int? = nil,
maxLevel: Int? = nil,
categoryIds: [Int]? = nil,
page: Int? = nil,
size: Int? = nil,
sort: String? = nil
) -> ResponsableEndPoint<PagedListResponseDTO<DictionaryItemDTO>> {
let joinedCategoryIds = categoryIds?.map(String.init).joined(separator: ",")
let joinedJobIds = jobId?.map(String.init).joined(separator: ",")

let query = DictionaryListQuery(keyword: keyword, page: page ?? 0, size: size ?? 20, sort: sort, minLevel: minLevel, maxLevel: maxLevel, jobIds: joinedJobIds, categoryIds: joinedCategoryIds)
let query = DictionaryListQuery(keyword: keyword, page: page ?? 0, size: size ?? 20, sort: sort, minLevel: minLevel ?? 1, maxLevel: maxLevel ?? 200, jobIds: joinedJobIds, categoryIds: joinedCategoryIds)
return .init(baseURL: base, path: "/api/v1/items", method: .GET, query: query
)
}
Expand Down
62 changes: 60 additions & 2 deletions MLS/Data/Data/Repository/CollectionAPIRepositoryImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class CollectionAPIRepositoryImpl: CollectionAPIRepository {
self.tokenInterceptor = tokenInterceptor
}

public func fetchCollectionList() -> Observable<[CollectionResponse]> {
let endPoint = CollectionEndPoint.fetchCollectionList()
public func fetchCollectionList(sort: String?) -> Observable<[CollectionResponse]> {
let endPoint = CollectionEndPoint.fetchCollectionList(query: FetchCollectionListQuery(sort: sort))
return provider.requestData(endPoint: endPoint, interceptor: tokenInterceptor)
.map { $0.map { $0.toDomain() }
}
Expand All @@ -30,10 +30,68 @@ public class CollectionAPIRepositoryImpl: CollectionAPIRepository {
return provider.requestData(endPoint: endPoint, interceptor: tokenInterceptor)
.map { $0.toDomain() }
}

// public func addBookmarksToCollection(collectionId: Int, bookmarkIds: [Int]) -> Completable {
// let endPoint = CollectionEndPoint.addBookmarksToCollection(id: collectionId, body: AddBookmarkRequestBody(bookmarkIds: bookmarkIds))
// return provider.requestData(endPoint: endPoint, interceptor: tokenInterceptor)
// .catch { error in
// if let netErr = error as? NetworkError {
// switch netErr {
// case let .statusError(code, body):
// return .error(DomainHTTPError.httpStatus(code: code, message: body))
// default:
// return .error(DomainHTTPError.unknown)
// }
// } else {
// return .error(DomainHTTPError.unknown)
// }
// }
// }
//
// public func addCollectionsToBookmark(bookmarkId: Int, collectionIds: [Int]) -> Completable {
// let endPoint = CollectionEndPoint.addCollectionsToBookmark(id: bookmarkId, body: AddCollectionRequestBody(collectionIds: collectionIds))
// return provider.requestData(endPoint: endPoint, interceptor: tokenInterceptor)
// }
Comment on lines +34 to +54

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

주석 처리된 addBookmarksToCollectionaddCollectionsToBookmark 함수가 있습니다. 현재 사용되지 않는 코드라면 가독성과 유지보수성 향상을 위해 삭제하는 것을 고려해 보세요.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추후 수정 예정


public func setCollectionName(collectionId: Int, name: String) -> Completable {
let endPoint = CollectionEndPoint.setCollectionName(id: collectionId, body: SetCollectionRequestBody(name: name))
return provider.requestData(endPoint: endPoint, interceptor: tokenInterceptor)
}

public func deleteCollection(collectionId: Int) -> Completable {
let endPoint = CollectionEndPoint.deleteCollection(id: collectionId)
return provider.requestData(endPoint: endPoint, interceptor: tokenInterceptor)
}

public func addCollectionAndBookmark(collectionIds: [Int], bookmarkIds: [Int]) -> Completable {
let endPoint = CollectionEndPoint.addCollectionAndBookmark(body: AddCollectionAndBookmarkBody(collectionIds: collectionIds, bookmarkIds: bookmarkIds))
return provider.requestData(endPoint: endPoint, interceptor: tokenInterceptor)
}
}

private extension CollectionAPIRepositoryImpl {
struct FetchCollectionListQuery: Encodable {
let sort: String?
}

struct CreateCollectionRequestDTO: Encodable {
let name: String
}

struct AddBookmarkRequestBody: Encodable {
let bookmarkIds: [Int]
}

struct AddCollectionRequestBody: Encodable {
let collectionIds: [Int]
}

struct SetCollectionRequestBody: Encodable {
let name: String
}

struct AddCollectionAndBookmarkBody: Encodable {
let collectionIds: [Int]
let bookmarkIds: [Int]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public final class CheckNotificationPermissionUseCaseImpl: CheckNotificationPerm
return Single.create { single in
UNUserNotificationCenter.current().getNotificationSettings { settings in
switch settings.authorizationStatus {
case .authorized:
single(.success(true))
default:
single(.success(false))
case .authorized:
single(.success(true))
default:
single(.success(false))
}
}
return Disposables.create()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// import DomainInterface
//
// import RxSwift
//
// public final class AddBookmarksToCollectionUseCaseImpl: AddBookmarksToCollectionUseCase {
// private let repository: CollectionAPIRepository
//
// public init(repository: CollectionAPIRepository) {
// self.repository = repository
// }
//
// public func execute(collectionId: Int, bookmarkIds: [Int]) -> Completable {
// return repository.addBookmarksToCollection(collectionId: collectionId, bookmarkIds: bookmarkIds)
// }
// }
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import DomainInterface
import RxSwift

public final class AddCollectionAndBookmarkUseCaseImpl: AddCollectionAndBookmarkUseCase {
private let repository: CollectionAPIRepository

public init(repository: CollectionAPIRepository) {
self.repository = repository
}

public func execute(collectionIds: [Int], bookmarkIds: [Int]) -> Completable {
return repository.addCollectionAndBookmark(collectionIds: collectionIds, bookmarkIds: bookmarkIds)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// import DomainInterface
// import RxSwift
//
// public final class AddCollectionsToBookmarkUseCaseImpl: AddCollectionsToBookmarkUseCase {
// private let repository: CollectionAPIRepository
//
// public init(repository: CollectionAPIRepository) {
// self.repository = repository
// }
//
// public func execute(bookmarkId: Int, collectionIds: [Int]) -> Completable {
// return repository.addCollectionsToBookmark(bookmarkId: bookmarkId, collectionIds: collectionIds)
// }
// }
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import DomainInterface

import RxSwift

public final class DeleteCollectionUseCaseImpl: DeleteCollectionUseCase {
private let repository: CollectionAPIRepository

public init(repository: CollectionAPIRepository) {
self.repository = repository
}

public func execute(collectionId: Int) -> Completable {
return repository.deleteCollection(collectionId: collectionId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public final class FetchCollectionListUseCaseImpl: FetchCollectionListUseCase {
self.repository = repository
}

public func execute() -> Observable<[CollectionResponse]> {
return repository.fetchCollectionList()
public func execute(sort: SortType?) -> Observable<[CollectionResponse]> {
return repository.fetchCollectionList(sort: sort?.sortParameter)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import DomainInterface

import RxSwift

public final class SetCollectionUseCaseImpl: SetCollectionUseCase {
private let repository: CollectionAPIRepository

public init(repository: CollectionAPIRepository) {
self.repository = repository
}

public func execute(collectionId: Int, name: String) -> Completable {
return repository.setCollectionName(collectionId: collectionId, name: name)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@ import RxSwift

public protocol CollectionAPIRepository {
// 컬렉션 목록 조회
func fetchCollectionList() -> Observable<[CollectionResponse]>
func fetchCollectionList(sort: String?) -> Observable<[CollectionResponse]>
// 컬렉션 목록 추가
func createCollectionList(name: String) -> Completable
// 컬렉션 상세 조회
func fetchCollectionUseCase(id: Int) -> Observable<[BookmarkResponse]>

// func addBookmarksToCollection(collectionId: Int, bookmarkIds: [Int]) -> Completable

// func addCollectionsToBookmark(bookmarkId: Int, collectionIds: [Int]) -> Completable

func setCollectionName(collectionId: Int, name: String) -> Completable

func deleteCollection(collectionId: Int) -> Completable

func addCollectionAndBookmark(collectionIds: [Int], bookmarkIds: [Int]) -> Completable
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// import RxSwift
//
// public protocol AddBookmarksToCollectionUseCase {
// func execute(collectionId: Int, bookmarkIds: [Int]) -> Completable
// }
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import RxSwift

public protocol AddCollectionAndBookmarkUseCase {
func execute(collectionIds: [Int], bookmarkIds: [Int]) -> Completable
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// import RxSwift
//
// public protocol AddCollectionsToBookmarkUseCase {
// func execute(bookmarkId: Int, collectionIds: [Int]) -> Completable
// }
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import RxSwift

public protocol DeleteCollectionUseCase {
func execute(collectionId: Int) -> Completable
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import RxSwift

public protocol FetchCollectionListUseCase {
func execute() -> Observable<[CollectionResponse]>
func execute(sort: SortType?) -> Observable<[CollectionResponse]>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import RxSwift

public protocol SetCollectionUseCase {
func execute(collectionId: Int, name: String) -> Completable
}
Loading