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.
Now, ifwesavethatandrefreshourpagehere, you'llseethatwecouldn't air.
That's because I accidentallyputthisslashattheverybeginningheresowecouldjustremovethatwesaveourpageandrefresh, andyou'llseethatwegetourtitlebeingcreatedhere, aswellas a listofauthorsinsideofherapplication.
Wesplititonthatteaandwejustgetthefirstsectionofthatstringwhichwillgetusthisdatesectionsinceweonlywant a dateandoutoftime.
Sonowthatwehavethatalldone, thiswillactuallypopulateourpublished a fieldforusanditwouldbesafer.
Refresh.
Overherewehaveourpublisheddatefieldshowinguprighthereandisdefaultedtonothingfornowbecausethere's actuallynovalueforpublisheddatebecauseitisnotomakethisform a littlebiteasiertoworkwithaddicts.
Fieldswerealsojustgoingtoput a quickminimumvalueonhere, whichisgoingtobeequaltoonebecausewecouldneverhave a bookthat's lessthanonepageslong.
Now I canmoveontoourlasttwosections, thefirstofwhichisgoingtobeourcoversowecanchangepagecountheretobecover, andinsteadofputtingournameheretobecoverimagenamebecausethisiswhatthevariableisourmodel, thisisn't actuallygoingtobethenameoftheimage.
Wealsowanttochangethetypehere, tobefiledinsteadofnumberremovedtheminimumandalso, unfortunately, fileinputsdon't allowyoutoset a defaultvalue.
Sowehavetoremovethevaluefieldaswell.
Andthisisjustalwaysbe a blankfileandputthatwecanalwaysaddtonow.
Lastly, wewanttoaddinthedescription.
Sochangethisdescriptionanddescriptionis a bitdifferentbecausethisis a largetextTerry, asyoucansee, whichsupportsusbeingabletousetheenterkeyaswellasotherkeysinsideofhere.
Butyoucan't useinsideof a normaltextinput, soweneedtousewhat's called a textarea.
Sosaidthistobe a textareaasopposedto a inputoftypetext, andthetextareaalsoneeds a closingtagoftextareabecausethisiswhereallthetextforyourtext.
Terryisgoingtogo.
Wealsowanttosetthenamehere.
Sothenameforthisisjustgoingtobe a description.
Andtheninsteadofhaving a valuepropertyontextarea, weactuallyneedtoputthevalueinsideofthetextareahere.
Sowhatwe'lldoiswe'lljusthavethis'llvalueinsteadofherewillsaybookdotdescriptionisthevaluefor a textfieldandeverygoatthat's goingtohavealltheinformationinsideofherethatwewant.
Nowifwegooverthere, Pidge, refreshthisandzoomin a littlebit, soit's easytosee.
Yousee, wehaveourtitle.
Authorpublished a pagecount, whichis a numberfieldthatcan't bedroppedbelowone.
Soinsideofourwrapsfileherewecouldgodowntoourgreatbookcrapandinhereiswhereweneedtosetupallthelogicforcreatingourbook, whichisgoingtoworksomewhatsimilarlytohowwedidthisforauthorsagainisgoingtobe a synchronous, aswasmentionedinthefunctiondefinitionherebecausewe'regoingtobeusingmongersandawaitinginsteadofusingcallbacks.
Butinsteadofdefaultingittonothing, wewanttoactuallysetallofourdifferentpropertiesfor a book.
The 1st 1 isgoingtobeourtitle.
WhatisgoingtocomefromtheriplessnotbodyDOTtitlethenwe'regoingtodotodayisexcellentfortheauthorauthorofourbookisgoingtobe a requestthatBodyDocauthor I wish, Dave, it's goingtobeagainexactlythesamehereexceptforweneedtowrapthisinsideofnewdatebecausethisrequestourbodyaboutpublisheddateisactuallygoingtoreturntoUSstring.
Soweneedtoconvertthatstrengthinto a dateusing a newdatefunctionhere, whichwillgiveusanactualdatewecanstoreonherdatabaseandthenwecandothepagecount.
Theeasiestwayforustodothatistouse a librarycalledMoulter.
Sowhat's installthatlibrarywould'vestillin P.
M.
I moulterandmultipleallowsustoworkwithmultipartforms, whichiswhat a fileformisalso, Inordertousefiles, weneedtochangeourforminsideofourviewpageheretobeofthetypeofmultipartform.
Inordertodothat, weneedtosetthe E and C typetobeequaltomultipartformdata, soslashformdata.
Andthistellsourserverthatourformisgoingtobesendingmultipartdata, whichcouldinclude a file.
Wejustwanttocallthatcallbackfunctionfirstpermitwewanttosenditisjustgoingtobeno, sincewehavenoerrorbecausethisisaneverperimeterandthesecondoptionisgoingtobe a boolean.
Thatsays, true, ifthefileisacceptedorfalse, ifthefirewasnotacceptedandallwewanttodoisacceptimagefiles, sowewanttosetup a variablehere, we'regonnacallthis a imagemindtypesvariable, andthisisjustgoingtobein a rapethathasallofthedifferentimagetypesthatweaccept.
WewantittojointotheuploadpathwhichshouldgiveuspublicupwardsbookcoversandwewanttocombinethatfilenameontotheendoftheuploadpathSothisisgoingtogetridofanyfilethathasthefinalnameinsideofthisbookcoversfolderhere, andthisisgoingtotakehere a functionwhichwillhaveanArabparameter.
Wewantthistobe a datewiththenameofpublishedafter, andwewantourvaluetocomefromthatpublishedaftervariableandifyourememberrightinourformfieldshere, wehadtodo a bunchoffancylogictoconvertthingsto a niceohStringbecausefromourdatabase, thispublisheddatecameout a littlebitdifferentlyformattedthanweactuallywantit.
Wewanttocallthiscoverimagehalfandthenwhichwantedtofind a dog, getfunctionforit.
Sowecansaywhenwecallbookdotcoverimagepath, it's goingtocallthisgetfunctionhere, andwe'lljustpassthisin a functionandit's thatdysfunctionwe'reactuallyordertofindhowwegetthat.
Andthereasonwe'reusing a normalfunctionhereinsteadofanairoffunctionisbecauseweneedtohaveaccesstothethisproperty, whichisgoingtobelinkedtotheactualbookitself.
Somakesureyouuse a functionhereandnotanarrowfunction, andthefirstthingwe'regonnadowewanttocheckifthisbookactuallyhas a coverimageappliedtoitsowecansit, coverimage, nameisnotequaltoknow.
Soifthereis a coverimage, thenweactuallywanttoreturnthepathwhichleadstothisbook.
Soinordertodebugthis, wejustbookedbackwherebooksvariablestofindandyounotice I forgottoincludetheawaitkeywordherewhichisincrediblyimportanttoputthisawake.
Andiftherequestqueriadottaleisnotequaltoanemptystring, thenweknowthattheyactuallypassed a titletothispage, andwecanactuallycheckandrenderthistitleinsideofourquery.
Sowecansaythatwewantourquerytobeequaltoourquery.
Essentially, thisisjust a pendingontoourquery, dierejects, andweusethisregularexpressioninourearlierexamplewiththeauthors.
Sothisisgoingtobeverysimilar.
Wewanttocheckonthetitleofourbook.
Thisisourdatabasemodelparameter.
SothisisgonnabethebookdottitleobjectofanRV, Davies, andthenwewanttocreate a newregularexpression.
Soreplacedotquerydottitleandwegetpastthe I flag, whichjustsaysthatwedon't careiftheytypedin a capital s orlowercase s isgoingtobetreatedexactlythesame.
Solet's dothatnow, firstthingthatweneedtodoiscopythisdownandpasteithere, andwejustwanttochange a fewthingswewanttocheckfirstforpublishedbeforewewanttodothisagaintomakesurethepublishedbeforeisnotequaltoanempty A string.
Sothismeansthatwehave a publishedbeforevariable, andinsteadofdoing a rejectshere, we'regoingtodo a lessthansowe'llsaythatourqueryisgoingtobeequaltoqueryGotlessthanorequalto.
Thisisthesametexthere.
ForthatwehaveltforWestonandthen e forequaltoWepassitinthefieldinourdatabase.