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

๐Ÿ“ฎ๐ŸŽจ ์œ ์ €/๋ฐ˜๋ ค๋™๋ฌผ ๊ด€๋ จ api ์—ฐ๋™ + UI ์ˆ˜์ • #100

Merged
merged 10 commits into from
Mar 17, 2024

Conversation

heejinnn
Copy link
Collaborator

@heejinnn heejinnn commented Mar 16, 2024

์ž‘์—… ์ด์œ 

๐Ÿ“ฎ api ์—ฐ๋™

  • ๋‹ค๋ฅธ ์œ ์ € ๋ณ„๋ช… ๋ณ€๊ฒฝ
  • ์‚ฌ์šฉ์ž ์„ค์ • ์ด๋ฆ„ ์กฐํšŒ
  • ๋ฐ˜๋ ค๋™๋ฌผ ์ •๋ณด ์กฐํšŒ
  • ๋ฐ˜๋ ค๋™๋ฌผ ์‚ญ์ œ
  • ๋ฐ˜๋ ค๋™๋ฌผ ์ˆ˜์ •

๐ŸŽจ UI ์ˆ˜์ • (๋ฐ˜๋ ค๋™๋ฌผ ์ˆ˜์ • ํ™”๋ฉด)

  • ์„ฑ๋ณ„ ์„ ํƒ menu -> PanModal๋กœ ๋ณ€๊ฒฝ
  • ์ƒ์ผ "๋‚˜์ด๋กœ ์ž…๋ ฅํ•˜๊ธฐ" toggle Button ์ถ”๊ฐ€

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

โœ๏ธ api case

case userNicknameCheck(userId: Int)// ์‚ฌ์šฉ์ž ์„ค์ • ์ด๋ฆ„ ์กฐํšŒ
case editSomeoneNickname(userId: Int, nickname: String)//๋‹ค๋ฅธ ์œ ์ € ๋ณ„๋ช… ๋ณ€๊ฒฝ
case petTotalInfoCheck(petId: Int)//๋ฐ˜๋ ค๋™๋ฌผ ์ •๋ณด ์กฐํšŒ
case petInfoEdit(petId: Int, combinedData: [String:Any])//๋ฐ˜๋ ค๋™๋ฌผ ์ˆ˜์ •
case petDelete(petId: Int)//๋ฐ˜๋ ค๋™๋ฌผ ์‚ญ์ œ

1๏ธโƒฃ ์‚ฌ์šฉ์ž ์„ค์ • ์ด๋ฆ„ ์กฐํšŒ

  • GET api/v2/accounts/{user_id}/name
  • "์ด๋ฆ„ ๋ณ€๊ฒฝ" menu๋ฅผ ํด๋ฆญํ•œ ๊ฒฝ์šฐ delegate ์‚ฌ์šฉํ•˜์—ฌ userNicknameCheck api์— ์š”์ฒญ์„ ๋ณด๋‚ธ๋‹ค.
protocol MemberTableViewCellDelegate: AnyObject {
    func didTapChangeName(_ userId: Int)
    func didTapCancellationBtn(_ userId: Int, _ userName: String)
    func didTapDelegationBtn(_ userId: Int, _ userName: String)
}
func didTapChangeName(_ userId: Int) {
    AuthorizationAlamofire.shared.userNicknameCheck(userId){ result in
        switch result {
        case .success(let data):
            if let responseData = data {
                do {
                    if let json = try JSONSerialization.jsonObject(with: responseData, options: []) as? [String: Any] {
                        if let jsonData = json["data"] as? [String: Any], let name = jsonData["name"] as? String {
                            let nextVC = EditUserNameVC(title: "์ด๋ฆ„ ๋ณ€๊ฒฝํ•˜๊ธฐ")
                            nextVC.beforeUserName = name//์‚ฌ์šฉ์ž์—๊ฒŒ ํ˜„์žฌ ์„ค์ •๋˜์–ด์žˆ๋Š” name
                            nextVC.division = "someone"//๋‹ค๋ฅธ ์‚ฌ์šฉ์ž ๋‹‰๋„ค์ž„ ์ˆ˜์ • ๋ถ„๊ธฐ ์ฒ˜๋ฆฌ
                            nextVC.selectedId = userId
                            self.delegate?.pushViewController(nextVC, animated: true)
                        }
                    }
                } catch {
                    print("Error: \(error)")
                }
            }
        case .failure(let error):
            print("Error: \(error)")
        }
    }
}

2๏ธโƒฃ ๋‹ค๋ฅธ ์œ ์ € ๋ณ„๋ช… ๋ณ€๊ฒฝ

  • PUT api/v2/accounts/{user_id}/nickname
  • division ๋ณ€์ˆ˜๋กœ "me", "someone"์œผ๋กœ ๊ตฌ๋ถ„ํ•˜์—ฌ ์ž์‹ ์˜ ๋‹‰๋„ค์ž„ ์ˆ˜์ •๊ณผ ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž ๋‹‰๋„ค์ž„ ์ˆ˜์ •์„ ๋ถ„๊ธฐ์ฒ˜๋ฆฌํ•˜์˜€๋‹ค.
