We'regoingtobecreatingthissearchbookspage, whichisgoingtohave a titlepublishedafterandpublishedbeforeFieldthatwecansearchbyaswellasit'lllistsallthebooksdownherethatmatchedthatsearch.
Also, we'regoingtohaveanadbookpagewhichwillallowustoadd a titleto a bookandauthor, whichweselectfrom a listofauthorsthatwe'vealreadycreated.
Wecanselect a published A Herewecanselectpagecountwilljuststay 200 forexample.
Weselectwhichbookcoverthatwewanttouse, andwecanadd a description, yourbook, andthenwecanhit, create, andthatwillbringusbacktothisbookpagewhere, asyoucansee, wecouldseethetitleofourbookhereandwecansearch.
Andthereasonwe'rehaving a createdatdateisbecauseinsideofourapplication, ourmainpageisgoingtoshowallofourrecentlyaddedbooksinorderfromwhenthemostrecentonetotheleastrecentone.
Soweneed a dateatwhichthesebookswereaddedtotheapplication.
Soweknowwhichbookswerecreatedwhenthisisgoingtobe, ofcourse, ofthetypedate, andwewanttorequirethis, obviouslyAndalso, wewanttosetthisto a defaultvalue.
Wealwaysjustwanttosetthistothecurrentdate.
SowecanjustsaydatedotnowAndthiswillsetthecreatorthatdatetothecurrentdateeverytimethatwecreateanobjectsowedon't havetomanuallysetthiseverytimewecreate a book.
Next, eachbookisgoingtohave a coverimage, andinsteadofactuallypassingintheimageitselfintothedatabase, we'redisappointedpastthenameoftheimagesowecanrestore a singlesmallstring, andthenwecouldstoretheactualimageitselfonourserverinthefinalsystem.
Sinceyoualwayswant a storefilesinthefilesystem, whenyoucan, we'regonnaputthisas a typeofstrengthandwe'realsogoingtoberequiredtrueforthis, thenlastly, asweallknow, everybookhasanauthor, soweneedtosetanauthortypeforourobject.
Andthisisgoingtobe a littlebitdifferentbecausewewanttoactuallyreferencetheauthorfromourauthorscollectionthatwecreatedoverhere.
Soinsteadofputtingthetypeheretobesomekindofauthortypeor I d typewe'regoingtobeusingthemongoosedotschemadottypesdotobject i d.
SonowwearehaveallofourbookdroughtsinhereanddownherewecantellourroutethatwewantallofourslashbooksroutestoGoto, ourbookwriterthatwecreatedlookslike a spellthatherewego.
Butif a userhasalreadyselectedanauthor, wewanttosetthatoptionasselected.
Sowe'regoingtocreateanifstatementhere.
ThisifstatementisgoingtosaythatiftheauthordiDiisequaltothebookdotauthorandrememberthereasonwe'redoingbookedoutauthorhereinsteadofbookedoutauthor, that I d isbecausethisauthorfieldisactually I d.
Ifyouremember, insteadofourmodel, thisis a I d object.
Soourauthorisactually I d oftheauthorinsideofourbook, sowecanchecktomakesurethatthe I d oftheauthorisequaltotheauthorofthebook I D.
Andifso, thisisgoingtobeourselectedvalue.
Sothisoptionhere, we'lljustsetittobeselective.
Youjustputtheselectedattributeonyouroption, andnowthisis a selectedoption.
Butif, forexample, thisauthorideaisnotthatsowe'llputan l statementhere.