Skip to content

Commit

Permalink
✨ 기본 이미지로 변경 가능한 기능 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
loinsir committed Dec 9, 2023
1 parent 3ca6269 commit 50bceff
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
9 changes: 7 additions & 2 deletions iOS/Layover/Layover/Network/DTOs/MemberDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
struct MemberDTO: Decodable {
let id: Int
let username, introduce: String
let profileImageURL: String
let profileImageURL: String?

enum CodingKeys: String, CodingKey {
case id, username, introduce
Expand All @@ -21,11 +21,16 @@ struct MemberDTO: Decodable {

extension MemberDTO {
func toDomain() -> Member {
var imageURL: URL? = nil
if let profileImageURL {
imageURL = URL(string: profileImageURL)
}

return Member(
identifier: id,
username: username,
introduce: introduce,
profileImageURL: URL(string: profileImageURL)
profileImageURL: imageURL
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ protocol UserEndPointFactory {
func makeUserWithDrawEndPoint() -> EndPoint<Response<NicknameDTO>>
func makeUserInformationEndPoint(with id: Int?) -> EndPoint<Response<MemberDTO>>
func makeUserPostsEndPoint(at page: Int, of id: Int?) -> EndPoint<Response<[PostDTO]>>
func makeUserProfileImageDefaultEndPoint() -> EndPoint<Response<Data>>
func makeFetchUserProfilePresignedURL(of fileType: String) -> EndPoint<Response<PresignedURLDTO>>
}

Expand Down Expand Up @@ -90,6 +91,13 @@ final class DefaultUserEndPointFactory: UserEndPointFactory {
)
}

func makeUserProfileImageDefaultEndPoint() -> EndPoint<Response<Data>> {
return EndPoint(
path: "/member/profile-image/default",
method: .POST
)
}

func makeFetchUserProfilePresignedURL(of fileType: String) -> EndPoint<Response<PresignedURLDTO>> {
var bodyParameters = [String: String]()
bodyParameters.updateValue(fileType, forKey: "filetype")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ final class EditProfileInteractor: EditProfileBusinessLogic, EditProfileDataStor
return false
}
} else { // 이미지 변경이 없는 경우 이미지 삭제 시도
guard await userWorker?.fetchImagePresignedURL(with: "jpeg") != nil else {
guard await userWorker?.setProfileImageDefault() == true else {
await MainActor.run {
presenter?.presentProfile(with: Models.EditProfile.Response(isSuccess: false))
}
Expand Down
4 changes: 4 additions & 0 deletions iOS/Layover/Layover/Workers/Mocks/MockUserWorker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ final class MockUserWorker: UserWorkerProtocol {
}
}

func setProfileImageDefault() async -> Bool {
true
}

func modifyProfileImage(data: Data, to url: String) async -> Bool {
true
}
Expand Down
15 changes: 14 additions & 1 deletion iOS/Layover/Layover/Workers/UserWorker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protocol UserWorkerProtocol {
func fetchProfile(by id: Int?) async -> Member?
func fetchPosts(at page: Int, of id: Int?) async -> [Post]?
func fetchImageData(with url: URL) async -> Data?
func setProfileImageDefault() async -> Bool
func fetchImagePresignedURL(with fileType: String) async -> String?
}

Expand Down Expand Up @@ -139,7 +140,7 @@ final class UserWorker: UserWorkerProtocol {
func logout() {
authManager.logout()
}

func fetchProfile(by id: Int?) async -> Member? {
let endPoint = userEndPointFactory.makeUserInformationEndPoint(with: id)

Expand Down Expand Up @@ -173,6 +174,18 @@ final class UserWorker: UserWorkerProtocol {
}
}

func setProfileImageDefault() async -> Bool {
let endPoint = userEndPointFactory.makeUserProfileImageDefaultEndPoint()

do {
let response = try await provider.request(with: endPoint)
return true
} catch {
os_log(.error, log: .data, "Error: %s", error.localizedDescription)
return false
}
}

func fetchImagePresignedURL(with fileType: String) async -> String? {
do {
let endPoint = userEndPointFactory.makeFetchUserProfilePresignedURL(of: fileType)
Expand Down

0 comments on commit 50bceff

Please sign in to comment.