Skip to content

Commit

Permalink
feat: 반려동물 삭제 api 연동
Browse files Browse the repository at this point in the history
  • Loading branch information
heejinnn committed Mar 13, 2024
1 parent ebe8587 commit 375a7c7
Show file tree
Hide file tree
Showing 19 changed files with 98 additions and 40 deletions.
Binary file not shown.
14 changes: 14 additions & 0 deletions fit-a-pet-client/fit-a-pet-client/API/AuthorizationAlamofire.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,20 @@ class AuthorizationAlamofire: TokenHandling {
}
}

func petDelete(_ petId: Int, completion: @escaping (Result<Data?, Error>) -> Void) {
os_log("AuthorizationAlamofire - petDelete() called", log: .default, type: .info)

self.session.request(PetRouter.petDelete(petId: petId))
.response { response in
switch response.result {
case .success(let data):
completion(.success(data))
case .failure(let error):
completion(.failure(error))
}
}
}


//MARK: UserInfoRouter

Expand Down
10 changes: 7 additions & 3 deletions fit-a-pet-client/fit-a-pet-client/API/Router/PetRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ enum PetRouter: URLRequestConvertible {
case userPetsList, userPetInfoList
case petTotalInfoCheck(petId: Int)
case petInfoEdit(petId: Int, combinedData: [String:Any])
case petDelete(petId: Int)

//pet care
case createCare(combinedData: [String:Any], petId: Int)
Expand All @@ -25,6 +26,8 @@ enum PetRouter: URLRequestConvertible {
return .get
case .petInfoEdit:
return .put
case .petDelete:
return .delete
}
}
var baseURL: URL {
Expand All @@ -39,7 +42,7 @@ enum PetRouter: URLRequestConvertible {
return "v2/users/\(UserDefaults.standard.string(forKey: "id")!)/pets/categories-check"
case .registPet, .userPetCareInfoList, .createCare, .checkCareCategory, .petCareComplete, .userPetInfoList:
return "v2/pets"
case .petTotalInfoCheck(let petId), .petInfoEdit(let petId, _):
case .petTotalInfoCheck(let petId), .petInfoEdit(let petId, _), .petDelete(let petId):
return "v2/pets/\(petId)"
}
}
Expand All @@ -50,7 +53,7 @@ enum PetRouter: URLRequestConvertible {
return ["petName": petName, "species": species, "gender": gender, "neutralization": neutralization, "birthdate": birthdate]
case let .careCategoryCheck(categoryName, pets):
return ["categoryName": categoryName, "pets": pets]
case .checkCareCategory, .userPetsList, .createCare, .userPetInfoList, .userPetCareInfoList, .petCareComplete, .petTotalInfoCheck, .petInfoEdit:
case .checkCareCategory, .userPetsList, .createCare, .userPetInfoList, .userPetCareInfoList, .petCareComplete, .petTotalInfoCheck, .petInfoEdit, .petDelete:
return [:]
}
}
Expand All @@ -66,7 +69,7 @@ enum PetRouter: URLRequestConvertible {
request.httpMethod = method.rawValue
request = try JSONEncoding.default.encode(request, withJSONObject: combinedData)

case .userPetsList, .userPetInfoList, .petTotalInfoCheck(_):
case .userPetsList, .userPetInfoList, .petTotalInfoCheck(_), .petDelete(_):
request = URLRequest(url: url)
request.httpMethod = method.rawValue

Expand All @@ -90,6 +93,7 @@ enum PetRouter: URLRequestConvertible {
request.httpMethod = method.rawValue
request = try JSONEncoding.default.encode(request, withJSONObject: combinedData)


default:
request = URLRequest.createURLRequestWithBody(url: url, method: method, parameters: parameters)
}
Expand Down
53 changes: 27 additions & 26 deletions fit-a-pet-client/fit-a-pet-client/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,32 +115,33 @@ extension AppDelegate: MessagingDelegate {
print("APNs fcm Token: \(String(describing: fcmToken!))")
// sendDeviceTokenWithAPI(fcmToken: fcmToken ?? "")

// AuthorizationAlamofire.shared.registDeviceToken(String(describing: fcmToken!), device.systemVersion, modelName) {result in
// switch result {
// case .success(let data):
// if let responseData = data,
// let jsonObject = try? JSONSerialization.jsonObject(with: responseData, options: []) as? [String: Any] {
// print("response jsonData: \(jsonObject)")
//
// }
//
// case .failure(let error):
// print("Error: \(error)")
// }
// }
//
// AuthorizationAlamofire.shared.pushNotificationAPI{result in
// switch result {
// case .success(let data):
// if let responseData = data,
// let jsonObject = try? JSONSerialization.jsonObject(with: responseData, options: []) as? [String: Any] {
// print("response jsonData: \(jsonObject)")
// }
//
// case .failure(let error):
// print("Error: \(error)")
// }
// }
AuthorizationAlamofire.shared.registDeviceToken(String(describing: fcmToken!), device.systemVersion, modelName) {result in
switch result {
case .success(let data):
if let responseData = data,
let jsonObject = try? JSONSerialization.jsonObject(with: responseData, options: []) as? [String: Any] {
print("response jsonData: \(jsonObject)")

AuthorizationAlamofire.shared.pushNotificationAPI{result in
switch result {
case .success(let data):
if let responseData = data,
let jsonObject = try? JSONSerialization.jsonObject(with: responseData, options: []) as? [String: Any] {
print("response jsonData: \(jsonObject)")
}

case .failure(let error):
print("Error: \(error)")
}
}
}

case .failure(let error):
print("Error: \(error)")
}
}



}
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"images" : [
{
"filename" : "apple_icon.png",
"filename" : "icon_oauth_apple.svg",
"idiom" : "universal",
"scale" : "1x"
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"images" : [
{
"filename" : "naver_icon.png",
"filename" : "icon_oauth_google.svg",
"idiom" : "universal",
"scale" : "1x"
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"images" : [
{
"filename" : "kakao_icon.png",
"filename" : "icon_oauth_kakao.svg",
"idiom" : "universal",
"scale" : "1x"
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"images" : [
{
"filename" : "google_icon.png",
"filename" : "icon_oauth_naver.svg",
"idiom" : "universal",
"scale" : "1x"
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
12 changes: 6 additions & 6 deletions fit-a-pet-client/fit-a-pet-client/ViewControllers/FirstVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ extension FirstVC{
let googleLogin = UIButton()
let appleLogin = UIButton()

naverLogin.setImage(UIImage(named: "naver_icon"), for: .normal)
kakaoLogin.setImage(UIImage(named: "kakao_icon"), for: .normal)
googleLogin.setImage(UIImage(named: "google_icon"), for: .normal)
appleLogin.setImage(UIImage(named: "apple_icon"), for: .normal)
naverLogin.setImage(UIImage(named: "icon_oauth_naver"), for: .normal)
kakaoLogin.setImage(UIImage(named: "icon_oauth_kakao"), for: .normal)
googleLogin.setImage(UIImage(named: "icon_oauth_google"), for: .normal)
appleLogin.setImage(UIImage(named: "icon_oauth_apple"), for: .normal)


kakaoLogin.addTarget(self, action: #selector(kakaoLoginBtnTapped(_:)), for: .touchUpInside)
Expand Down Expand Up @@ -252,7 +252,7 @@ extension FirstVC{
let profilePicUrl = user.profile?.imageURL(withDimension: 320)

print("user: \(user)")
print("userId: \(userId)")
print("userId: \(String(describing: userId))")
print("emailAddress: \(String(describing: emailAddress))")
print("fullName: \(String(describing: fullName))")
print("profileUrl: \(String(describing: profilePicUrl))")
Expand All @@ -264,7 +264,7 @@ extension FirstVC{
let idToken = user.idToken?.tokenString

KeychainHelper.saveTempToken(tempToken: idToken!)
print("idToken: \(idToken)")
print("idToken: \(String(describing: idToken))")

OauthInfo.provider = "google"
OauthInfo.oauthId = userId!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class LoginVC: UIViewController{
let mainVC = TabBarController()
mainVC.modalPresentationStyle = .fullScreen

AnonymousAlamofire.shared.login("jayang", "dkssudgktpdy") { [weak self] loginResult in
AnonymousAlamofire.shared.login("heejin", "heejin123") { [weak self] loginResult in
switch loginResult {
case .success(let data):
if let responseData = data {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import UIKit
import SnapKit


//TODO: 알림 배경 수정 필요
class SettingVC: UIViewController {

Expand Down

0 comments on commit 375a7c7

Please sign in to comment.