Skip to content

Commit

Permalink
Merge pull request #92 from KCY-Fit-a-Pet/feat/91
Browse files Browse the repository at this point in the history
📮🎨 기록 api 연동 + 기록 ui 변경 사항들
  • Loading branch information
psychology50 authored Feb 21, 2024
2 parents 5b8dcfd + ad1c350 commit caa3ef5
Show file tree
Hide file tree
Showing 42 changed files with 1,535 additions and 289 deletions.
109 changes: 103 additions & 6 deletions fit-a-pet-client/fit-a-pet-client.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
"pins" : [
{
"identity" : "abseil-cpp-swiftpm",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/abseil-cpp-SwiftPM.git",
"state" : {
"revision" : "583de9bd60f66b40e78d08599cc92036c2e7e4e1",
"version" : "0.20220203.2"
}
},
{
"identity" : "boringssl-swiftpm",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/boringssl-SwiftPM.git",
"state" : {
"revision" : "dd3eda2b05a3f459fc3073695ad1b28659066eab",
"version" : "0.9.1"
}
},
{
"identity" : "firebase-ios-sdk",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/firebase-ios-sdk",
"state" : {
"revision" : "7e80c25b51c2ffa238879b07fbfc5baa54bb3050",
"version" : "9.6.0"
}
},
{
"identity" : "googleappmeasurement",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleAppMeasurement.git",
"state" : {
"revision" : "c1cfde8067668027b23a42c29d11c246152fe046",
"version" : "9.6.0"
}
},
{
"identity" : "googledatatransport",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleDataTransport.git",
"state" : {
"revision" : "a732a4b47f59e4f725a2ea10f0c77e93a7131117",
"version" : "9.3.0"
}
},
{
"identity" : "googleutilities",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleUtilities.git",
"state" : {
"revision" : "bc27fad73504f3d4af235de451f02ee22586ebd3",
"version" : "7.12.1"
}
},
{
"identity" : "grpc-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/grpc/grpc-ios.git",
"state" : {
"revision" : "8440b914756e0d26d4f4d054a1c1581daedfc5b6",
"version" : "1.44.3-grpc"
}
},
{
"identity" : "gtm-session-fetcher",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/gtm-session-fetcher.git",
"state" : {
"revision" : "5ccda3981422a84186387dbb763ba739178b529c",
"version" : "2.3.0"
}
},
{
"identity" : "leveldb",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/leveldb.git",
"state" : {
"revision" : "9d108e9112aa1d65ce508facf804674546116d9c",
"version" : "1.22.3"
}
},
{
"identity" : "nanopb",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/nanopb.git",
"state" : {
"revision" : "819d0a2173aff699fb8c364b6fb906f7cdb1a692",
"version" : "2.30909.0"
}
},
{
"identity" : "promises",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/promises.git",
"state" : {
"revision" : "e70e889c0196c76d22759eb50d6a0270ca9f1d9e",
"version" : "2.3.1"
}
},
{
"identity" : "swift-protobuf",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-protobuf.git",
"state" : {
"revision" : "65e8f29b2d63c4e38e736b25c27b83e012159be8",
"version" : "1.25.2"
}
}
],
"version" : 2
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>Promises (Playground) 1.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>16</integer>
</dict>
<key>Promises (Playground) 2.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>17</integer>
</dict>
<key>Promises (Playground).xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>15</integer>
</dict>
</dict>
</dict>
</plist>
54 changes: 54 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 @@ -269,5 +269,59 @@ class AuthorizationAlamofire: TokenHandling {
}
}

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

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

func createRecord(_ petId: Int ,_ combinedData: [String: Any], _ memoCategoryId: Int, completion: @escaping (Result<Data?, Error>) -> Void) {
os_log("AuthorizationAlamofire - createRecord() called ", log: .default, type: .info)

self.session.request(MySearchRouter.createRecord(petId: petId, combinedData: combinedData, memoCategoryId: memoCategoryId))
.response { response in
switch response.result {
case .success(let data):
completion(.success(data))
case .failure(let error):
completion(.failure(error))
}
}
}

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

