-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from KCY-Fit-a-Pet/feat/70
📮 pet 정보 리스트 api 연동
- Loading branch information
Showing
16 changed files
with
324 additions
and
109 deletions.
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
Binary file modified
BIN
+12.6 KB
(110%)
...it-a-pet-client.xcworkspace/xcuserdata/maclove.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
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
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
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
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 |
---|---|---|
|
@@ -51,3 +51,7 @@ enum ViewState { | |
case daysTableView | ||
static var stateNum = 0 | ||
} | ||
|
||
enum SelectedPetId{ | ||
static var petId = 0 | ||
} |
80 changes: 80 additions & 0 deletions
80
fit-a-pet-client/fit-a-pet-client/Utils/PetDataManager.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 @@ | ||
import Foundation | ||
|
||
struct PetInfoResponse: Codable { | ||
let status: String | ||
let data: PetData? | ||
} | ||
|
||
struct PetData: Codable { | ||
let pets: [Pet]? | ||
} | ||
|
||
struct Pet: Codable { | ||
let id: Int | ||
let petName: String | ||
let gender: String | ||
let petProfileImage: String | ||
let feed: String | ||
let age: Int | ||
} | ||
|
||
struct CareInfoResponse: Codable { | ||
let status: String | ||
let data: CareInfo? | ||
} | ||
|
||
struct CareInfo: Codable { | ||
var careCategories: [CareCategory]? | ||
|
||
} | ||
|
||
struct CareCategory: Codable { | ||
let careCategoryId: Int | ||
let categoryName: String | ||
var cares: [Care] | ||
} | ||
|
||
struct Care: Codable { | ||
let careId: Int | ||
let careDateId: Int | ||
let careName: String | ||
let careDate: String | ||
let isClear: Bool | ||
} | ||
|
||
|
||
struct PetDataManager { | ||
static var pets: [Pet] = [] | ||
static var careCategories: [CareCategory] = [] | ||
|
||
static func updatePets(with data: Data) { | ||
do { | ||
let decoder = JSONDecoder() | ||
let petInfoResponse = try decoder.decode(PetInfoResponse.self, from: data) | ||
|
||
if let newPets = petInfoResponse.data?.pets { | ||
pets = newPets | ||
|
||
print("petsList: \(pets)") | ||
} | ||
} catch { | ||
print("Error updating pet data: \(error)") | ||
} | ||
} | ||
|
||
|
||
static func updateCareInfo(with data: Data) { | ||
do { | ||
let decoder = JSONDecoder() | ||
let careInfoResponse = try decoder.decode(CareInfoResponse.self, from: data) | ||
|
||
if let newCareCategories = careInfoResponse.data?.careCategories { | ||
careCategories = newCareCategories | ||
print("careCategories: \(careCategories)") | ||
} | ||
} catch { | ||
print("Error updating care info: \(error)") | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.