Skip to content

Commit

Permalink
Merge pull request #333 from boostcampwm-2021/issue/#332
Browse files Browse the repository at this point in the history
[리팩토링] 프로토콜과 extension 파일 분리
  • Loading branch information
sujeong000 authored Nov 30, 2021
2 parents b2489bf + 09ea668 commit 8546bf7
Show file tree
Hide file tree
Showing 46 changed files with 541 additions and 253 deletions.
106 changes: 101 additions & 5 deletions BBus/BBus.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// AlarmSettingAPIUsable.swift
// BBus
//
// Created by 최수정 on 2021/12/01.
//

import Foundation
import Combine

protocol AlarmSettingAPIUsable: BaseUseCase {
func busArriveInfoWillLoaded(stId: String, busRouteId: String, ord: String) -> AnyPublisher<ArrInfoByRouteDTO, Error>
func busStationsInfoWillLoaded(busRouetId: String, arsId: String) -> AnyPublisher<[StationByRouteListDTO]?, Error>
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
import Foundation
import Combine

protocol AlarmSettingAPIUsable: BaseUseCase {
func busArriveInfoWillLoaded(stId: String, busRouteId: String, ord: String) -> AnyPublisher<ArrInfoByRouteDTO, Error>
func busStationsInfoWillLoaded(busRouetId: String, arsId: String) -> AnyPublisher<[StationByRouteListDTO]?, Error>
}

final class AlarmSettingAPIUseCase: AlarmSettingAPIUsable {
typealias AlarmSettingUseCases = GetArrInfoByRouteListUsable & GetStationsByRouteListUsable

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// AlarmSettingCalculatable.swift
// BBus
//
// Created by 최수정 on 2021/12/01.
//

import Foundation

protocol AlarmSettingCalculatable: AverageSectionTimeCalculatable { }
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@

import Foundation

protocol AlarmSettingCalculatable: AverageSectionTimeCalculatable { }

struct AlarmSettingCalculateUseCase: AlarmSettingCalculatable { }
15 changes: 15 additions & 0 deletions BBus/BBus/Foreground/BusRoute/UseCase/BusRouteAPIUsable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// BusRouteAPIUsable.swift
// BBus
//
// Created by 최수정 on 2021/12/01.
//

import Foundation
import Combine

protocol BusRouteAPIUsable: BaseUseCase {
func searchHeader(busRouteId: Int) -> AnyPublisher<BusRouteDTO?, Error>
func fetchRouteList(busRouteId: Int) -> AnyPublisher<[StationByRouteListDTO], Error>
func fetchBusPosList(busRouteId: Int) -> AnyPublisher<[BusPosByRtidDTO], Error>
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
import Foundation
import Combine

protocol BusRouteAPIUsable: BaseUseCase {
func searchHeader(busRouteId: Int) -> AnyPublisher<BusRouteDTO?, Error>
func fetchRouteList(busRouteId: Int) -> AnyPublisher<[StationByRouteListDTO], Error>
func fetchBusPosList(busRouteId: Int) -> AnyPublisher<[BusPosByRtidDTO], Error>
}

final class BusRouteAPIUseCase: BusRouteAPIUsable {

private let useCases: GetRouteListUsable & GetStationsByRouteListUsable & GetBusPosByRtidUsable
Expand Down
18 changes: 18 additions & 0 deletions BBus/BBus/Foreground/Home/UseCase/HomeAPIUsable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// HomeAPIUsable.swift
// BBus
//
// Created by 최수정 on 2021/12/01.
//

import Foundation
import Combine

protocol HomeAPIUsable: BaseUseCase {
typealias HomeUseCases = GetFavoriteItemListUsable & CreateFavoriteItemUsable & GetStationListUsable & GetRouteListUsable & GetArrInfoByRouteListUsable

func fetchFavoriteData() -> AnyPublisher<[FavoriteItemDTO], Error>
func fetchBusRemainTime(favoriteItem: FavoriteItemDTO) -> AnyPublisher<HomeFavoriteInfo, Error>
func fetchStation() -> AnyPublisher<[StationDTO], Error>
func fetchBusRoute() -> AnyPublisher<[BusRouteDTO], Error>
}
9 changes: 0 additions & 9 deletions BBus/BBus/Foreground/Home/UseCase/HomeAPIUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@
import Foundation
import Combine

protocol HomeAPIUsable: BaseUseCase {
typealias HomeUseCases = GetFavoriteItemListUsable & CreateFavoriteItemUsable & GetStationListUsable & GetRouteListUsable & GetArrInfoByRouteListUsable

func fetchFavoriteData() -> AnyPublisher<[FavoriteItemDTO], Error>
func fetchBusRemainTime(favoriteItem: FavoriteItemDTO) -> AnyPublisher<HomeFavoriteInfo, Error>
func fetchStation() -> AnyPublisher<[StationDTO], Error>
func fetchBusRoute() -> AnyPublisher<[BusRouteDTO], Error>
}

final class HomeAPIUseCase: HomeAPIUsable {

private let useCases: HomeUseCases
Expand Down
14 changes: 14 additions & 0 deletions BBus/BBus/Foreground/Home/UseCase/HomeCalculatable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// HomeCalculatable.swift
// BBus
//
// Created by 최수정 on 2021/12/01.
//

import Foundation

protocol HomeCalculateUsable: BaseUseCase {
func findStationName(in list: [StationDTO]?, by stationId: String) -> String?
func findBusName(in list: [BusRouteDTO]?, by busRouteId: String) -> String?
func findBusType(in list: [BusRouteDTO]?, by busName: String) -> RouteType?
}
6 changes: 0 additions & 6 deletions BBus/BBus/Foreground/Home/UseCase/HomeCalculateUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@

import Foundation

protocol HomeCalculateUsable: BaseUseCase {
func findStationName(in list: [StationDTO]?, by stationId: String) -> String?
func findBusName(in list: [BusRouteDTO]?, by busRouteId: String) -> String?
func findBusType(in list: [BusRouteDTO]?, by busName: String) -> RouteType?
}

struct HomeCalculateUseCase: HomeCalculateUsable {
func findStationName(in list: [StationDTO]?, by stationId: String) -> String? {
guard let stationId = Int(stationId),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// MovingStatusAPIUsable.swift
// BBus
//
// Created by 최수정 on 2021/12/01.
//

import Foundation
import Combine

protocol MovingStatusAPIUsable: BaseUseCase {
func searchHeader(busRouteId: Int) -> AnyPublisher<BusRouteDTO?, Error>
func fetchRouteList(busRouteId: Int) -> AnyPublisher<[StationByRouteListDTO], Error>
func fetchBusPosList(busRouteId: Int) -> AnyPublisher<[BusPosByRtidDTO], Error>
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
import Foundation
import Combine

protocol MovingStatusAPIUsable: BaseUseCase {
func searchHeader(busRouteId: Int) -> AnyPublisher<BusRouteDTO?, Error>
func fetchRouteList(busRouteId: Int) -> AnyPublisher<[StationByRouteListDTO], Error>
func fetchBusPosList(busRouteId: Int) -> AnyPublisher<[BusPosByRtidDTO], Error>
}

final class MovingStatusAPIUseCase: MovingStatusAPIUsable {

private let useCases: GetRouteListUsable & GetStationsByRouteListUsable & GetBusPosByRtidUsable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// MovingStatusCalculatable.swift
// BBus
//
// Created by 최수정 on 2021/12/01.
//

import Foundation

protocol MovingStatusCalculatable: AverageSectionTimeCalculatable {
func filteredBuses(from buses: [BusPosByRtidDTO], startOrd: Int, currentOrd: Int, count: Int) -> [BusPosByRtidDTO]
func convertBusInfo(header: BusRouteDTO) -> BusInfo
func remainStation(bus: BusPosByRtidDTO, startOrd: Int, count: Int) -> Int
func pushAlarmMessage(remainStation: Int) -> (message: String?, terminated: Bool)
func remainTime(bus: BusPosByRtidDTO, stations: [StationInfo], startOrd: Int, boardedBus: BoardedBus) -> Int
func convertBusPos(startOrd: Int, order: Int, sect: String, fullSect: String) -> Double
func isOnBoard(gpsY: Double, gpsX: Double, busY: Double, busX: Double) -> Bool
func stationIndex(with targetId: String, with stations: [StationByRouteListDTO]) -> Int?
func filteredStations(from stations: [StationByRouteListDTO]) -> (stations: [StationInfo], time: Int)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,6 @@ import Foundation
import Combine
import CoreLocation

protocol MovingStatusCalculatable: AverageSectionTimeCalculatable {
func filteredBuses(from buses: [BusPosByRtidDTO], startOrd: Int, currentOrd: Int, count: Int) -> [BusPosByRtidDTO]
func convertBusInfo(header: BusRouteDTO) -> BusInfo
func remainStation(bus: BusPosByRtidDTO, startOrd: Int, count: Int) -> Int
func pushAlarmMessage(remainStation: Int) -> (message: String?, terminated: Bool)
func remainTime(bus: BusPosByRtidDTO, stations: [StationInfo], startOrd: Int, boardedBus: BoardedBus) -> Int
func convertBusPos(startOrd: Int, order: Int, sect: String, fullSect: String) -> Double
func isOnBoard(gpsY: Double, gpsX: Double, busY: Double, busX: Double) -> Bool
func stationIndex(with targetId: String, with stations: [StationByRouteListDTO]) -> Int?
func filteredStations(from stations: [StationByRouteListDTO]) -> (stations: [StationInfo], time: Int)
}

final class MovingStatusCalculateUseCase: MovingStatusCalculatable {

func filteredBuses(from buses: [BusPosByRtidDTO], startOrd: Int, currentOrd: Int, count: Int) -> [BusPosByRtidDTO] {
Expand Down
14 changes: 14 additions & 0 deletions BBus/BBus/Foreground/Search/UseCase/SearchAPIUsable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// SearchAPIUsable.swift
// BBus
//
// Created by 최수정 on 2021/12/01.
//

import Foundation
import Combine

protocol SearchAPIUsable: BaseUseCase {
func loadBusRouteList() -> AnyPublisher<[BusRouteDTO], Error>
func loadStationList() -> AnyPublisher<[StationDTO], Error>
}
5 changes: 0 additions & 5 deletions BBus/BBus/Foreground/Search/UseCase/SearchAPIUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
import Foundation
import Combine

protocol SearchAPIUsable: BaseUseCase {
func loadBusRouteList() -> AnyPublisher<[BusRouteDTO], Error>
func loadStationList() -> AnyPublisher<[StationDTO], Error>
}

final class SearchAPIUseCase: SearchAPIUsable {

private let useCases: GetRouteListUsable & GetStationListUsable
Expand Down
13 changes: 13 additions & 0 deletions BBus/BBus/Foreground/Search/UseCase/SearchCalculatable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// SearchCalculatable.swift
// BBus
//
// Created by 최수정 on 2021/12/01.
//

import Foundation

protocol SearchCalculatable {
func searchBus(by keyword: String, at routeList: [BusRouteDTO]) -> [BusSearchResult]
func searchStation(by keyword: String, at stationList: [StationDTO]) -> [StationSearchResult]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@

import Foundation

protocol SearchCalculatable {
func searchBus(by keyword: String, at routeList: [BusRouteDTO]) -> [BusSearchResult]
func searchStation(by keyword: String, at stationList: [StationDTO]) -> [StationSearchResult]
}

final class SearchCalculateUseCase: SearchCalculatable {
func searchBus(by keyword: String, at routeList: [BusRouteDTO]) -> [BusSearchResult] {
if keyword.isEmpty {
Expand Down
18 changes: 18 additions & 0 deletions BBus/BBus/Foreground/Station/UseCase/StationAPIUsable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// StationAPIUsable.swift
// BBus
//
// Created by 최수정 on 2021/12/01.
//

import Foundation
import Combine

protocol StationAPIUsable: BaseUseCase {
func loadStationList() -> AnyPublisher<[StationDTO], Error>
func refreshInfo(about arsId: String) -> AnyPublisher<[StationByUidItemDTO], Error>
func add(favoriteItem: FavoriteItemDTO) -> AnyPublisher<Data, Error>
func remove(favoriteItem: FavoriteItemDTO) -> AnyPublisher<Data, Error>
func getFavoriteItems() -> AnyPublisher<[FavoriteItemDTO], Error>
func loadRoute() -> AnyPublisher<[BusRouteDTO], Error>
}
9 changes: 0 additions & 9 deletions BBus/BBus/Foreground/Station/UseCase/StationAPIUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@
import Foundation
import Combine

protocol StationAPIUsable: BaseUseCase {
func loadStationList() -> AnyPublisher<[StationDTO], Error>
func refreshInfo(about arsId: String) -> AnyPublisher<[StationByUidItemDTO], Error>
func add(favoriteItem: FavoriteItemDTO) -> AnyPublisher<Data, Error>
func remove(favoriteItem: FavoriteItemDTO) -> AnyPublisher<Data, Error>
func getFavoriteItems() -> AnyPublisher<[FavoriteItemDTO], Error>
func loadRoute() -> AnyPublisher<[BusRouteDTO], Error>
}

final class StationAPIUseCase: StationAPIUsable {
typealias StationUseCases = GetStationByUidItemUsable & GetStationListUsable & CreateFavoriteItemUsable & DeleteFavoriteItemUsable & GetFavoriteItemListUsable & GetRouteListUsable

Expand Down
12 changes: 12 additions & 0 deletions BBus/BBus/Foreground/Station/UseCase/StationCalculatable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// StationCalculatable.swift
// BBus
//
// Created by 최수정 on 2021/12/01.
//

import Foundation

protocol StationCalculatable: BaseUseCase {
func findStation(in stations: [StationDTO], with arsId: String) -> StationDTO?
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@

import Foundation

protocol StationCalculatable: BaseUseCase {
func findStation(in stations: [StationDTO], with arsId: String) -> StationDTO?
}

final class StationCalculateUseCase: StationCalculatable {
func findStation(in stations: [StationDTO], with arsId: String) -> StationDTO? {
let station = stations.filter() { $0.arsID == arsId }
Expand Down
24 changes: 0 additions & 24 deletions BBus/BBus/Global/DTO/BusPosByVehicleIdDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,6 @@

import Foundation

struct JsonHeader: Codable {
let msgHeader: MessageHeader
}

struct JsonMessage<T: Codable>: Codable {
let msgHeader: MessageHeader
let msgBody: MessageBody<T>
}

struct MessageHeader: Codable {
let headerMessage, headerCD: String
let itemCount: Int

enum CodingKeys: String, CodingKey {
case headerMessage = "headerMsg"
case headerCD = "headerCd"
case itemCount
}
}

struct MessageBody<T: Codable>: Codable {
let itemList: [T]
}

struct BusPosByVehicleIdDTO: Codable {

let stationOrd: String
Expand Down
32 changes: 32 additions & 0 deletions BBus/BBus/Global/DTO/JsonDTO.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// JsonDTO.swift
// BBus
//
// Created by 최수정 on 2021/12/01.
//

import Foundation

struct JsonHeader: Codable {
let msgHeader: MessageHeader
}

struct JsonMessage<T: Codable>: Codable {
let msgHeader: MessageHeader
let msgBody: MessageBody<T>
}

struct MessageHeader: Codable {
let headerMessage, headerCD: String
let itemCount: Int

enum CodingKeys: String, CodingKey {
case headerMessage = "headerMsg"
case headerCD = "headerCd"
case itemCount
}
}

struct MessageBody<T: Codable>: Codable {
let itemList: [T]
}
Loading

0 comments on commit 8546bf7

Please sign in to comment.