-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Week4 코드 프리징
- Loading branch information
Showing
111 changed files
with
3,136 additions
and
793 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// Array+Extension.swift | ||
// Escaper | ||
// | ||
// Created by 최완식 on 2021/11/18. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Array { | ||
var isNotEmpty: Bool { | ||
return !self.isEmpty | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// ViewType.swift | ||
// Escaper | ||
// | ||
// Created by shinheeRo on 2021/11/16. | ||
// | ||
|
||
import Foundation | ||
|
||
enum ViewType { | ||
case email | ||
case password | ||
case passwordCheck | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// | ||
// DataInjection.swift | ||
// Escaper | ||
// | ||
// Created by 최완식 on 2021/11/17. | ||
// | ||
|
||
import Foundation | ||
import CoreLocation | ||
import Firebase | ||
|
||
class DataInjection { | ||
static let shared = DataInjection() | ||
private init() {} | ||
|
||
func run(storeRegion: StoreRegion) { | ||
guard let json = self.readLocalFile(location: storeRegion), | ||
let injectionDTO = self.decode(from: json) else { return } | ||
|
||
var roomId = storeRegion.code | ||
|
||
injectionDTO.stores.forEach { storeInjectionDTO in | ||
|
||
var roomIds = [String]() | ||
let geocoder = CLGeocoder() | ||
let locale = Locale(identifier: "Ko-kr") | ||
|
||
let genres = storeInjectionDTO.rooms.map({ Genre(rawValue: $0.genre) }).compactMap({ $0 }) | ||
if genres.isEmpty { return } // 특정 업체가 가지고 있는 방의 장르가 우리가 가지고 있는 장르에 해당하는 것이 하나도 없을 경우 다음 업체를 봐야 함 | ||
|
||
geocoder.geocodeAddressString(storeInjectionDTO.address, in: nil, preferredLocale: locale) { placemarks, error in | ||
if let error = error { | ||
print(error.localizedDescription) | ||
} | ||
guard let placemark = placemarks?.first else { return } | ||
|
||
let geoLocation = GeoLocation(latitude: (placemark.location?.coordinate.latitude)!, longitude: (placemark.location?.coordinate.longitude)!) | ||
let district = storeInjectionDTO.address.components(separatedBy: " ")[1] | ||
|
||
storeInjectionDTO.rooms.forEach { room in | ||
|
||
if Genre(rawValue: room.genre) == nil { return } // 없는 genre의 데이터가 있을 경우 다음 방으로 넘어감 | ||
|
||
roomId += 1 | ||
roomIds.append("\(roomId)") | ||
|
||
let roomDTO = RoomDTO(roomId: "\(roomId)", | ||
title: room.title, | ||
storeName: storeInjectionDTO.storeName, | ||
difficulty: room.difficulty, | ||
genre: room.genre, | ||
geoLocation: geoLocation, | ||
district: district, | ||
records: []) | ||
|
||
FirebaseService.shared.addRoom(room: roomDTO) | ||
} | ||
|
||
let storeDTO = StoreDTO(name: storeInjectionDTO.storeName, | ||
homePage: storeInjectionDTO.homepage, | ||
telephone: storeInjectionDTO.telephone, | ||
address: storeInjectionDTO.address, | ||
region: storeRegion.engName, | ||
geoLocation: geoLocation, | ||
district: district, | ||
roomIds: roomIds) | ||
|
||
FirebaseService.shared.addStore(store: storeDTO) | ||
} | ||
} | ||
|
||
} | ||
|
||
private func readLocalFile(location: StoreRegion) -> Data? { | ||
do { | ||
if let bundlePath = Bundle.main.path(forResource: location.engName, ofType: "json"), | ||
let jsonData = try String(contentsOfFile: bundlePath).data(using: .utf8) { | ||
return jsonData | ||
} | ||
} catch { | ||
print(error) | ||
} | ||
return nil | ||
} | ||
|
||
private func decode(from data: Data) -> InjectionDTO? { | ||
return try? JSONDecoder().decode(InjectionDTO.self, from: data) | ||
} | ||
} | ||
|
||
extension FirebaseService { | ||
func addRoom(room: RoomDTO) { | ||
if FirebaseApp.app() == nil { | ||
FirebaseApp.configure() | ||
} | ||
let database = Firestore.firestore() | ||
let path = database.collection(Collection.rooms.value).document("\(room.roomId)") | ||
path.setData(room.toDictionary()) | ||
} | ||
|
||
func addStore(store: StoreDTO) { | ||
if FirebaseApp.app() == nil { | ||
FirebaseApp.configure() | ||
} | ||
let database = Firestore.firestore() | ||
let path = database.collection(Collection.stores.value).document("\(store.district)_\(store.name)") | ||
path.setData(store.toDictionary()) | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// InjectionDTOs.swift | ||
// Escaper | ||
// | ||
// Created by 최완식 on 2021/11/17. | ||
// | ||
|
||
import Foundation | ||
|
||
struct InjectionDTO: Codable { | ||
let stores: [StoreInjectionDTO] | ||
} | ||
|
||
struct StoreInjectionDTO: Codable { | ||
let storeName, telephone: String | ||
let homepage: String | ||
let address: String | ||
let rooms: [RoomInjectionDTO] | ||
} | ||
|
||
struct RoomInjectionDTO: Codable { | ||
let title, genre: String | ||
let difficulty: Int | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.