Skip to content

Commit

Permalink
#9 edit setUserInform Api
Browse files Browse the repository at this point in the history
  • Loading branch information
JunseokNoh committed Aug 17, 2021
1 parent ee44a1f commit e2567c4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
37 changes: 30 additions & 7 deletions KNU_CSE/KNU_CSE/View/Main/MyPage/UserInfrom/UserInformView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class UserInformView:BaseUIViewController, ViewProtocol{
override func viewDidLoad() {
super.viewDidLoad()
self.BindingGetUserInform()
self.BindingResetImage()
self.userInformationViewModel.getUserInform()
}

Expand Down Expand Up @@ -197,12 +198,7 @@ extension UserInformView{
actionSheet.popUpActionSheet(edit_text: "프로필 이미지 변경", editAction: { [weak self] action in
self?.presentPhotoView()
}, remove_text: "프로필 이미지 삭제", removeAction:{ [weak self] action in
self?.setOriginProfile()
if self?.userInformationViewModel.model.imagePath != nil{
self?.addBtnAction()
}
let image = UIImage(systemName: "person.circle.fill")!.resized(toWidth: self!.profile_width_hegiht)!.withTintColor(.lightGray.withAlphaComponent(0.4))
self?.userInformationViewModel.model.imageData = image.jpegData(compressionQuality: 1)
self?.userInformationViewModel.resetImage()
}
, cancel_text: "취소")
}
Expand Down Expand Up @@ -257,7 +253,7 @@ extension UserInformView{
self.userInformationViewModel.setInformlistener.binding(successHandler: {result in
if result.success{
Alert(title: "성공", message: "회원정보가 변경되었습니다.", viewController: self).popUpDefaultAlert(action: { action in
self.navigationController?.popViewController(animated: true)
// self.navigationController?.popViewController(animated: true)
})
}else{
if let error = result.error?.message {
Expand All @@ -266,6 +262,33 @@ extension UserInformView{
})
}
}
}, failHandler: { Error in
print(Error)
Alert(title: "실패", message: "네트워크 상태를 확인하세요", viewController: self).popUpDefaultAlert(action: nil)
}, asyncHandler: {

}, endHandler: {

})
}

func BindingResetImage(){
self.userInformationViewModel.resetImagelistener.binding(successHandler: { [weak self] result in
if result.success{
self?.setOriginProfile()
// if self?.userInformationViewModel.model.imagePath != nil{
// self?.addBtnAction()
// }
// let image = UIImage(systemName: "person.circle.fill")!.resized(toWidth: self!.profile_width_hegiht)!.withTintColor(.lightGray.withAlphaComponent(0.4))
// self?.userInformationViewModel.model.imageData = image.jpegData(compressionQuality: 1)
}else{
if let error = result.error?.message {
Alert(title: "실패", message: error, viewController: self!).popUpDefaultAlert(action: { action in
self?.navigationController?.popViewController(animated: true)
})
}
}

}, failHandler: { Error in
Alert(title: "실패", message: "네트워크 상태를 확인하세요", viewController: self).popUpDefaultAlert(action: nil)
}, asyncHandler: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import Alamofire
struct UserInformViewModel{
var model:Profile!
var getInformlistener: BaseAction<Profile, errorHandler> = BaseAction()
var setInformlistener: BaseAction<String, errorHandler> = BaseAction()
var setInformlistener: BaseAction<ProfileResponse, errorHandler> = BaseAction()
var resetImagelistener: BaseAction<String, errorHandler> = BaseAction()

init(){

Expand All @@ -24,7 +25,12 @@ struct UserInformViewModel{

func setUserInform(){
let request = Request(requestMultipart: model.getMultipart(), requestMethod: .put, enviroment:.setInform)
request.sendMutiPartRequest(request: request, responseType: String.self, errorType: errorHandler.self, action: self.setInformlistener)
request.sendMutiPartRequest(request: request, responseType: ProfileResponse.self, errorType: errorHandler.self, action: self.setInformlistener)
}

func resetImage(){
let request = Request(requestBodyObject: nil, requestMethod: .delete, enviroment: .resetImage)
request.sendRequest(request: request, responseType: String.self, errorType: errorHandler.self, action:self.resetImagelistener)
}
}

Expand Down Expand Up @@ -85,3 +91,7 @@ class Profile:BaseObject{
}
}

struct ProfileResponse: Codable{
var newNickName: String?
var newProFileImg: String?
}

0 comments on commit e2567c4

Please sign in to comment.