if division == "me" {
    AuthorizationAlamofire.shared.editUserName("name", userName){ [self]
        ...
    }
}else{
    AuthorizationAlamofire.shared.editSomeoneNickname(selectedId, userName){ [self]
        result in
        switch result {
        case .success(let data):
            if let responseData = data {
                NotificationCenter.default.post(name: .managerDelegationBtnTapped, object: nil)
                self.navigationController?.popViewController(animated: true)
            }
        case .failure(let error):
            print("Error: \(error)")
        }
    }
}  

3๏ธโƒฃ ๋ฐ˜๋ ค๋™๋ฌผ ์ •๋ณด ์กฐํšŒ

  • GET api/v2/pets/{pet_id}
  • ๋ฐ›์•„์˜จ ๋ฐ์ดํ„ฐ๋Š” PetDataManager.petEditData ์—์„œ ๊ด€๋ฆฌ
struct PetEditData: Codable{
    let id: Int
    var petName: String
    var petProfileImage: String
    var gender: String
    var neutered: Bool
    var birthdate: String
    var species: String
    var feed: String
}
AuthorizationAlamofire.shared.petTotalInfoCheck(SelectedPetId.petId) { result in
        switch result {
        case .success(let data):
            if let responseData = data,
               let jsonObject = try? JSONSerialization.jsonObject(with: responseData, options: []) as? [String: Any],
               let dataObject = jsonObject["data"] as? [String: Any],
               let petObject = dataObject["pet"] as? [String: Any] {
                
                ...
                
                let newPetEditData = PetEditData(id: id, petName: petName, petProfileImage: petProfileImage, gender: gender, neutered: neutered, birthdate: birthdate, species: species, feed: feed)
                
                PetDataManager.petEditData = newPetEditData
            }
            
        case .failure(let error):
            print("Error: \(error)")
        }
    }
}
  • ๋ฐ›์•„์˜จ ๋ฐ์ดํ„ฐ๋กœ ๊ธฐ์กด ๋ฐ˜๋ ค๋™๋ฌผ์˜ ๋ฐ์ดํ„ฐ ์ˆ˜์ •ํ™”๋ฉด์— ์„ธํŒ…

4๏ธโƒฃ ๋ฐ˜๋ ค๋™๋ฌผ ์ˆ˜์ •

  • PUT api/v2/pets/{pet_id}
  • ์ˆ˜์ •ํ™”๋ฉด์—์„œ ๋ฐ”๊พผ ๋ฐ์ดํ„ฐ๋“ค PetDataManager.petEditData์— ์ ์šฉ
let petEditData = PetDataManager.petEditData

let combinedData: [String: Any] = [
    "petName": petEditData.petName,
    "gender": petEditData.gender,
    "neutralization": petEditData.neutered,
    "birthdate": petEditData.birthdate,
    "species": petEditData.species,
    "feed": petEditData.feed
]

AuthorizationAlamofire.shared.petInfoEdit(SelectedPetId.petId, combinedData){ result in
    switch result {
    case .success(let data):
        if let responseData = data,
           let jsonObject = try? JSONSerialization.jsonObject(with: responseData, options: []) as? [String: Any] {
            self.navigationController?.popViewController(animated: true)
        }
        
    case .failure(let error):
        print("Error: \(error)")
    }
}

5๏ธโƒฃ ๋ฐ˜๋ ค๋™๋ฌผ ์‚ญ์ œ

  • DELETE api/v2/pets/{pet_id}
  • ์‚ญ์ œ ๋ฒ„ํŠผ ๋ˆ„๋ฅด๋ฉด ์‚ญ์ œ api ํ˜ธ์ถœ ํ›„ navigationController RootView๋กœ ์ด๋™ํ•œ๋‹ค.
AuthorizationAlamofire.shared.petDelete(SelectedPetId.petId){ 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)")
            self.navigationController?.popToRootViewController(animated: true)
        }
        
    case .failure(let error):
        print("Error: \(error)")
    }
}

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

close #98

@heejinnn heejinnn requested a review from psychology50 March 16, 2024 10:47
@heejinnn heejinnn self-assigned this Mar 16, 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.

ํ•œ ๊ฐ€์ง€ ๊ฑธ๋ฆฌ๋Š” ๊ฒŒ ์žˆ์–ด์„œ ์ปค๋ฉ˜ํŠธ ๋‚จ๊ฒจ๋‘ก๋‹ˆ๋‹ค.
์กธ์ž‘ํ•˜๋ฉด์„œ ์ด๊ฑฐ๊นŒ์ง€ ํ•˜์‹œ๋Š๋ผ ์ˆ˜๊ณ  ๋งŽ์œผ์‹ญ๋‹ˆ๋‹ค.

@heejinnn heejinnn merged commit 72b2f54 into develop Mar 17, 2024
9 of 10 checks passed
@heejinnn heejinnn deleted the feat/98 branch March 17, 2024 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants