Skip to content

Commit

Permalink
Merge pull request #156 from EAT-SSU/refactor/#61
Browse files Browse the repository at this point in the history
[#61] enum ๊ฐ’์„ ํ†ตํ•œ ์‹๋‹น ๊ด€๋ฆฌ ๋ฐ ๋ฐฉํ•™์—ฌ๋ถ€ ํ™•์ธํ•˜์—ฌ isVacation ์ ์šฉ
  • Loading branch information
CJiu01 authored Nov 9, 2024
2 parents 1e6b25a + dffb1c4 commit 64ef13c
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Firebase
class FirebaseRemoteConfig {
static let shared = FirebaseRemoteConfig()
var remoteConfig: RemoteConfig
var isVacationPeriod = false

private init() {
remoteConfig = RemoteConfig.remoteConfig()
Expand Down Expand Up @@ -59,7 +60,7 @@ class FirebaseRemoteConfig {

func fetchRestaurantInfo() {
// 1. fetch
remoteConfig.fetch() { (status, error) -> Void in
remoteConfig.fetch(withExpirationDuration: 0) { (status, error) -> Void in
if status == .success {
// 2. activate: ์ปจํ”ผ๊ทธ ๊ฐ’ ๊ฐ€์ ธ์˜ด
self.remoteConfig.activate()
Expand All @@ -83,4 +84,17 @@ class FirebaseRemoteConfig {
}
}
}

func fetchIsVacationPeriod() {
remoteConfig.fetch(withExpirationDuration: 0) { (status, error) -> Void in
if status == .success {
self.remoteConfig.activate()

self.isVacationPeriod = self.remoteConfig["isVacationPeriod"].boolValue
print("Is vacation period: \(self.isVacationPeriod)")
} else {
print("Error: \(error?.localizedDescription ?? "Unknown error")")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ final class LoginViewController: BaseViewController {
// MARK: - Properties

var loginAfterlooking = true
static public let isVacationPeriod = false

// MARK: - UI Components

Expand Down Expand Up @@ -66,6 +67,8 @@ final class LoginViewController: BaseViewController {
}

private func setFirebaseTask() {
FirebaseRemoteConfig.shared.fetchIsVacationPeriod()

#if DEBUG
#else
Analytics.logEvent("LoginViewControllerLoad", parameters: nil)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// RestaurantType.swift
// EATSSU
//
// Created by ์ตœ์ง€์šฐ on 11/8/24.
//

import Foundation

enum RestaurantType {
case change
case fix
}

enum Restaurant {
case dodamRestaurant
case dormitoryRestaurant
case studentRestaurant
case snackCorner

var type: RestaurantType {
switch self {
case .dodamRestaurant, .dormitoryRestaurant, .studentRestaurant:
return .change
case .snackCorner:
return .fix
}
}

var identifier: String {
switch self {
case .dodamRestaurant:
return "DODAM"
case .dormitoryRestaurant:
return "DORMITORY"
case .studentRestaurant:
return "HAKSIK"
case .snackCorner:
return "SNACK_CORNER"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,37 +107,37 @@ final class HomeRestaurantViewController: BaseViewController {
}

func getSectionIndex(for restaurant: String) -> Int? {
let restaurantRawValue = [TextLiteral.dormitoryRawValue,
TextLiteral.dodamRawValue,
TextLiteral.studentRestaurantRawValue,
TextLiteral.snackCornerRawValue]
let restaurantRawValue = [Restaurant.dormitoryRestaurant.identifier,
Restaurant.dodamRestaurant.identifier,
Restaurant.studentRestaurant.identifier,
Restaurant.snackCorner.identifier]
return restaurantRawValue.firstIndex(of: restaurant)
}

func getSectionKey(for section: Int) -> String {
let restaurantRawValue = [TextLiteral.dormitoryRawValue,
TextLiteral.dodamRawValue,
TextLiteral.studentRestaurantRawValue,
TextLiteral.snackCornerRawValue]
let restaurantRawValue = [Restaurant.dormitoryRestaurant.identifier,
Restaurant.dodamRestaurant.identifier,
Restaurant.studentRestaurant.identifier,
Restaurant.snackCorner.identifier]
return restaurantRawValue[section]
}

func fetchData(date: Date, time: String) {
let formatDate = changeDateFormat(date: date)
getChageMenuData(date: formatDate, restaurant: TextLiteral.dormitoryRawValue, time: time) {}
getChageMenuData(date: formatDate, restaurant: TextLiteral.dodamRawValue, time: time) {}
getChageMenuData(date: formatDate, restaurant: TextLiteral.studentRestaurantRawValue, time: time) {}
getChageMenuData(date: formatDate, restaurant: Restaurant.dormitoryRestaurant.identifier, time: time) {}
getChageMenuData(date: formatDate, restaurant: Restaurant.dodamRestaurant.identifier, time: time) {}
getChageMenuData(date: formatDate, restaurant: Restaurant.studentRestaurant.identifier, time: time) {}

let weekday = Weekday.from(date: date)
isWeekend = weekday.isWeekend

if time == TextLiteral.lunchRawValue {

if !weekday.isWeekend {
if !FirebaseRemoteConfig.shared.isVacationPeriod && !weekday.isWeekend {
getFixMenuData(restaurant: TextLiteral.snackCornerRawValue) {}
} else {
currentRestaurant = TextLiteral.snackCornerRawValue
self.fixMenuTableViewData[TextLiteral.snackCornerRawValue] = [MenuInformation(menuId: 0, name: "", mainRating: nil, price: nil)]
currentRestaurant = Restaurant.snackCorner.identifier
self.fixMenuTableViewData[Restaurant.snackCorner.identifier] = [MenuInformation(menuId: 0, name: "", mainRating: nil, price: nil)]
}
}
}
Expand Down

0 comments on commit 64ef13c

Please sign in to comment.