Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐Ÿ“ฎ Mainํ™”๋ฉด care ๊ด€๋ จ api ์—ฐ๋™ #76

Merged
merged 7 commits into from
Jan 24, 2024

Conversation

heejinnn
Copy link
Collaborator

@heejinnn heejinnn commented Jan 23, 2024

์ž‘์—… ์ด์œ 

  • ์‚ฌ์šฉ์ž pet list ์กฐํšŒ api ์—ฐ๋™
  • ์‚ฌ์šฉ์ž pet care list ์กฐํšŒ api ์—ฐ๋™
  • ์‚ฌ์šฉ์ž pet care list ์กฐํšŒ ํ›„ ๋ฐ์ดํ„ฐ ์ €์žฅ ํฌ๋งท ์„ค์ •
  • care ์ˆ˜ํ–‰ api

์ž‘์—… ์‚ฌํ•ญ

1๏ธโƒฃ ์‚ฌ์šฉ์ž pet list ์กฐํšŒ api

  • GET api/v2/users/{user_id}/pets/summary
AuthorizationAlamofire.shared.userPetsList { result in
      switch result {
      case .success(let data):
          if let responseData = data {
              do {
                  let jsonObject = try JSONSerialization.jsonObject(with: responseData, options: []) as? [String: Any] ?? [:]

                  var pets: [SummaryPet] = []

                  if let dataDict = jsonObject["data"] as? [String: Any],
                      let petsArray = dataDict["pets"] as? [[String: Any]] {

                      for petDict in petsArray {
                          if let petId = petDict["id"] as? Int,
                              let petName = petDict["petName"] as? String {
                              let pet = SummaryPet(id: petId, petName: petName)
                              pets.append(pet)
                          }
                      }
                  }
                  PetDataManager.summaryPets = pets
                  print("User Pets List: \(PetDataManager.summaryPets)")
                  self.petCareMethod.seletedPetId(pets[0].id)
                  self.updateUIWithFetchedData()
          }

      case .failure(let profileError):
          print("Error fetching user pets list: \(profileError)")
      }
}
  • petCollectionView ๋ฐ์ดํ„ฐ ์„ค์ • + ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ 0 index cell ์„ ํƒ
func updateUIWithFetchedData() {
    self.petDataMethod.updatePetCollectData(with: PetDataManager.summaryPets)
    self.petListView.petCollectionView.reloadData()
    self.petCollectionView.reloadData()
    //0๋ฒˆ์งธ cell ๊ธฐ๋ณธ์œผ๋กœ ์„ ํƒ
    let defaultIndexPath = IndexPath(item: 0, section: 0)
    self.petListView.petCollectionView.selectItem(at: defaultIndexPath, animated: false, scrollPosition: .left)
    self.petCollectionView.selectItem(at: defaultIndexPath, animated: false, scrollPosition: .left)
}
  • pet ์„ ํƒ์‹œ ์„ ํƒ ๊ฐ’ ์„ค์ •
petDataMethod.didSelectPetClosure = { selectedPet in
    self.petListView.petCollectionView.selectItem(at: selectedPet, animated: false, scrollPosition: .left)
    self.petCollectionView.selectItem(at: selectedPet, animated: false, scrollPosition: .left)
}

2๏ธโƒฃ ์‚ฌ์šฉ์ž pet care list ์กฐํšŒ api

  • GET api/v2/users/{user_id}/pets/{pet_id}/cares/categories
for (_, pet) in PetDataManager.summaryPets.enumerated() {
    AuthorizationAlamofire.shared.userPetCareInfoList(pet.id) { careInfoResult in
        switch careInfoResult {
        case .success(let careInfoData):
            if let responseData = careInfoData {
                PetDataManager.updateCareInfo(with: responseData, petId: pet.id)
                DispatchQueue.main.async {
                    self.petCareMethod.updatePetCareCollectData(with: PetDataManager.careCategoriesByPetId)
                    self.petCareCollectionView.reloadData()
                }
            }
            
        case .failure(let careInfoError):
            print("Error fetching pet care info for pet \(pet.id): \(careInfoError)")
        }
    }
}
  • ์„ ํƒํ•œ pet id์— ๋”ฐ๋ฅธ petCareCollectionView reload
petDataMethod.didSelectPetClosure = { selectedPet in
    ...
    let selectedPet = PetDataManager.summaryPets[selectedPet.item] 
    self.petCareMethod.seletedPetId(selectedPet.id) // ์„ ํƒํ•œ pet id 
    self.petCareCollectionView.reloadData()
}

3๏ธโƒฃ care ์ˆ˜ํ–‰ api

  • GET api/v2/users/{user_id}/pets/{pet_id}/cares/{care_id}/care-dates/{careDate_id}
petCareMethod.didSelectPetClosure = { [self] indexPath in
    if let careCategory = petCareMethod.petCareData[petCareMethod.selectedPet]?[indexPath.section] {
        let selectedCare = careCategory.cares[indexPath.item]
        self.careId = selectedCare.careId 
        self.caredateId = selectedCare.careDateId
    }
    AuthorizationAlamofire.shared.petCareComplete(petId, careId, caredateId) { result in
        switch result {
        case .success(let data):
            if let responseData = data {
                do {
                    let jsonObject = try JSONSerialization.jsonObject(with: responseData, options: []) as? [String: Any] ?? [:]
                    
                    print("Response JSON Data (User Profile): \(jsonObject)")
                } catch {
                    print("Error parsing user profile JSON: \(error)")
                }
            }
            
        case .failure(let profileError):
            print("Error fetching user profile info: \(profileError)")
        }
        
    }
}

์ด์Šˆ ์—ฐ๊ฒฐ

close #75

@heejinnn heejinnn self-assigned this Jan 23, 2024
Copy link
Member

@psychology50 psychology50 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ”ผ๋“œ๋ฐฑ ๋“œ๋ฆฐ์ง€ ์–ผ๋งˆ๋‚˜ ๋๋‹ค๊ณ  ๋ฐ”๋กœ ๋ฐ˜์˜ํ•ด์ฃผ์‹œ๋„ค์š”. ๋ฉ‹์žˆ์Šต๋‹ˆ๋‹ค..

@psychology50 psychology50 merged commit 5817c0c into develop Jan 24, 2024
1 check passed
@psychology50 psychology50 deleted the feat/75 branch January 24, 2024 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

โœจMain ํ™”๋ฉด ์ผ€์–ด ๊ด€๋ จ API ์—ฐ๋™
2 participants