Skip to content
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

MyPage 서버와 연결 및 더미데이터 삭제 #186

Merged
merged 2 commits into from
Dec 8, 2022
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
11 changes: 5 additions & 6 deletions Segno/Segno/Data/Network/Endpoints/UserDetailEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,24 @@
import Foundation

enum UserDetailEndpoint: Endpoint {
case item
case item(String)

var baseURL: URL? {
return URL(string: BaseURL.urlString)
}

var httpMethod: HTTPMethod {
return .GET
return .POST
}

var path: String {
// TODO: 서버에 맞춰서 path 조정
return ""
return "user"
}

var parameters: HTTPRequestParameter? {
switch self {
case .item:
return HTTPRequestParameter.queries([:]) // TODO: queries로 무언가 들어가야함
case .item(let token):
return HTTPRequestParameter.body(["token": token])
}
}
}
19 changes: 5 additions & 14 deletions Segno/Segno/Data/Repository/DTO/UserDetailDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,13 @@
//

struct UserDetailDTO: Decodable {
// TODO: 일단은 UserDetailItem과 동일하게 작성. 이후 서버 사이드에 따라 바꾸겠습니다.
let identifier: String
let nickname: String
let writtenDiary: String
let email: String
let oauthType: String
let diaryCount: Int

enum CodingKeys: String, CodingKey {
case identifier = "_id"
case nickname
case writtenDiary = "diary"
case nickname = "nickName"
case email, oauthType, diaryCount
}

#if DEBUG
static let example = UserDetailDTO(
identifier: "id",
nickname: "test123",
writtenDiary: "50000"
)
#endif
}
22 changes: 10 additions & 12 deletions Segno/Segno/Data/Repository/MyPageRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Created by 이예준 on 2022/11/30.
//

import Foundation

import RxSwift

protocol MyPageRepository {
Expand All @@ -13,18 +15,14 @@ protocol MyPageRepository {

final class MyPageRepositoryImpl: MyPageRepository {
func getUserDetail() -> Single<UserDetailDTO> {
// let endpoint = UserDetailEndpoint.item(id)
//
// return NetworkManager.shared.call(endpoint)
// .map {
// try JSONDecoder().decode(UserDetailDTO.self, from: $0)
// }

// TODO: 추후에 NetworkManager로 변경
return Single.create { observer -> Disposable in
observer(.success(UserDetailDTO.example))
// TODO: Keychain으로부터 토큰 가져오기
let token = "A1lmMjb2pgNWg6ZzAaPYgMcqRv/8BOyO4U/ui6i/Ic4="
Comment on lines +18 to +19
Copy link
Collaborator

Choose a reason for hiding this comment

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

🥲

let endpoint = UserDetailEndpoint.item(token)

return Disposables.create()
}
return NetworkManager.shared.call(endpoint)
.map {
let userDetailDTO = try JSONDecoder().decode(UserDetailDTO.self, from: $0)
return userDetailDTO
}
}
}
2 changes: 1 addition & 1 deletion Segno/Segno/Domain/UseCase/UserDetailUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class UserDetailUseCaseImpl: UserDetailUseCase {

func getUserDetail() -> Single<UserDetailItem> {
return repository.getUserDetail().map {
UserDetailItem(identifier: $0.identifier, nickname: $0.nickname, writtenDiary: $0.writtenDiary)
UserDetailItem(nickname: $0.nickname, email: $0.email, oauthType: $0.oauthType, diaryCount: $0.diaryCount)
}
}
}
5 changes: 3 additions & 2 deletions Segno/Segno/Entity/UserDetailItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
//

struct UserDetailItem: Hashable {
let identifier: String
let nickname: String
let writtenDiary: String
let email: String
let oauthType: String
let diaryCount: Int
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ final class MyPageViewController: UIViewController {
numberFormatter.numberStyle = .decimal

let price = Double(writtenDiary)
let result = numberFormatter.string(from: NSNumber(value:price!))! + "개"
let result = numberFormatter.string(from: NSNumber(value:price)) ?? 0 + "개"

_ = Observable<[MyPageCellModel]>.just([
.writtenDiary(title: "작성한 일기 수", subtitle: result),
Expand Down
2 changes: 1 addition & 1 deletion Segno/Segno/Presentation/ViewModel/MyPageViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class MyPageViewModel {
let useCase: UserDetailUseCase
var userDetailItem = PublishSubject<UserDetailItem>()
lazy var nicknameObservable = userDetailItem.map { $0.nickname }
lazy var writtenDiaryObservable = userDetailItem.map { $0.writtenDiary }
lazy var writtenDiaryObservable = userDetailItem.map { $0.diaryCount }

private let disposeBag = DisposeBag()

Expand Down