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

๐Ÿ“ฎ Schedule ๋“ฑ๋ก/์กฐํšŒ api ์—ฐ๋™ #84

Merged
merged 3 commits into from
Jan 30, 2024

Conversation

heejinnn
Copy link
Collaborator

์ž‘์—… ์ด์œ 

  • ์ผ์ • ๋“ฑ๋ก
  • ๊ด€๋ฆฌ ์ค‘์ธ ๋ชจ๋“  ๋ฐ˜๋ ค๋™๋ฌผ์˜ ์ง€์ • ๋‚ ์งœ ์ผ์ • ์กฐํšŒ

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

1๏ธโƒฃ ์ผ์ • ๋“ฑ๋ก

  • POST api/v2/users/{user_id}/pets/{pet_id}/schedules (์ถ”ํ›„ ๋ณ€๋™ ์˜ˆ์ •)
let combinedData: [String: Any] = [
    "scheduleName": ScheduleRegistrationManager.shared.scheduleName ?? "",
    "location": ScheduleRegistrationManager.shared.location ?? "",
    "reservationDate": ScheduleRegistrationManager.shared.reservationDate ?? "",
    "notifyTime": ScheduleRegistrationManager.shared.notifyTime ?? 0,
    "petIds": ScheduleRegistrationManager.shared.petIds ?? [],
]
        
AuthorizationAlamofire.shared.createSchedule(combinedData){ 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)")
                
                self.dismiss(animated: true){ [weak self] in
                    self?.reloadClosure?()
                }

            } catch {
                print("Error parsing user profile JSON: \(error)")
            }
        }

    case .failure(let profileError):
        print("Error fetching user profile info: \(profileError)")
    }
}

2๏ธโƒฃ ๊ด€๋ฆฌ ์ค‘์ธ ๋ชจ๋“  ๋ฐ˜๋ ค๋™๋ฌผ์˜ ์ง€์ • ๋‚ ์งœ ์ผ์ • ์กฐํšŒ

  • GET api/v2/users/1/schedules?year={year}&month={month}&day={day}
func petScheduleListAPI(_ year: String, _ month: String, _ day: String){
    AuthorizationAlamofire.shared.petScheduleList(year, month, day){ result in
        switch result {
        case .success(let data):
            if let responseData = data {
                do {
                    self.scheduleListResponse = try JSONDecoder().decode(ScheduleListResponse.self, from: responseData)
                    
                    let schedules = self.scheduleListResponse!.data.schedules
                    self.scheduleView.scheduleListTableView.reloadData()
                } catch {
                    print("Error decoding schedule list JSON: \(error)")
                }
            }
            
        case .failure(let profileError):
            print("Error fetching user pets list: \(profileError)")
        }
    }
}
  • ์‘๋‹ต ๋ฐ์ดํ„ฐ ๊ด€๋ฆฌ
struct PetScheduleInfo: Codable {
    let petId: Int
    let petProfileImage: String
}

struct ScheduleData: Codable {
    let reservationDate: String
    let scheduleId: Int
    let scheduleName: String
    let location: String
    let pets: [PetScheduleInfo]
}

struct ScheduleListResponse: Codable {
    let status: String
    var data: ScheduleListData
}

struct ScheduleListData: Codable {
    var schedules: [ScheduleData]
}
  • ๋™์ž‘ ํ™•์ธ

Simulator Screen Recording - iPhone 14 - 2024-01-30 at 18 00 38

โœ๏ธ ์ผ์ • ๋“ฑ๋กVC dismiss๋œ ๊ฒฝ์šฐ CalendarVC viewWillAppear ์‹คํ–‰

: ์ƒˆ๋กญ๊ฒŒ ์ถ”๊ฐ€๋œ ์ผ์ •์ด ๋ฐ˜์˜๋˜์ง€ ์•Š๋Š” ์˜ค๋ฅ˜๋•Œ๋ฌธ์— viewWillAppear์‹คํ–‰ํ•˜์—ฌ ์ƒˆ๋กœ์šด ๊ฐ’์œผ๋กœ reload

  • ์ผ์ • ๋“ฑ๋กVC present
 @objc func didTapAddButton() {
    let calendarRegistrationVC = CalendarRegistrationVC()
    let navigationController = UINavigationController(rootViewController: calendarRegistrationVC)
    
    calendarRegistrationVC.reloadClosure = { [weak self] in //reloadClosure๊ฐ€ ์‹คํ–‰๋œ ๊ฒฝ์šฐ (์ฆ‰, ์ผ์ • ๋“ฑ๋ก VC dismiss๋œ ๊ฒฝ์šฐ ์‹คํ–‰๋˜๋„๋ก)
        self?.viewWillAppear(true)
    }
    
    self.present(navigationController, animated: true)
  
}
  • ์ผ์ • ๋“ฑ๋กVC dismiss
 self.dismiss(animated: true){ [weak self] in
    self?.reloadClosure?()
}

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

#82

@heejinnn heejinnn self-assigned this Jan 30, 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.

์Šค์ผ€์ค„ api ํ•„์š”ํ•˜๋ฉด ๋ฐ”๋กœ ๋ง์”€ํ•ด์ฃผ์„ธ์š”

@psychology50 psychology50 merged commit e511deb into develop Jan 30, 2024
3 checks passed
@psychology50 psychology50 deleted the feat/82 branch January 30, 2024 12:20
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.

2 participants