Created
June 18, 2021 18:29
-
-
Save JaniKibichi/12543ce43b7588d326e3ce3b86db360f to your computer and use it in GitHub Desktop.
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
package com.janikibichi.firstore | |
object LanguageStoreProtocol{ | |
def props(randomId:String):Props = Props(new LanguageStoreActor(randomId:String)) | |
// WE CAN ONLY USE THIS ACTOR TO STORE NEW MENUS, TO FETCH WE EITHER FETCH MENU CONTENT OR MENU OPTIONS FROM RESPECTIVE ACTORS | |
final case class LanguageStore(language: String, menucontent: List[MenuContent],menuoptions: List[MenuOptions]) | |
final case class StoreMenus(languageMenu: LanguageMenu) | |
} | |
class LanguageStoreActor(randomId:String) extends Actor with ActorLogging{ | |
def receive: Receive = { | |
case StoreMenus(languageMenu: LanguageMenu) => | |
// STORE MENU CONTENT | |
for(content <- languageMenu.menucontent)yield{ | |
// CREATE A REFERENCE | |
val menuDocRef: DocumentReference = FireStoreConfig.database.collection("MenuContent").document() | |
val menuMap = Map( | |
"title"->menu.title, | |
"body"->menu.body, | |
"state"->menu.state, | |
"language"->menu.language | |
) | |
// ASYNCHRONOUSLY WRITE DATA | |
val writtenResult: ApiFuture[WriteResult] = menuDocRef.set(menuMap.asJava, SetOptions.merge()) | |
} | |
// STORE MENU OPTIONS | |
for(option <- languageMenu.menuoptions)yield{ | |
// CREATE A REFERENCE | |
val menuDocRef: DocumentReference = FireStoreConfig.database.collection("MenuOption").document() | |
val menuMap = Map( | |
"state" -> opt.state, | |
"option1" -> opt.option1, | |
"option2" -> opt.option2, | |
"option3" -> opt.option3, | |
"option4" -> opt.option4, | |
"option5" -> opt.option5, | |
"option6" -> opt.option6, | |
"language" -> opt.language, | |
) | |
// ASYNCHRONOUSLY WRITE DATA | |
val writtenResult: ApiFuture[WriteResult] = menuDocRef.set(menuMap.asJava, SetOptions.merge()) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment