package Ġcom . had u ken . j apan . mar vel aac . data . source Ċ Ċ import Ġcom . had u ken . j apan . mar vel aac . data . database . Data Base Ċ import Ġcom . had u ken . j apan . mar vel aac . data . database . entity . Com ic Book Entity Ċ import Ġcom . had u ken . j apan . mar vel aac . data . database . entity . Com ic Creator Join Ċ import Ġcom . had u ken . j apan . mar vel aac . data . database . entity . Creator Entity Ċ import Ġcom . had u ken . j apan . mar vel aac . domain . model . Com ic Book Ċ import Ġcom . had u ken . j apan . mar vel aac . domain . model . Com ic Book Item Ċ import Ġcom . had u ken . j apan . mar vel aac . domain . model . to Com ic Book Ċ import Ġcom . had u ken . j apan . mar vel aac . domain . model . to Com ic Book Item Ċ Ċ class ĠData Base Com ic Source ( private Ġval Ġdata Base : ĠData Base ) Ġ: ĠData Com ic Book Source Ġ{ ĊĊĠĠĠ Ġoverride Ġfun Ġget Com ic Book ( com ic Id : ĠString ): ĠDataSource Response < Com ic Book > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcom ic Book Entity Ġ= Ġdata Base . com ic Book DAO (). getS inge Data ( com ic Id ) Ġ?: Ġreturn ĠDataSource Response . error () ĊĠĠĠĠĠĠĠ Ġval Ġcom ic Creator Join s Ġ= Ġdata Base . com ic Join s DAO (). getAll By Com ic Id ( com ic Id ) ĊĠĠĠĠĠĠĠ Ġval Ġcreator Entities Ġ= Ġdata Base . creator DAO (). get Creators By Primary Ids ( com ic Creator Join s . map Ġ{ Ġit . creator Primary Id Ġ}) ĊĠĠĠĠĠĠĠ Ġreturn ĠDataSource Response . success ( to Com ic Book ( com ic Book Entity , Ġcreator Entities )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġget Com ic Books (): ĠDataSource Response < List < Com ic Book >> Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcom ic Book Entities Ġ= Ġdata Base . com ic Book DAO (). getAll () ĊĠĠĠĠĠĠĠ Ġval Ġcom ic Creator Join s Ġ= Ġdata Base . com ic Join s DAO (). getAll By Com ic Ids ( com ic Book Entities . map Ġ{ Ġit . com ic Id Ġ}) ĊĠĠĠĠĠĠĠ Ġval Ġcreator Entities Ġ= Ġdata Base . creator DAO (). get Creators By Primary Ids ( com ic Creator Join s . map Ġ{ Ġit . creator Primary Id Ġ}) ĊĠĠĠĠĠĠĠ Ġreturn ĠDataSource Response . success ( com ic Book Entities . map Ġ{ Ġcom ic Entity Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġcreator Primary Ids Ġ= Ġcom ic Creator Join s . filter Ġ{ Ġit . com ic Primary Id Ġ== Ġcom ic Entity . com ic Id Ġ}. map Ġ{ Ġit . creator Primary Id Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġto Com ic Book ( com ic Entity , Ġcreator Entities . filter Ġ{ Ġcreator Primary Ids . contains ( it . creator Uri ) Ġ}) ĊĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġget Com ic Book Items (): ĠDataSource Response < List < Com ic Book Item >> Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcom ic Book Entity Ġ= Ġdata Base . com ic Book DAO (). getAll () ĊĠĠĠĠĠĠĠ Ġreturn ĠDataSource Response . success ( com ic Book Entity . map Ġ{ Ġto Com ic Book Item ( it ) Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġsave ( com ic Books : ĠList < Com ic Book >) Ġ{ ĊĠĠĠĠĠĠĠ Ġcom ic Books . forEach Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsave ( it ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġsave ( com ic Book : ĠCom ic Book ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġcom ic Entity Ġ= ĠCom ic Book Entity ( com ic Id Ġ= Ġcom ic Book . com ic Id , Ġtitle Ġ= Ġcom ic Book . title , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġdescription Ġ= Ġcom ic Book . description , Ġart Url Ġ= Ġcom ic Book . art Url ) ĊĠĠĠĠĠĠĠ Ġval Ġcreator Entities Ġ= Ġcom ic Book . cre ators . map Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠCreator Entity ( creator Uri Ġ= Ġit . creator Uri , Ġname Ġ= Ġit . name , Ġrole Ġ= Ġit . role ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġsave Com ic To Data Base ( com ic Entity , Ġcreator Entities ) ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġsave Com ic To Data Base ( com ic Entity : ĠCom ic Book Entity , Ġcreator Entities : ĠList < Creator Entity >) Ġ{ ĊĠĠĠĠĠĠĠ Ġdata Base . com ic Book DAO (). insert ( com ic Entity ) ĊĠĠĠĠĠĠĠ Ġcreator Entities . forEach Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdata Base . creator DAO (). insert ( it ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdata Base . com ic Join s DAO (). insert ( Com ic Creator Join ( com ic Entity . com ic Id , Ġit . creator Uri )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ }