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

API Worker를 리팩토링해요 #725

Merged
merged 3 commits into from
Dec 17, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ final class OAuthDIContainer: BaseContainer {
// MARK: - Make Repository

private func makeOAuthRepository() -> OAuthRepositoryProtocol {
return OAuthRepository()
return AuthRepository()
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ extension MainViewReactor {
case .fetchMainUseCase:
return fetchMainUseCase.execute()
.asObservable()
.flatMap { result -> Observable<Mutation> in
guard let data = result else {
return Observable.empty()
}
.flatMap { data -> Observable<Mutation> in
return Observable.concat(
.just(.updateMainData(data)),
.just(.setBalloonText),
Expand All @@ -145,10 +142,7 @@ extension MainViewReactor {
case .fetchMainNightUseCase:
return fetchMainNightUseCase.execute()
.asObservable()
.flatMap { result -> Observable<Mutation> in
guard let data = result else {
return .empty()
}
.flatMap { data -> Observable<Mutation> in
return .just(.updateMainNight(data))
}
case .setTimer(let isInTime, let time):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ extension PostReactor {
return fetchMissionUseCase.execute(missionId: missionId)
.asObservable()
.flatMap { entity -> Observable<Mutation> in
guard let originEntity = entity else { return .empty() }
return .concat(
.just(.setSelectedPostIndex(index)),
.just(.setMissionContent(originEntity))
.just(.setMissionContent(entity))
)

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import Domain
import Data
import ReactorKit



public final class PrivacyViewReactor: Reactor {
public var initialState: State
@Injected var fetchAppVersionUseCase: FetchAppVersionUseCaseProtocol
Expand Down Expand Up @@ -70,25 +68,28 @@ public final class PrivacyViewReactor: Reactor {
.just(.setLoading(true)),
.merge(
fetchAppVersionUseCase.execute()
.asObservable()
.withUnretained(self)
.flatMap { owner, appVersionEntity -> Observable<Mutation> in
owner.fetchPrivacyItemsUseCase.execute()
.asObservable()
return owner.fetchPrivacyItemsUseCase.execute()
.flatMap { privateInfo -> Observable<Mutation> in
guard let appVersionEntity = appVersionEntity else { return .empty() }
var sectionItem: [PrivacyItemModel] = []
privateInfo.forEach {
sectionItem.append(.privacyWithAuthItem(PrivacyCellReactor(descrption: $0, isCheck: appVersionEntity.latest)))

sectionItem.append(
.privacyWithAuthItem(
PrivacyCellReactor(
descrption: $0,
isCheck: appVersionEntity.latest
)
)
)
}

return .concat(
.just(.setPrivacyItemModel(sectionItem)),
.just(.setBibbiAppInfo(appVersionEntity))
)
}

},

fetchAuthorizationItemUseCase.execute()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import SnapKit
import Then

final class BibbiInquireBannerView: UIView {


private let mainLogoView: UIImageView = UIImageView()
private let subLogoView: UIImageView = UIImageView()
private let descrptionLabel: UILabel = BBLabel(.body1Bold, textAlignment: .left)
Expand All @@ -27,7 +25,6 @@ final class BibbiInquireBannerView: UIView {
setupUI()
setupAttributes()
setupAutoLayout()
print("Device Size: \(UIScreen.main.bounds.size.width)")
}

required init?(coder: NSCoder) {
Expand All @@ -38,8 +35,6 @@ final class BibbiInquireBannerView: UIView {
addSubviews(mainLogoView, subLogoView, arrowImageView, descrptionLabel, subtitleLabel)
}



private func setupAttributes() {

mainLogoView.do {
Expand Down Expand Up @@ -68,10 +63,6 @@ final class BibbiInquireBannerView: UIView {
$0.text = "의견 남기러 가기"
$0.textColor = .blue500
}




}


Expand Down Expand Up @@ -107,12 +98,7 @@ final class BibbiInquireBannerView: UIView {
$0.width.height.equalTo(11)
$0.centerY.equalTo(subtitleLabel)
}



}


}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public final class ProfileViewController: BaseViewController<ProfileViewReactor>
}

// 기본 이미지가 true 이고 닉네임 변경 할 경우 redraw
extension ProfileViewController {
extension ProfileViewController {
private func setupProfileImage(url: URL) {
let processor = DownsamplingImageProcessor(size: profileView.bounds.size)

Expand Down Expand Up @@ -324,10 +324,11 @@ extension ProfileViewController: PHPickerViewControllerDelegate {
picker.dismiss(animated: true, completion: nil)

if let imageProvider = itemProvider, imageProvider.canLoadObject(ofClass: UIImage.self) {
imageProvider.loadObject(ofClass: UIImage.self) { image, error in
guard let photoImage: UIImage = image as? UIImage,
imageProvider.loadObject(ofClass: UIImage.self) { [weak self] image, error in
guard let self = self,
let photoImage: UIImage = image as? UIImage,
let originalData: Data = photoImage.jpegData(compressionQuality: 1.0) else { return }
imageProvider.didSelectProfileImageWithProcessing(photo: originalData, error: error)
self.reactor?.action.onNext(.didSelectPHAssetsImage(originalData))
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import Domain

struct FamilyWidgetEntry: TimelineEntry {
let date: Date
let family: RecentFamilyPostEntity?
let family: WidgetPostEntity?
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ struct FamilyWidgetView: View {
}

// MARK: 가족중 일부가 사진을 올렸을 때 뷰
private func getPhotoView(info: RecentFamilyPostEntity) -> some View {
private func getPhotoView(info: WidgetPostEntity) -> some View {
ZStack {
if let postImageUrl = info.postImageUrl {

Expand Down
45 changes: 0 additions & 45 deletions 14th-team5-iOS/Data/Sources/APIs/App/AppAPI/AppAPIWorker.swift

This file was deleted.

22 changes: 0 additions & 22 deletions 14th-team5-iOS/Data/Sources/APIs/App/AppAPI/AppAPIs.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,17 @@ import Foundation
import RxSwift

typealias CommentAPIWorker = CommentAPIs.Worker
extension CommentAPIs {
public final class Worker: BBRxAPIWorker {
public init() { super.init() }
}
}


// MARK: - Extensions

extension CommentAPIWorker {


// MARK: - Fetch Comment

/// 게시물에 등록 된 댓글을 페이지네이션으로 조회하는 Method입니다.
/// HTTP Method: GET
/// - Parameters: postId: String
/// - Returns: GetPostCommentResponseDTO
func fetchComment(
postId: String,
query: PostCommentPaginationQuery
) -> Observable<PaginationResponsePostCommentResponseDTO> {
) -> Observable<GetPostCommentResponseDTO> {
let page = query.page
let size = query.size
let sort = query.sort.rawValue
Expand All @@ -39,8 +32,10 @@ extension CommentAPIWorker {
}


// MARK: - Create Comment

/// 게시물에 댓글을 등록하는 Method입니다.
/// HTTP Method: POST
/// - Parameters: postId: String
/// - Returns: PostCommentResponseDTO
func createComment(
postId: String,
body: CreatePostCommentReqeustDTO
Expand All @@ -51,8 +46,10 @@ extension CommentAPIWorker {
}


// MARK: - Update Comment

/// 게시물에 등록된 댓글을 수정하는 Method입니다.
/// HTTP Method: PUT
/// - Parameters: postId: String, commentId: String
/// - Returns: PostCommentResponseDTO
func updateComment(
postId: String,
commentId: String,
Expand All @@ -64,12 +61,14 @@ extension CommentAPIWorker {
}


// MARK: - Delete Comment

/// 게시물에 등록된 댓글을 삭제하는 Method입니다.
/// HTTP Method: Delete
/// - Parameters: postId: String, commentId: String
/// - Returns: DeletePostCommentResponseDTO
func deleteComment(
postId: String,
commentId: String
) -> Observable<PostCommentDeleteResponseDTO> {
) -> Observable<DeletePostCommentResponseDTO> {
let spec = CommentAPIs.deletePostComment(postId: postId, commentId: commentId).spec

return request(spec)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ import Core
import Foundation

enum CommentAPIs: BBAPI {
/// 게시물 댓글 조회
case fetchPostComment(postId: String, page: Int, size: Int, sort: String)
/// 게시물 댓글 추가
case createPostComment(postId: String, body: CreatePostCommentReqeustDTO)
/// 게시물 댓글 수정
case updatePostComment(postId: String, commentId: String)
/// 게시물 댓글 삭제
case deletePostComment(postId: String, commentId: String)

var spec: Spec {
Expand Down Expand Up @@ -47,4 +51,8 @@ enum CommentAPIs: BBAPI {
)
}
}

final class Worker: BBRxAPIWorker {
init() { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
import Foundation

public struct CreatePostCommentReqeustDTO: Encodable {
var content: String
let content: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import Domain
import Foundation

public struct PostCommentDeleteResponseDTO: Decodable {
var success: Bool
public struct DeletePostCommentResponseDTO: Decodable {
let success: Bool
}

extension PostCommentDeleteResponseDTO {
extension DeletePostCommentResponseDTO {
func toDomain() -> PostCommentDeleteEntity {
return .init(success: success)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// PaginationResponsePostCommentResponseDTO.swift
// Data
//
// Created by 김건우 on 1/17/24.
//

import Domain
import Foundation

public struct GetPostCommentResponseDTO: Decodable {
let currentPage: Int
let totalPage: Int
let itemPerPage: Int
let hasNext: Bool
let results: [PostCommentResponseDTO]
}

extension GetPostCommentResponseDTO {
func toDomain() -> PaginationResponsePostCommentEntity {
return .init(
currentPage: currentPage,
totalPage: totalPage,
itemPerPage: itemPerPage,
hasNext: hasNext,
results: results.map { $0.toDomain() }
)
}
}
Loading
Loading