[SOLVED] 程序代写代做代考 database js Microsoft Word – Document5

30 $

File Name: 程序代写代做代考_database_js_Microsoft_Word_–_Document5.zip
File Size: 612.3 KB

SKU: 0699727199 Category: Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Or Upload Your Assignment Here:


Microsoft Word – Document5

LearningOutcome
Bytheendofthisexercise,youwillfurtherdevelopyourskills
inbuildingAPIs,andbuildingonyourunderstandingofREST.

Prerequisites
YouwillbebuildingonwhatyouhadfromExercise5,
continuingtouseSequelizetoprogrammaticallyinteractwith
yourdatabase.
Ifyouhaven’tdoneExercise5,pleaseseetheprerequisites
fromthatexercise.

GettingStarted
YouwillbebuildingontopofwhatyouhadfromExercise5.
JustlikeinExercise5,you’llneedtoinstalltheSequelize
package.YoucanfindthatinformationontheGettingStarted
sectionofExercise5.

Task
Inyourpreviousassignment,youupdatedyourGETrequests
tointeractwithyourdatabaseviaSequelize,butyoudidn’t
updatethePOSTs.We’llexpandonthistogetyourMusicApp
tobefullyoperationalagain,exceptwe’llbechangingtheAPIs
upandaddingafewnewones.
InExercise3whenyoubuiltyourPOST/api/playlistsAPI,
ittookcareofany“Update”inyourapplication(addinganew
playlist,oraddingsongstoaplaylist).Thatwasnotaverygood
wayofbuildingAPIs(remember,I’mteachingyouthebad
waysofdoingthingsandsoyouunderstandwhythegood
waysaregood!).Itwasn’tgoodbecause:
Theysendfartoomuchdataforeverychange(whysend

alltheplaylistdatawhenyoucouldjustsendwhichsong
you’readdingtowhichplaylist?).

TheyarenotRESTful.
Withthefollowingtasks,we’llmakeourAPIrequestsmore

efficient,moreRESTful,andfunctionalusingtheORM.
AddingSongstoPlaylists
Inexercise3,youpersistedplaylistdatatodiskbysendingall
ofthePlaylistdataviaaPOSTto/api/playlists.Insteadwe
willcreateaAPIsspecificallyforaddingsongstoplaylists.
ThefollowingtwoAPIrequestsdescribedbothsolvethisina
betterway.Youcanimplement*eitherone*(bothdescribed
justtohelpwithyourunderstandingofPUTvsPOST).
PUT/API/PLAYLISTS/:ID
PUTisusedwhenyouwanttoupdateanexistingresource.But
whenusingaPUT,youshouldalsobeprovidingallthe
informationnecessary,becauseitwillreplacetheentire
resource.Remember–PUTsshouldbeidempotent,meaningif
youkeepissuingaPUTrequestrepeatedly,onlythefirst
requestshouldactuallychangeanystateinyourdatabase.
ThebodyofthePUTrequestshouldbethe_entire_listofsongs
(notjusttheonebeingadded).Forexample,ifyouwereadding
song64toaplaylistwithsongs8,16,and32,yourrequest
wouldlooklikethis:
PUT/api/playlists/4

{
name:“SomeAwesomePlaylist”,
songs:[8,16,32,64]
}

TheresultisthatyourPlaylist#4shouldcontainsongs8,16,
32and64.Don’tworryaboutdealingwithinvalidPOSTbody
dataforthisexercise.Theresponseshouldbea200.
Ontheserveryou’deitherdeleteallofthesongsintheplaylist
andthenaddthenewones,oryou’ddoadifftoseewhat
changedandperformthenecessaryoperationstoadd/remove
basedonthatdiff.Howyouimplementthisisuptoyou.
Butthisisalsonotveryefficientinourcase,becausewe’renot

