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

[Network] #110 - 식당 제보하기 기능 완료 #115

Merged
merged 7 commits into from
Jul 19, 2024
Merged

Conversation

EunsuSeo01
Copy link
Member

🔥 Pull requests

👷 작업한 내용

  • 식당 제보하기 API 멀티파트 통신 코드 작성
  • 식당 카테고리 API 제보하기 화면에 연결
  • 데이터 바인딩 완료

🚨 참고 사항

BaseTargetType.swift

case formdataHeader(multipartData: [MultipartFormData])

멀티파트 통신을 위한 헤더 타입이 추가되었습니다.

📸 스크린샷

구현 내용 SE Console
GIF

🖥️ 주요 코드 설명

ReportViewModel.swift

  • createMultipartFormData 함수를 통해 멀티파트 통신할 때 사용되는 [MultipartFormData] 타입의 데이터를 만듭니다.
func createMultipartFormData(image: Data?, request: PostHankkiRequestDTO) -> [MultipartFormData] {
        var multipartData: [MultipartFormData] = []
        multipartData.append(MultipartFormData(provider: .data(image ?? .empty), name: "image", fileName: "image.jpg", mimeType: "image/jpeg"))
        let jsonData = convertToJSON(request: request)
        multipartData.append(MultipartFormData(provider: .data(jsonData), name: "request", fileName: "request.json", mimeType: "application/json"))
        return multipartData
    }
  • convertToJSON 함수를 통해 PostHankkiRequestDTO 형태의 구조체를 JSON 형태로 변경합니다.
    func convertToJSON(request: PostHankkiRequestDTO) -> Data {
        do {
            let jsonData = try JSONEncoder().encode(request)
            return jsonData
        } catch {
            print("JSON 변환 실패", error.localizedDescription)
        }
        return Data()
    }

ReportViewController.swift

  • collectMenuCellData 함수를 통해 메뉴 컬렉션뷰 셀을 하나씩 돌면서 셀 안에 있는 2개의 텍스트필드(메뉴 이름과 가격)의 값을 순차적으로 가져와 [MenuData] 형태를 만듭니다.
  • filter 함수를 사용하여 메뉴 이름 또는 가격 값이 비어있는 것은 제외시켰습니다.
  • 이를 식당 제보하기 API를 호출할 때 Request의 형태로 넣어줍니다.
/// 사용자가 셀에 입력한 메뉴 데이터 모으기
    /// 빈값 필터링
    func collectMenuCellData() {
        var sectionNumber: Int = ReportSectionType.menu.rawValue

        var menuName: String = ""
        var menuPrice: String = ""

        for i in 0..<collectionView.numberOfItems(inSection: sectionNumber) {
            let indexPath = IndexPath(row: i, section: sectionNumber)
            if let cell = collectionView.cellForItem(at: indexPath) as? MenuCollectionViewCell {
                for subview in cell.contentView.subviews {
                    if let textField = subview as? UITextField {
                        if textField.tag == i * 2 {
                            menuName = textField.text ?? ""
                        } else if textField.tag == i * 2 + 1 {
                            menuPrice = textField.text ?? ""
                        }
                    }
                }

                let menuData = MenuData(name: menuName, price: Int(menuPrice) ?? 0)
                menuCellData.append(menuData)
            }
        }

        // 빈값은 버림
        menuCellData = menuCellData.filter { $0.name != "" && $0.price != 0 }
    }

✅ Check List

  • Merge 대상 브랜치가 올바른가?
  • 최종 코드가 에러 없이 잘 동작하는가?
  • 전체 변경사항이 500줄을 넘지 않는가?

📟 관련 이슈

@EunsuSeo01 EunsuSeo01 added 🐬 은수 은수 공주 작업 🛜 Network API 연결 labels Jul 19, 2024
@EunsuSeo01 EunsuSeo01 self-assigned this Jul 19, 2024
@EunsuSeo01 EunsuSeo01 linked an issue Jul 19, 2024 that may be closed by this pull request
2 tasks
@EunsuSeo01 EunsuSeo01 changed the title [Network] #110 - [Network] #110 - 식당 제보하기 기능 완료 Jul 19, 2024
Copy link
Member

@mcrkgus mcrkgus left a comment

Choose a reason for hiding this comment

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

레전드 개발자 발생 나이스하다

/// 식당 제보하기 Response
struct PostHankkiResponseData: Codable {
var name: String
var id: Int64
Copy link
Member

Choose a reason for hiding this comment

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

detail good

Comment on lines +163 to +179
for i in 0..<collectionView.numberOfItems(inSection: sectionNumber) {
let indexPath = IndexPath(row: i, section: sectionNumber)
if let cell = collectionView.cellForItem(at: indexPath) as? MenuCollectionViewCell {
for subview in cell.contentView.subviews {
if let textField = subview as? UITextField {
if textField.tag == i * 2 {
menuName = textField.text ?? ""
} else if textField.tag == i * 2 + 1 {
menuPrice = textField.text ?? ""
}
}
}

let menuData = MenuData(name: menuName, price: Int(menuPrice) ?? 0)
menuCellData.append(menuData)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

아주 NICE LGTM

Copy link
Contributor

@shimseohyun shimseohyun left a comment

Choose a reason for hiding this comment

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

개 굿이오 마마

Comment on lines 23 to 24
window = UIWindow(windowScene: windowScene)
window?.rootViewController = SplashViewController()
window?.rootViewController = navigationController
Copy link
Contributor

Choose a reason for hiding this comment

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

바꿔주시오
image

@@ -55,15 +56,21 @@ extension BaseTargetType {
}

var headers: [String: String]? {
var header = ["Content-Type": "application/json"]
var header: [String: String] = [:]
Copy link
Contributor

Choose a reason for hiding this comment

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

타입 지정 아주 나이스 하오


var selectedImageData: Data?

var menus: [MenuData] = [MenuData()]
Copy link
Contributor

Choose a reason for hiding this comment

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

이건 그냥 빈 배열로 넣어야하면 안되나요?

Copy link
Member Author

Choose a reason for hiding this comment

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

기본으로 메뉴 셀 하나는 처음부터 보여야 해서 이렇게 했습니다!

@EunsuSeo01 EunsuSeo01 merged commit f251e6c into develop Jul 19, 2024
@EunsuSeo01 EunsuSeo01 deleted the network/#110 branch July 19, 2024 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐬 은수 은수 공주 작업 🛜 Network API 연결
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Network] 식당 제보하기 API 연동
3 participants