-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feat] #28 - 미션 리스트 뷰 비즈니스 로직 구현 #53
Changes from all commits
873436e
9870d71
44dc175
eb5b2a9
31404de
f4e2298
4c534a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// MissionListFetchType.swift | ||
// Core | ||
// | ||
// Created by Junho Lee on 2022/12/21. | ||
// Copyright © 2022 SOPT-Stamp-iOS. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public enum MissionListFetchType: String { | ||
case all | ||
case complete | ||
case incomplete | ||
|
||
public var path: String { | ||
return self.rawValue | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,19 +8,38 @@ | |
|
||
import Combine | ||
|
||
import Core | ||
import Domain | ||
import Network | ||
|
||
public class MissionListRepository { | ||
|
||
private let networkService: MissionService | ||
private let cancelBag = Set<AnyCancellable>() | ||
private let missionService: MissionService | ||
private let cancelBag = CancelBag() | ||
|
||
public init(service: MissionService) { | ||
self.networkService = service | ||
self.missionService = service | ||
} | ||
} | ||
|
||
extension MissionListRepository: MissionListRepositoryInterface { | ||
|
||
public func fetchMissionList(type: MissionListFetchType, userId: Int?) -> AnyPublisher<[MissionListModel], Error> { | ||
let userId: Int = (userId != nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lsj8706 그렇네요 엘비스 연산자가 쓰기 싫어서 그래왔는데 그냥 쓰는것도 좋아 보이는군요... |
||
? userId! | ||
: 1 | ||
switch type { | ||
case .all: | ||
return missionService.fetchAllMissionList(userId: userId) | ||
.map { $0.toDomain() } | ||
.eraseToAnyPublisher() | ||
case .complete: | ||
return missionService.fetchCompleteMissionList(userId: userId) | ||
.map { $0.toDomain() } | ||
.eraseToAnyPublisher() | ||
case .incomplete: | ||
return missionService.fetchIncompleteMissionList(userId: userId) | ||
.map { $0.toDomain() } | ||
.eraseToAnyPublisher() | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// MissionListTransform.swift | ||
// Data | ||
// | ||
// Created by Junho Lee on 2022/12/20. | ||
// Copyright © 2022 SOPT-Stamp-iOS. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
import Domain | ||
import Network | ||
|
||
public extension MissionListEntity { | ||
func toDomain() -> [MissionListModel] { | ||
return self.map { .init(id: $0.id, | ||
title: $0.title, | ||
level: $0.level, | ||
isCompleted: $0.isCompleted) } | ||
} | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,12 @@ | |
|
||
import Foundation | ||
|
||
public struct MissionListEntity { | ||
|
||
public struct MissionListEntityElement: Codable { | ||
public let id: Int | ||
public let title: String | ||
public let level: Int | ||
public let profileImage: [String]? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아 이거 서버쪽에서 뺀다구 전달받았는디 아직 결과값에 일부 들어오고 있나보네여... |
||
public let isCompleted: Bool | ||
} | ||
|
||
public typealias MissionListEntity = [MissionListEntityElement] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,10 @@ import Moya | |
import Foundation | ||
|
||
public enum APIType { | ||
case notice | ||
case auth | ||
case alert | ||
case mission | ||
case rank | ||
case stamp | ||
case user | ||
} | ||
|
||
|
@@ -26,23 +27,44 @@ extension BaseAPI { | |
var base = Config.Network.baseURL | ||
|
||
switch Self.apiType { | ||
case .alert: | ||
base += "/alert" | ||
case .notice: | ||
base += "/notice" | ||
case .auth: | ||
base += "/auth" | ||
case .mission: | ||
base += "/mission" | ||
case .rank: | ||
base += "/rank" | ||
case .stamp: | ||
base += "/stamp" | ||
case .user: | ||
base += "/user" | ||
} | ||
|
||
guard let url = URL(string: base) else { | ||
fatalError("baseURL could not be configured") | ||
} | ||
|
||
return url | ||
} | ||
|
||
public var headers: [String: String]? { | ||
return ["Content-Type": "application/json"] | ||
} | ||
} | ||
|
||
public enum HeaderType { | ||
case json | ||
case jsonUserId(userId: Int) | ||
case userId(userId: Int) | ||
Comment on lines
+54
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 야무지네요.. |
||
|
||
public var value: [String: String] { | ||
switch self { | ||
case .json: | ||
return ["Content-Type": "application/json"] | ||
case .jsonUserId(let userId): | ||
return ["Content-Type": "application/json", | ||
"userId": String(userId)] | ||
case .userId(let userId): | ||
return ["userId": String(userId)] | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍👍