This repository has been archived by the owner on Dec 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ :: [#195] 프로필 이미지 수정을 위한 파일들을 다시 추가합니다
- Loading branch information
1 parent
e2af994
commit 13dc126
Showing
7 changed files
with
135 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import Moya | ||
import Foundation | ||
|
||
enum ImageAPI { | ||
case uploadImages([Data]) | ||
} | ||
|
||
extension ImageAPI: GCMSAPI { | ||
|
||
var domain: GCMSDomain { | ||
return .image | ||
} | ||
var urlPath: String { | ||
switch self { | ||
case .uploadImages: | ||
return "" | ||
} | ||
} | ||
var method: Moya.Method { | ||
switch self { | ||
case .uploadImages: | ||
return .post | ||
} | ||
} | ||
var task: Task { | ||
switch self { | ||
case let .uploadImages(datas): | ||
let multiparts = datas.map { data -> MultipartFormData in | ||
let uuid = UUID().uuidString | ||
return MultipartFormData( | ||
provider: .data(data), | ||
name: "file", | ||
fileName: "\(uuid).png" | ||
) | ||
} | ||
return .uploadMultipart(multiparts) | ||
} | ||
} | ||
var jwtTokenType: JWTTokenType? { | ||
switch self { | ||
case .uploadImages: | ||
return .accessToken | ||
|
||
default: | ||
return JWTTokenType.none | ||
} | ||
} | ||
var headers: [String: String]? { | ||
return ["Content-type": "multipart/form-data"] | ||
} | ||
|
||
typealias ErrorType = GCMSError | ||
var errorMapper: [Int: GCMSError]? { | ||
switch self { | ||
case .uploadImages: | ||
return[ | ||
400: .overFourPhoto, | ||
500: .photoUploadFailed | ||
] | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
Service/Sources/Data/DataSource/Remote/DataMapping/Image/Upload/UploadImageResponse.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Foundation | ||
|
||
struct UploadImagesResponse: Decodable { | ||
let images: [String] | ||
} |
14 changes: 14 additions & 0 deletions
14
Service/Sources/Data/DataSource/Remote/DataSource/ImageRemote.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import RxSwift | ||
import Foundation | ||
|
||
protocol ImageRemoteProtocol { | ||
func uploadPictures(datas: [Data]) -> Single<[String]> | ||
} | ||
|
||
final class ImageRemote: BaseRemote<ImageAPI>, ImageRemoteProtocol { | ||
func uploadPictures(datas: [Data]) -> Single<[String]> { | ||
return request(.uploadImages(datas)) | ||
.map(UploadImagesResponse.self) | ||
.map(\.images) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Service/Sources/Data/Repositories/DefaultImageRepository.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import RxSwift | ||
import Foundation | ||
|
||
final class DefaultImageRepository: ImageRepository { | ||
private let imageRemote: any ImageRemoteProtocol | ||
init(imageRemote: any ImageRemoteProtocol) { | ||
self.imageRemote = imageRemote | ||
} | ||
|
||
func uploadImages(datas: [Data]) -> Single<[String]> { | ||
imageRemote.uploadPictures(datas: datas) | ||
} | ||
} |