Skip to content

Commit

Permalink
[Fix] sopt-makers#78 - Network 모듈에 Domain 의존성 제거 및 userId 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
yangsubinn committed Jan 4, 2023
1 parent e3663f7 commit 3e41373
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ extension ListDetailRepository: ListDetailRepositoryInterface {
.asDriver()
}

public func postStamp(missionId: Int, stampData: ListDetailRequestModel) -> Driver<ListDetailModel> {
public func postStamp(missionId: Int, stampData: [Any]) -> Driver<ListDetailModel> {
return stampService.postStamp(userId: userId, missionId: missionId, requestModel: stampData)
.map { $0.toDomain() }
.asDriver()
}

public func putStamp(missionId: Int, stampData: ListDetailRequestModel) -> Driver<Int> {
public func putStamp(missionId: Int, stampData: [Any]) -> Driver<Int> {
return stampService.putStamp(userId: userId, missionId: missionId, requestModel: stampData)
.map { $0.toDomain() }
.asDriver()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class MissionListRepository {

extension MissionListRepository: MissionListRepositoryInterface {
public func fetchMissionList(type: MissionListFetchType, userId: Int?) -> AnyPublisher<[MissionListModel], Error> {
let userId = userId ?? 1
let userId = userId ?? (UserDefaultKeyList.Auth.userId ?? 1)
switch type {
case .all:
return missionService.fetchAllMissionList(userId: userId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Combine

public protocol ListDetailRepositoryInterface {
func fetchListDetail(missionId: Int) -> Driver<ListDetailModel>
func postStamp(missionId: Int, stampData: ListDetailRequestModel) -> Driver<ListDetailModel>
func putStamp(missionId: Int, stampData: ListDetailRequestModel) -> Driver<Int>
func postStamp(missionId: Int, stampData: [Any]) -> Driver<ListDetailModel>
func putStamp(missionId: Int, stampData: [Any]) -> Driver<Int>
func deleteStamp(stampId: Int) -> Driver<Bool>
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ extension DefaultListDetailUseCase: ListDetailUseCase {
}

public func postStamp(missionId: Int, stampData: ListDetailRequestModel) {
repository.postStamp(missionId: missionId, stampData: stampData)
let data = [stampData.imgURL as Any, stampData.content] as [Any]
repository.postStamp(missionId: missionId, stampData: data)
.sink { model in
self.listDetailModel.send(model)
}.store(in: self.cancelBag)
}

public func putStamp(missionId: Int, stampData: ListDetailRequestModel) {
repository.putStamp(missionId: missionId, stampData: stampData)
let data = [stampData.imgURL as Any, stampData.content] as [Any]
repository.putStamp(missionId: missionId, stampData: data)
.sink { result in
self.editSuccess.send(true)
}.store(in: self.cancelBag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ import Foundation
import Alamofire
import Moya

import Domain

public enum StampAPI {
case fetchStampListDetail(userId: Int, missionId: Int)
case postStamp(userId: Int, missionId: Int, requestModel: ListDetailRequestModel)
case putStamp(userId: Int, missionId: Int, requestModel: ListDetailRequestModel)
case postStamp(userId: Int, missionId: Int, requestModel: [Any])
case putStamp(userId: Int, missionId: Int, requestModel: [Any])
case deleteStamp(stampId: Int)
case resetStamp(userId: Int)
}
Expand Down Expand Up @@ -91,11 +89,11 @@ extension StampAPI: BaseAPI {
let fileName = (self.method == .post) ? ".jpg" : ".png"
let mimeType = (self.method == .post) ? "image/jpeg" : "image/png"

let imageData = MultipartFormData(provider: .data(requestModel.imgURL ?? Data()), name: "imgUrl", fileName: fileName, mimeType: mimeType)
let imageData = MultipartFormData(provider: .data(requestModel[0] as! Data), name: "imgUrl", fileName: fileName, mimeType: mimeType)
multipartData.append(imageData)

do {
let content = try JSONSerialization.data(withJSONObject: ["contents": requestModel.content], options: .withoutEscapingSlashes)
let content = try JSONSerialization.data(withJSONObject: ["contents": requestModel[1]], options: .withoutEscapingSlashes)

let formData = MultipartFormData(provider: .data(content), name: "stampContent", mimeType: "application/json")
multipartData.append(formData)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ import Combine
import Alamofire
import Moya

import Domain

public typealias DefaultStampService = BaseService<StampAPI>

public protocol StampService {
func fetchStampListDetail(userId: Int, missionId: Int) -> AnyPublisher<ListDetailEntity, Error>
func postStamp(userId: Int, missionId: Int, requestModel: ListDetailRequestModel) -> AnyPublisher<ListDetailEntity, Error>
func putStamp(userId: Int, missionId: Int, requestModel: ListDetailRequestModel) -> AnyPublisher<StampEntity, Error>
func postStamp(userId: Int, missionId: Int, requestModel: [Any]) -> AnyPublisher<ListDetailEntity, Error>
func putStamp(userId: Int, missionId: Int, requestModel: [Any]) -> AnyPublisher<StampEntity, Error>
func deleteStamp(stampId: Int) -> AnyPublisher<Int, Error>
func resetStamp(userId: Int) -> AnyPublisher<Int, Error>
}
Expand All @@ -29,11 +27,11 @@ extension DefaultStampService: StampService {
requestObjectInCombine(StampAPI.fetchStampListDetail(userId: userId, missionId: missionId))
}

public func postStamp(userId: Int, missionId: Int, requestModel: ListDetailRequestModel) -> AnyPublisher<ListDetailEntity, Error> {
public func postStamp(userId: Int, missionId: Int, requestModel: [Any]) -> AnyPublisher<ListDetailEntity, Error> {
requestObjectInCombine(StampAPI.postStamp(userId: userId, missionId: missionId, requestModel: requestModel))
}

public func putStamp(userId: Int, missionId: Int, requestModel: ListDetailRequestModel) -> AnyPublisher<StampEntity, Error> {
public func putStamp(userId: Int, missionId: Int, requestModel: [Any]) -> AnyPublisher<StampEntity, Error> {
requestObjectInCombine(StampAPI.putStamp(userId: userId, missionId: missionId, requestModel: requestModel))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Foundation
import Combine

import Alamofire
import Domain
import Moya

public typealias DefaultUserService = BaseService<UserAPI>
Expand Down

0 comments on commit 3e41373

Please sign in to comment.