self.session.request(MySearchRouter.createFolder(petId: petId, rootMemoCategoryId: rootMemoCategoryId, categoryName: categoryName))
.response { response in
switch response.result {
case .success(let data):
completion(.success(data))
case .failure(let error):
completion(.failure(error))
}
}
}
func recordDataListInquiry(_ petId: Int , _ memoCategoryId: Int, _ searchData: String, completion: @escaping (Result<Data?, Error>) -> Void) {
os_log("AuthorizationAlamofire - recordDataListInquiry() called ", log: .default, type: .info)

self.session.request(MySearchRouter.recordDataListInquiry(petId: petId, memoCategoryId: memoCategoryId, searchData: searchData))
.response { response in
switch response.result {
case .success(let data):
completion(.success(data))
case .failure(let error):
completion(.failure(error))
}
}
}
}

66 changes: 47 additions & 19 deletions fit-a-pet-client/fit-a-pet-client/API/MySearchRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum MySearchRouter: URLRequestConvertible {
case findId(phone: String, code: String)
case findPw(phone: String, newPassword: String, code: String)
case existId(uid: String)
case userProfileInfo, oauthLogin, oauthSendSms, refresh ,userPetsList, userPetInfoList, petCountScheduleList
case userProfileInfo, oauthLogin, oauthSendSms, refresh ,userPetsList, userPetInfoList, petCountScheduleList, recordTotalFolderList
case userNotifyType(type: String)
case editUserPw(type: String, prePassword: String, newPassword: String)
case editUserName(type: String, name: String)
Expand All @@ -30,6 +30,9 @@ enum MySearchRouter: URLRequestConvertible {
case petCareComplete(petId: Int, careId: Int, caredateId: Int)
case createSchedule(combinedData: [String:Any])
case petScheduleList(year: String, month: String, day: String)
case createRecord(petId: Int, combinedData: [String:Any], memoCategoryId: Int)
case createFolder(petId: Int, rootMemoCategoryId: Int, categoryName: String)
case recordDataListInquiry(petId: Int, memoCategoryId: Int, searchData: String)

var baseURL: URL {
switch self {
Expand All @@ -44,9 +47,9 @@ enum MySearchRouter: URLRequestConvertible {

var method: HTTPMethod {
switch self {
case .sendSms, .checkSms, .login, .regist, .presignedurl, .registPet,.sendAuthSms, .checkAuthSms, .findId, .findPw, .oauthLogin, .oauthSendSms, .oauthCheckSms, .oauthRegistUser, .createCare, .careCategoryCheck, .createSchedule:
case .sendSms, .checkSms, .login, .regist, .presignedurl, .registPet,.sendAuthSms, .checkAuthSms, .findId, .findPw, .oauthLogin, .oauthSendSms, .oauthCheckSms, .oauthRegistUser, .createCare, .careCategoryCheck, .createSchedule, .createRecord, .createFolder:
return .post
case .existId, .userProfileInfo, .userNotifyType, .refresh ,.checkCareCategory, .userPetsList, .userPetInfoList, .userPetCareInfoList, .petCareComplete, .petScheduleList, .petCountScheduleList:
case .existId, .userProfileInfo, .userNotifyType, .refresh ,.checkCareCategory, .userPetsList, .userPetInfoList, .userPetCareInfoList, .petCareComplete, .petScheduleList, .petCountScheduleList, .recordTotalFolderList, .recordDataListInquiry:
return .get
case .uploadImage, .editUserPw, .editUserName:
return .put
Expand Down Expand Up @@ -81,22 +84,23 @@ enum MySearchRouter: URLRequestConvertible {
return "v2/accounts/search"
case .existId:
return "v2/accounts/exists"
case .userProfileInfo, .editUserPw, .editUserName:
case .userProfileInfo, .editUserPw, .editUserName, .recordTotalFolderList:
return "v2/accounts/\(UserDefaults.standard.string(forKey: "id")!)"
case .userNotifyType:
return "v2/accounts/\(UserDefaults.standard.string(forKey: "id")!)/notify"
case .userPetsList:
return "v2/users/\(UserDefaults.standard.string(forKey: "id")!)/pets/summary"
case .careCategoryCheck:
return "v2/users/\(UserDefaults.standard.string(forKey: "id")!)/pets/categories-check"
case .userPetCareInfoList, .createCare, .checkCareCategory, .petCareComplete, .petCountScheduleList:
case .userPetCareInfoList, .createCare, .checkCareCategory, .petCareComplete, .petCountScheduleList, .createFolder, .createRecord, .recordDataListInquiry:
return "v2/pets"
case .userPetInfoList:
return "v2/users/\(UserDefaults.standard.string(forKey: "id")!)/pets"
case .createSchedule:
return "v2/schedules"
case .petScheduleList:
return "v2/accounts/\(UserDefaults.standard.string(forKey: "id")!)/schedules"

}
}

Expand Down Expand Up @@ -137,7 +141,9 @@ enum MySearchRouter: URLRequestConvertible {
return ["categoryName": categoryName, "pets": pets]
case let .petScheduleList(year, month, day):
return ["year": year, "month": month, "day": day]
case .uploadImage(_), .userProfileInfo, .oauthLogin, .oauthSendSms, .refresh, .checkCareCategory, .userPetsList, .createCare, .userPetInfoList, .userPetCareInfoList, .petCareComplete, .createSchedule, .petCountScheduleList:
case let .createFolder(_, _ ,categoryName):
return ["subMemoCategoryName": categoryName]
case .uploadImage(_), .userProfileInfo, .oauthLogin, .oauthSendSms, .refresh, .checkCareCategory, .userPetsList, .createCare, .userPetInfoList, .userPetCareInfoList, .petCareComplete, .createSchedule, .petCountScheduleList, .recordTotalFolderList, .createRecord, .recordDataListInquiry:
return [:]

}
Expand Down Expand Up @@ -174,7 +180,7 @@ enum MySearchRouter: URLRequestConvertible {

case .presignedurl(let dirname, let extensionType, _, _):

let bodyParameters = ["dirname": dirname, "extension": extensionType] //TODO: 추후 수정
let bodyParameters = ["dirname": dirname, "extension": extensionType]

let queryParameters = [
URLQueryItem(name: "result", value: "true"),
Expand All @@ -183,8 +189,6 @@ enum MySearchRouter: URLRequestConvertible {
request = createURLRequestWithBodyAndQuery(url: url, bodyParameters: bodyParameters, queryParameters: queryParameters)

case .uploadImage(let image):
request = createURLRequestForImage(url: baseURL, image: image)
print("baseURL: \(baseURL)")

let queryParameters = [URLQueryItem(name: "X-Amz-Algorithm", value: PAYLOADURL.algorithm),
URLQueryItem(name: "X-Amz-Credential", value: PAYLOADURL.credential),
Expand All @@ -195,8 +199,8 @@ enum MySearchRouter: URLRequestConvertible {
URLQueryItem(name: "x-amz-acl", value: PAYLOADURL.acl)
]

request = createURLRequestWithQuery(url: baseURL, queryParameters: queryParameters)
request = createURLRequestForImage(url: baseURL, image: image, queryParameters: queryParameters)

// case .registPet:
// request = createURLRequestWithBody(url: url)

Expand Down Expand Up @@ -267,14 +271,14 @@ enum MySearchRouter: URLRequestConvertible {
case .oauthSendSms:
let idToken = KeychainHelper.loadTempToken()!

let bodyParameters = ["to": RegistrationManager.shared.phone, "idToken": idToken, "nonce": OauthInfo.nonce] as [String : Any]
let bodyParameters = ["to": RegistrationManager.shared.phone!, "idToken": idToken, "nonce": OauthInfo.nonce] as [String : Any]
let queryParameters = [URLQueryItem(name: "provider", value: OauthInfo.provider)]

request = createURLRequestWithBodyAndQuery(url: url, bodyParameters: bodyParameters, queryParameters: queryParameters)
case .oauthCheckSms(let code):
let idToken = KeychainHelper.loadTempToken()!

let bodyParameters = ["to": RegistrationManager.shared.phone, "idToken": idToken, "nonce": OauthInfo.nonce] as [String : Any]
let bodyParameters = ["to": RegistrationManager.shared.phone!, "idToken": idToken, "nonce": OauthInfo.nonce] as [String : Any]
let queryParameters = [URLQueryItem(name: "provider", value: OauthInfo.provider), URLQueryItem(name: "code", value: code)]

request = createURLRequestWithBodyAndQuery(url: url, bodyParameters: bodyParameters, queryParameters: queryParameters)
Expand Down Expand Up @@ -316,6 +320,27 @@ enum MySearchRouter: URLRequestConvertible {
url = url.appendingPathComponent("/\(SelectedPetId.petId)/schedules")
let queryParameters = [URLQueryItem(name: "count", value: "3")]
request = createURLRequestWithQuery(url: url, queryParameters: queryParameters)

case .recordTotalFolderList:
url = url.appendingPathComponent("/memo-categories")
request = URLRequest(url: url)
request.httpMethod = method.rawValue

case .createRecord(let petId, let combinedData, let memoCategoryId):
url = url.appendingPathComponent("/\(petId)/memo-categories/\(memoCategoryId)/memos")
request = URLRequest(url: url)
request.httpMethod = method.rawValue
request = try JSONEncoding.default.encode(request, withJSONObject: combinedData)

case .createFolder(let petId, let rootMemoCategoryId, _):
url = url.appendingPathComponent("/\(petId)/root-memo-categories/\(rootMemoCategoryId)")
request = createURLRequestWithBody(url: url)

case .recordDataListInquiry(let petId, let memoCategoryId, let searchData):
url = url.appendingPathComponent("/\(petId)/memo-categories/\(memoCategoryId)/memos")
request = URLRequest(url: url)
request.httpMethod = method.rawValue

default:
request = createURLRequestWithBody(url: url)
}
Expand Down Expand Up @@ -377,23 +402,26 @@ enum MySearchRouter: URLRequestConvertible {
return request
}

private func createURLRequestForImage(url: URL, image: UIImage) -> URLRequest {
private func createURLRequestForImage(url: URL, image: UIImage, queryParameters: [URLQueryItem]) -> URLRequest {
var request = URLRequest(url: url)
request.httpMethod = method.rawValue

guard let imageData = image.jpegData(compressionQuality: 0.8) else {
return request
}

request.httpBody = imageData
request.setValue("image/jpeg", forHTTPHeaderField: "Content-Type")

var components = URLComponents(url: url, resolvingAgainstBaseURL: false)
components?.queryItems = queryParameters

if let urlWithQuery = components?.url {
request.url = urlWithQuery
}

//os_log
let log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "AlamofireRequest")
os_log("Request URL: %@", log: log, type: .debug, "\(String(describing: request.url))")
os_log("Request Headers: %@", log: log, type: .debug, "\(request.allHTTPHeaderFields ?? [:])")
os_log("Request Body: %@", log: log, type: .debug, "\(String(data: request.httpBody ?? Data(), encoding: .utf8) ?? "Body not available")")

return request
}
}
1 change: 0 additions & 1 deletion fit-a-pet-client/fit-a-pet-client/API/TokenHandling.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ protocol TokenHandling {
extension TokenHandling {
func extractAndStoreToken(from response: AFDataResponse<Data?>) {

// print(response.response?.allHeaderFields as? [String: String])

if let responseHeaders = response.response?.allHeaderFields as? [String: String],
let accessToken = responseHeaders["Authorization"] {
Expand Down
Loading

0 comments on commit caa3ef5

Please sign in to comment.