네트워크를 구현하여 홈 탭 및 함께메뉴결정 탭에 서버 데이터를 반영합니다.#5
Merged
Conversation
- NetworkProvider 추가 - WhatWeEatBaseURL 및 API 추가 - 네트워크 관련 Model 추가 - HomeViewModel 추가 - 함께메뉴결정 탭에서 그룹만들기 버튼을 탭했을 때 서버에서 임의의 PIN 번호를 받아 다음 화면의 ViewModel로 전달
- 불필요한 파일 제거
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
배경
서버와 통신을 해서 홈탭의 랜덤 메뉴, 함께메뉴결정의 PIN 번호를 띄울 수 있도록 했습니다.
작업 내용
1. 네트워크 구현 및 API 추상화
RxSwift를 활용하여 비동기 작업을 처리했습니다. 서버에서 받아온 데이터는Observable타입으로 반환하고, ViewModel에서 ViewController에 전달하여 화면에 나타내는 구조로 구현했습니다.API를 열거형으로 관리하는 경우, API를 추가할 때마다 새로운 case를 생성하여 열거형이 비대해지고, 열거형 관련 switch문을 매번 수정해야 하는 번거로움이 있었습니다. 따라서 API마다 독립적인 구조체 타입으로 관리되도록 변경하고, URL 프로퍼티 외에도 HttpMethod 프로퍼티를 추가한 APIProtocol 타입을 채택하도록 개선했습니다. 이로써 코드유지 보수가 용이하며, 협업 시 각자 담당한 API 구조체 타입만 관리하면 되기 때문에 충돌을 방지할 수 있습니다.
2. 데모 웹 애플리케이션을 통한 네트워크 테스트
jar 실행파일을 설치하여데모 웹 애플리케이션을 통한 네트워크 테스트 (baseURL을http://localhost:8080/로 설정)를 구현했습니다. 실제 서버와 독립적인 테스트를 실행한 이유는 아래와 같습니다.3. 홈탭의 랜덤메뉴
랜덤메뉴의 이름, 이미지를 서버에서 받아 띄워줬습니다.
HomeViewController의viewDidLoad시점에서 서버로부터 데이터를 받아오도록 했습니다. 이때 서버에서 보내주는 데이터 형식이 JSON이기 때문에,MenuEntity를 추가했습니다.추후 GameResult에 대한 데이터를 Get할 때에는 각 메뉴에 해당하는 키워드를 보여줘야 했기에 이는 옵셔널 타입으로 뒀습니다.
4. 함께메뉴결정 탭의 PIN 번호
TogetherMenuViewController의makeGroupButton을 탭할 경우TogetherMenuViewModel에서 서버에게 PIN 번호를 요청합니다.request(api:)메서드를 통해Observable<Int>로 반환 값을 받으면 이를 FlowCoordinator의showSharePinNumberPage로 전달 후SharePinNumberPageViewModel로 전달하여SharePinNumberPageViewController에서 View에 띄울 수 있도록 했습니다.서버에서 JSON 형태로 데이터를 전달해주는 것이 아니라, Int 타입으로 PIN 번호만 보내주기 때문에 따로 Entity를 구현하진 않았습니다.
테스트 방법
데모 웹 애플리케이션을 로컬에 설치하여 서버 데이터가 정상적으로 반영되는지 확인합니다.
리뷰 노트
Activity Indicator를 추가할 예정입니다.스크린샷