-
Notifications
You must be signed in to change notification settings - Fork 0
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
[IDLE-180] 센터프로필 조회및 수정 API 연동 #22
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
80 changes: 80 additions & 0 deletions
80
project/Projects/Data/ConcreteRepository/UserInfo/DefaultUserProfileRepository.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,80 @@ | ||
// | ||
// DefaultUserProfileRepository.swift | ||
// ConcreteRepository | ||
// | ||
// Created by choijunios on 7/20/24. | ||
// | ||
|
||
import Foundation | ||
import RxSwift | ||
import Entity | ||
import RepositoryInterface | ||
import NetworkDataSource | ||
|
||
public class DefaultUserProfileRepository: UserProfileRepository { | ||
|
||
let userInformationService: UserInformationService | ||
let externalRequestService: ExternalRequestService | ||
|
||
public init(_ keyValueStore: KeyValueStore? = nil) { | ||
|
||
if let keyValueStore { | ||
self.userInformationService = .init(keyValueStore: keyValueStore) | ||
self.externalRequestService = .init(keyValueStore: keyValueStore) | ||
} else { | ||
self.userInformationService = .init() | ||
self.externalRequestService = .init() | ||
} | ||
} | ||
|
||
public func getCenterProfile() -> Single<CenterProfileVO> { | ||
|
||
userInformationService | ||
.requestDecodable(api: .getCenterProfile, with: .withToken) | ||
.map { (dto: CenterProfileDTO) in dto.toEntity() } | ||
} | ||
|
||
public func updateCenterProfileForText(phoneNumber: String, introduction: String?) -> Single<Void> { | ||
userInformationService | ||
.request(api: .updateCenterProfile( | ||
officeNumber: phoneNumber, | ||
introduce: introduction | ||
), with: .withToken) | ||
.map { _ in return () } | ||
} | ||
|
||
/// 이미지 업로드 | ||
public func uploadImage(_ userType: UserType, imageInfo: ImageUploadInfo) -> Single<Void> { | ||
|
||
getPreSignedUrl(userType, ext: imageInfo.ext) | ||
.flatMap { [unowned self] dto in | ||
self.uploadImageToPreSignedUrl(url: dto.uploadUrl, data: imageInfo.data) | ||
.map { _ in (id: dto.imageId, ext: dto.imageFileExtension) } | ||
} | ||
.flatMap { (id, ext) in | ||
self.callbackToServerForUploadImageSuccess(userType, imageId: id, ext: ext) | ||
} | ||
} | ||
|
||
private func getPreSignedUrl(_ userType: UserType, ext: String) -> Single<ProfileImageUploadInfoDTO> { | ||
userInformationService | ||
.request(api: .getPreSignedUrl(userType: userType, imageExt: ext), with: .withToken) | ||
.map(ProfileImageUploadInfoDTO.self) | ||
} | ||
|
||
private func uploadImageToPreSignedUrl(url: String, data: Data) -> Single<Void> { | ||
externalRequestService | ||
.request(api: .uploadImageToS3(url: url, data: data), with: .plain) | ||
.map { _ in () } | ||
} | ||
|
||
private func callbackToServerForUploadImageSuccess(_ userType: UserType, imageId: String, ext: String) -> Single<Void> { | ||
userInformationService | ||
.request(api: .imageUploadSuccessCallback( | ||
userType: userType, | ||
imageId: imageId, | ||
imageExt: ext), with: .withToken | ||
) | ||
.map { _ in () } | ||
} | ||
} |
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
File renamed without changes.
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
48 changes: 48 additions & 0 deletions
48
project/Projects/Data/NetworkDataSource/API/ExtenalUrlAPI.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,48 @@ | ||
// | ||
// ExtenalUrlAPI.swift | ||
// NetworkDataSource | ||
// | ||
// Created by choijunios on 7/20/24. | ||
// | ||
|
||
import Foundation | ||
import Moya | ||
import Alamofire | ||
|
||
public enum ExtenalUrlAPI { | ||
|
||
case uploadImageToS3(url: String, data: Data) | ||
} | ||
|
||
extension ExtenalUrlAPI: BaseAPI { | ||
|
||
public var apiType: APIType { | ||
var baseUrl: String! | ||
switch self { | ||
case .uploadImageToS3(let url, _): | ||
baseUrl = url | ||
} | ||
return .external(url: baseUrl) | ||
} | ||
|
||
public var path: String { | ||
switch self { | ||
default: | ||
"" | ||
} | ||
} | ||
|
||
public var method: Moya.Method { | ||
switch self { | ||
case .uploadImageToS3: | ||
.put | ||
} | ||
} | ||
|
||
public var task: Moya.Task { | ||
switch self { | ||
case .uploadImageToS3(_, let data): | ||
.requestData(data) | ||
} | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
project/Projects/Data/NetworkDataSource/API/UserInformationAPI.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,101 @@ | ||
// | ||
// UserInformationAPI.swift | ||
// NetworkDataSource | ||
// | ||
// Created by choijunios on 7/20/24. | ||
// | ||
|
||
import Foundation | ||
import Moya | ||
import Entity | ||
import Alamofire | ||
|
||
extension UserType { | ||
var pathUri: String { | ||
switch self { | ||
case .center: | ||
"center" | ||
case .worker: | ||
"carer" | ||
} | ||
} | ||
} | ||
|
||
public enum UserInformationAPI { | ||
|
||
// 프로필 조회 | ||
case getCenterProfile | ||
case updateCenterProfile(officeNumber: String, introduce: String?) | ||
|
||
// 프로필 사진 업로드 | ||
case getPreSignedUrl(userType: UserType, imageExt: String) | ||
case imageUploadSuccessCallback(userType: UserType, imageId: String, imageExt: String) | ||
|
||
// case getPreSignedUrlForProfile(type: UserType) | ||
// case callbackForUpdateProfileImage(type: UserType) | ||
} | ||
|
||
extension UserInformationAPI: BaseAPI { | ||
|
||
public var apiType: APIType { | ||
.users | ||
} | ||
|
||
public var path: String { | ||
switch self { | ||
case .getCenterProfile: | ||
"center/my/profile" | ||
case .updateCenterProfile: | ||
"center/my/profile" | ||
case .getPreSignedUrl(let type, _): | ||
"\(type.pathUri)/my/profile-image/upload-url" | ||
case .imageUploadSuccessCallback(let type, _, _): | ||
"\(type.pathUri)/my/profile-image/upload-callback" | ||
} | ||
} | ||
|
||
public var method: Moya.Method { | ||
switch self { | ||
case .getCenterProfile: | ||
.get | ||
case .updateCenterProfile: | ||
.post | ||
case .getPreSignedUrl: | ||
.get | ||
case .imageUploadSuccessCallback: | ||
.post | ||
} | ||
} | ||
|
||
var parameterEncoding: ParameterEncoding { | ||
switch self { | ||
default: | ||
return JSONEncoding.default | ||
} | ||
} | ||
|
||
public var task: Moya.Task { | ||
switch self { | ||
case .getCenterProfile: | ||
return .requestPlain | ||
case .updateCenterProfile(let officeNumber, let introduce): | ||
var bodyData: [String: String] = ["officeNumber": officeNumber] | ||
if let introduce { | ||
bodyData["introduce"] = introduce | ||
} | ||
return .requestParameters(parameters: bodyData, encoding: parameterEncoding) | ||
case .getPreSignedUrl(_, let imageExt): | ||
let params: [String: String] = [ | ||
"imageFileExtension": imageExt | ||
] | ||
return .requestParameters(parameters: params, encoding: URLEncoding.queryString) | ||
case.imageUploadSuccessCallback(_, let imageId, let imageExt): | ||
let params: [String: String] = [ | ||
"imageId": imageId, | ||
"imageFileExtension": imageExt | ||
] | ||
return .requestParameters(parameters: params, encoding: parameterEncoding) | ||
} | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
project/Projects/Data/NetworkDataSource/DTO/UserInfo/CenterProfileDTO.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,38 @@ | ||
// | ||
// CenterProfileDTO.swift | ||
// NetworkDataSource | ||
// | ||
// Created by choijunios on 7/20/24. | ||
// | ||
|
||
import Foundation | ||
import Entity | ||
|
||
public struct CenterProfileDTO: Codable { | ||
let centerName: String? | ||
let officeNumber: String? | ||
let roadNameAddress: String? | ||
let lotNumberAddress: String? | ||
let detailedAddress: String? | ||
let longitude: String? | ||
let latitude: String? | ||
let introduce: String? | ||
let profileImageUrl: String? | ||
} | ||
|
||
public extension CenterProfileDTO { | ||
|
||
func toEntity() -> CenterProfileVO { | ||
CenterProfileVO( | ||
centerName: centerName ?? "", | ||
officeNumber: officeNumber ?? "", | ||
roadNameAddress: roadNameAddress ?? "", | ||
lotNumberAddress: lotNumberAddress ?? "", | ||
detailedAddress: detailedAddress ?? "", | ||
longitude: longitude ?? "", | ||
latitude: latitude ?? "", | ||
introduce: introduce ?? "", | ||
profileImageURL: URL(string: profileImageUrl ?? "") | ||
) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
project/Projects/Data/NetworkDataSource/DTO/UserInfo/ProfileImageUploadInfoDTO.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,15 @@ | ||
// | ||
// ProfileImageUploadInfoDTO.swift | ||
// NetworkDataSource | ||
// | ||
// Created by choijunios on 7/20/24. | ||
// | ||
|
||
import Foundation | ||
|
||
public struct ProfileImageUploadInfoDTO: Decodable { | ||
|
||
public let imageId: String | ||
public let imageFileExtension: String | ||
public let uploadUrl: String | ||
} |
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
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@J0onYEong 이 값들이 모두 정말로 Optional인가요~~~?
적어도 몇개는 required로 갖고 있어야 할 값들로 보입니다. 파싱 오류 방지를 위해서 무조건 Optional로 가는건 좋지 않습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵! 저렇게 처리하고 랩핑을 벗길때 기본값을 고민했어야 했는데.. 앞으로는 요구사항을 좀더 명확히 인지해 보겠습니다!