Skip to content

Commit

Permalink
Merge pull request #256 from depromeet/fix/#254-fix-위젯-오류-가족-가입-오류-딥링…
Browse files Browse the repository at this point in the history
…크-수정-사항-반영

fix: 위젯 관련 통신 로직 수정, 가족 가입 안되는 이슈 해결
  • Loading branch information
YuGeonHui authored Jan 12, 2024
2 parents 6553ffc + 60707c4 commit 929bdde
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ public final class HomeViewController: BaseViewController<HomeViewReactor> {
postCollectionView.rx.setDelegate(self)
.disposed(by: disposeBag)

Observable<Void>.just(())
.take(1)
.map { Reactor.Action.viewDidLoad }
.bind(to: reactor.action)
.disposed(by: disposeBag)
// Observable<Void>.just(())
// .take(1)
// .map { Reactor.Action.viewDidLoad }
// .bind(to: reactor.action)
// .disposed(by: disposeBag)

Observable.concat (
Observable.just(()).map { Reactor.Action.getFamilyMembers },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct FamilyService {

let token = App.Repository.token.keychain.string(forKey: "accessToken")
let appKey = "9c61cc7b-0fe9-40eb-976e-6a74c8cb9092"
let urlString = "https://dev.api.no5ing.kr/v1/widgets/single-recent-family-post"
let urlString = "https://api.no5ing.kr/v1/widgets/single-recent-family-post"

var request = URLRequest(url: URL(string: urlString)!)
request.addValue("application/json", forHTTPHeaderField: "accept")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ struct FamilyWidgetView: View {
.font(family == .systemSmall ? DesignSystemFontFamily.Pretendard.semiBold.swiftUIFont(size: 16) : DesignSystemFontFamily.Pretendard.semiBold.swiftUIFont(size: 18))
.frame(height: family == .systemSmall ? 34 : 52)
.frame(width: family == .systemSmall ? 34 : 52)
.foregroundColor(.white)
.background(Circle().stroke(Color.white, lineWidth: 4))
.clipShape(Circle())
.background(DesignSystemAsset.gray700.swiftUIColor)
.clipShape(Circle())
.padding(.leading, 14)
.padding(.top, 14)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public final class AccountRepository: AccountImpl {
private let profileWorker = ProfileAPIWorker()
private let meApiWorekr = MeAPIWorker()

private let signInResult = PublishRelay<APIResult>()
private let fetchMemberInfo = PublishRelay<Void>()
private let signUpFinished = PublishRelay<Void>()

public func kakaoLogin(with snsType: SNS, vc: UIViewController) -> Observable<APIResult> {
return Observable.create { observer in
Expand Down Expand Up @@ -79,13 +80,19 @@ public final class AccountRepository: AccountImpl {
meApiWorekr.fetchMemberInfo()
.asObservable()
.withUnretained(self)
.bind(onNext: { $0.0.joinFamily(inviteCode: UserDefaults.standard.inviteCode) })
.bind(onNext: {
let memberInfo = $0.1
print("member Info: \(memberInfo?.memberId)")
})
.disposed(by: disposeBag)
}

// MARK: 링크가입 사용자 -> 가입 이후 가족가입
private func joinFamily(inviteCode: String?) {
guard let inviteCode else { return }

print("inviteCode: \(inviteCode)")

meApiWorekr.joinFamily(with: inviteCode)
.asObservable()
.withUnretained(self)
Expand All @@ -102,7 +109,8 @@ public final class AccountRepository: AccountImpl {
let tk = AccessToken(accessToken: token.accessToken, refreshToken: token.refreshToken, isTemporaryToken: token.isTemporaryToken)
App.Repository.token.accessToken.accept(tk)

self.fetchMember()
self.fetchMemberInfo.accept(())
self.signUpFinished.accept(())

observer.onNext(token)
observer.onCompleted()
Expand Down Expand Up @@ -137,5 +145,15 @@ public final class AccountRepository: AccountImpl {

public init() {
signInHelper.bind()

fetchMemberInfo
.withUnretained(self)
.bind(onNext: { $0.0.fetchMember() })
.disposed(by: disposeBag)

signUpFinished
.withUnretained(self)
.bind(onNext: { $0.0.joinFamily(inviteCode: UserDefaults.standard.inviteCode) })
.disposed(by: disposeBag)
}
}
6 changes: 4 additions & 2 deletions 14th-team5-iOS/Data/Sources/Account/MeAPI/MeAPIWorker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,12 @@ extension MeAPIWorker: MeRepositoryProtocol {
}

private func joinFamily(spec: APISpec, headers: [APIHeader]?, jsonEncodable: Encodable) -> Single<FamilyInfo?> {
return request(spec: spec, headers: headers)

return request(spec: spec, headers: headers, jsonEncodable: jsonEncodable)
.subscribe(on: Self.queue)
.do(onNext: {
if let str = String(data: $0.1, encoding: .utf8) {
debugPrint("getFamilyInfo result : \(str)")
debugPrint("Join Family result : \(str)")
}
})
.map(FamilyInfo.self)
Expand All @@ -138,6 +139,7 @@ extension MeAPIWorker: MeRepositoryProtocol {
}

public func joinFamily(with inviteCode: String) -> Single<FamilyInfo?> {

let payload = _PayLoad.FamilyPayload(inviteCode: inviteCode)
let spec = MeAPIs.joinFamily.spec

Expand Down
2 changes: 1 addition & 1 deletion 14th-team5-iOS/Data/Sources/Account/MeAPI/MeAPIs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public enum MeAPIs: API {
case .memberInfo:
return APISpec(method: .get, url: "\(BibbiAPI.hostApi)/me/member-info")
case .joinFamily:
return APISpec(method: .post, url: "\(BibbiAPI.hostApi)/me/join-family")
return APISpec(method: .post, url: "\(BibbiAPI.hostApi)/me/join-family")
}
}

Expand Down

0 comments on commit 929bdde

Please sign in to comment.