doinganybulkoperations(itcouldbeusefulifyourUIdidn’t
persistsongsuntilyoupress“Save”though!).
SohereisanotherAPIthatfitsourusecaseabitbetter:
POST/API/PLAYLISTS/:ID
Butyoumightsay“Wait,IthoughtweshouldonlyusePOSTfor
create?”.Whileit’struethatPOSTistheonlyHTTPmethodyou
shouldusewhencreatingaresource,itdoesn’tmeanyoucan’t
useitforupdates.It’salsousedwhenyouwanttomakean
updatethatisnon-idempotent,whichwearedoinginthiscase
(asdoingthefollowingPOSTwouldupdatethestateofthe
serverbycontinuouslyaddingthissongoverandover).
Anexamplerequesttoaddsong64toaplaylistwith8,16,and
32wouldlooklike:
POST/api/playlists/4

{
song:64
}
Thisshouldaddsong64toplaylist4.Don’tworryabout
dealingwithinvalidPOSTbodydataforthisexercise.The
responseshouldbea200.
UPDATINGAPPLOGIC
YoushouldalsoupdateyourMusicAppJSlogictocalloneof
thesetwomethods(insteadofusingPOST/api/playlists
whichwasthecasefromExercise3).Whichoneyouchooseis
uptoyou,andnoitdoesn’tmatterforyourmarks.
CreatingnewPlaylists
Inexercise3,youpersistednewPlayliststhroughthesameAPI
asaddingsongs(POST/api/playlists).We’llkeep
/api/playlists,butthistimeit’llstrictlybeusedtocreate
newplaylists.
POST/API/PLAYLISTS
Whencreatinganewplaylist,itshouldaccepta“name”
parameterinthebodylikeso:

POST/api/playlists

{
“name”:“Secondgreatestplaylist”
}

Don’tworryabouthandlinginvalidPOSTbodydatainthe
request.Theresponseshouldcontaina200,andtheidand
nameofthenewplaylist:
{
id:101
name:“Sendgreatestplaylist”
}
UPDATE.It’salsofineiftheresponsecontainsaJSONresponse
containinganemptyarrayofsongs:
{
id:101
name:“Sendgreatestplaylist”,
songs:[]
}
UPDATINGAPPLOGIC
Whenyougetaresponsebackfromtheserver,addthenew
playlisttoyourMUSIC_DATAin-memorystateobject,and
updateyourUIwiththenewplaylist.
(interestingtidbit:youcouldaddittotheUIrightaway,doing
sowouldmeanbuildingaOptimisticUI]),butyoualsohaveto
dealwithwhathappensiftheserveractuallyendsuprejecting
yourrequest).
Removingasongfromaplaylist
DELETE/API/PLAYLISTS/:ID/
ThebodyoftheDELETErequestshouldcontainthesongid
thatyouwanttoremovefromaparticularplaylist.For
example:
DELETE/api/playlists/:id

{
song:64
}
GenerallyDELETErequestsshouldbeidempotent,butsince
ourapplicationstatedoesn’tknowabouttheidsofthe
relationships(andIdon’tthinkitshould),we’llmakean
exceptionhere(RESTisnotaperfectscience????).
UPDATINGAPPLOGIC
Thisisnewfunctionalityyou’lladdtoyourUI–you’llbeadding
a“Remove”buttononthesongslistedwhenlookingatthe
songsintheplaylist.InyourUIforthatpage,addan“x”button
totherightofthe“+”button(usethesamexyouusedinthe
modaldismissal).
Whenclickingthe“x”,thesongshouldbea)removedfrom
memory,b)removedintheUI,andc)removefromtheDBviaa
calltoyourDELETEAPI.

Requirements
*One*ofPUT/api/playlists/:idorPOST

/api/playlists/:id,whichupdatesthePlaylistatid
withthecontentsoftherequestbody.(2mark)

“Addsongstoplaylist”inyourUIusesoneoftheabove
APIcalls.(1mark)

POST/api/playlistscreatesplaylistsandreturnsthe
playlistid.(2marks)

“CreatePlaylist”inyourUIusesyourupdatedPOST
/api/playlists.(1mark)

DELETE/api/playlists/:iddeletesthesongfrom
playlistidspecifiedinthebody.(2marks)

Add“Deletesongfromplaylist”functionalityinUI.(1
mark)

“Deletesongfromplaylist”inyourUIusesyourDELETE
APItopersistchanges.(1mark)

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] 程序代写代做代考 database js Microsoft Word – Document5
30 $