Let's try to create a Home Library Service! Users
can create, read, update, delete data about Artists
, Tracks
and Albums
, add them to Favorites
in their own Home Library!
NB! You must create new repository from template for this task. Its name must be nodejs2022Q2-service i.e. full link to the repository must be https://github.com/%your-gihub-id%/nodejs2022Q2-service.
Create an application, the application should operate with the following resources:
-
User
(with attributes):interface User { id: string; // uuid v4 login: string; password: string; version: number; // integer number, increments on update createdAt: number; // timestamp of creation updatedAt: number; // timestamp of last update }
-
Artist
(with attributes):interface Artist { id: string; // uuid v4 name: string; grammy: boolean; }
-
Track
(with attributes):interface Track { id: string; // uuid v4 name: string; artistId: string | null; // refers to Artist albumId: string | null; // refers to Album duration: number; // integer number }
-
Album
(with attributes):interface Album { id: string; // uuid v4 name: string; year: number; artistId: string | null; // refers to Artist }
-
Favorites
(with attributes):interface Favorites { artists: string[]; // favorite artists ids albums: string[]; // favorite albums ids tracks: string[]; // favorite tracks ids }
Details:
- For
Users
,Artists
,Albums
,Tracks
andFavorites
REST endpoints with separate router paths should be created
-
Users
(/user
route)GET /user
- get all users- Server should answer with
status code
200 and all users records
- Server should answer with
GET /user/:id
- get single user by id- Server should answer with
status code
200 and and record withid === userId
if it exists - Server should answer with
status code
400 and corresponding message ifuserId
is invalid (notuuid
) - Server should answer with
status code
404 and corresponding message if record withid === userId
doesn't exist
- Server should answer with
POST /user
- create user (following DTO should be used)CreateUserDto
interface CreateUserDto { login: string; password: string; }
- Server should answer with
status code
201 and newly created record if request is valid - Server should answer with
status code
400 and corresponding message if requestbody
does not contain required fields
- Server should answer with
PUT /user/:id
- update user's passwordUpdatePasswordDto
(with attributes):interface UpdatePasswordDto { oldPassword: string; // previous password newPassword: string; // new password }
- Server should answer with
status code
200 and updated record if request is valid - Server should answer with
status code
400 and corresponding message ifuserId
is invalid (notuuid
) - Server should answer with
status code
404 and corresponding message if record withid === userId
doesn't exist - Server should answer with
status code
403 and corresponding message ifoldPassword
is wrong
- Server should answer with
DELETE /user/:id
- delete user- Server should answer with
status code
204 if the record is found and deleted - Server should answer with
status code
400 and corresponding message ifuserId
is invalid (notuuid
) - Server should answer with
status code
404 and corresponding message if record withid === userId
doesn't exist
- Server should answer with
-
Tracks
(/track
route)GET /track
- get all tracks- Server should answer with
status code
200 and all tracks records
- Server should answer with
GET /track/:id
- get single track by id- Server should answer with
status code
200 and and record withid === trackId
if it exists - Server should answer with
status code
400 and corresponding message iftrackId
is invalid (notuuid
) - Server should answer with
status code
404 and corresponding message if record withid === trackId
doesn't exist
- Server should answer with
POST /track
- create new track- Server should answer with
status code
201 and newly created record if request is valid - Server should answer with
status code
400 and corresponding message if requestbody
does not contain required fields
- Server should answer with
PUT /track/:id
- update track info- Server should answer with
status code
200 and updated record if request is valid - Server should answer with
status code
400 and corresponding message iftrackId
is invalid (notuuid
) - Server should answer with
status code
404 and corresponding message if record withid === trackId
doesn't exist
- Server should answer with
DELETE /track/:id
- delete track- Server should answer with
status code
204 if the record is found and deleted - Server should answer with
status code
400 and corresponding message iftrackId
is invalid (notuuid
) - Server should answer with
status code
404 and corresponding message if record withid === trackId
doesn't exist
- Server should answer with
-
Artists
(/artist
route)GET /artist
- get all artists- Server should answer with
status code
200 and all artists records
- Server should answer with
GET /artist/:id
- get single artist by id- Server should answer with
status code
200 and and record withid === artistId
if it exists - Server should answer with
status code
400 and corresponding message ifartistId
is invalid (notuuid
) - Server should answer with
status code
404 and corresponding message if record withid === artistId
doesn't exist
- Server should answer with
POST /artist
- create new artist- Server should answer with
status code
201 and newly created record if request is valid - Server should answer with
status code
400 and corresponding message if requestbody
does not contain required fields
- Server should answer with
PUT /artist/:id
- update artist info- Server should answer with
status code
200 and updated record if request is valid - Server should answer with
status code
400 and corresponding message ifartist
is invalid (notuuid
) - Server should answer with
status code
404 and corresponding message if record withid === artistId
doesn't exist
- Server should answer with
DELETE /artist/:id
- delete album- Server should answer with
status code
204 if the record is found and deleted - Server should answer with
status code
400 and corresponding message ifartistId
is invalid (notuuid
) - Server should answer with
status code
404 and corresponding message if record withid === artistId
doesn't exist
- Server should answer with
-
Albums
(/album
route)GET /album
- get all albums- Server should answer with
status code
200 and all albums records
- Server should answer with
GET /album/:id
- get single album by id- Server should answer with
status code
200 and and record withid === albumId
if it exists - Server should answer with
status code
400 and corresponding message ifalbumId
is invalid (notuuid
) - Server should answer with
status code
404 and corresponding message if record withid === albumId
doesn't exist
- Server should answer with
POST /album
- create new album- Server should answer with
status code
201 and newly created record if request is valid - Server should answer with
status code
400 and corresponding message if requestbody
does not contain required fields
- Server should answer with
PUT /album/:id
- update album info- Server should answer with
status code
200 and updated record if request is valid - Server should answer with
status code
400 and corresponding message ifalbumId
is invalid (notuuid
) - Server should answer with
status code
404 and corresponding message if record withid === albumId
doesn't exist
- Server should answer with
DELETE /album/:id
- delete album- Server should answer with
status code
204 if the record is found and deleted - Server should answer with
status code
400 and corresponding message ifalbumId
is invalid (notuuid
) - Server should answer with
status code
404 and corresponding message if record withid === albumId
doesn't exist
- Server should answer with
-
Favorites
GET /favs
- get all favorites- Server should answer with
status code
200 and all favorite records (not their ids), split by entity type:
interface FavoritesRepsonse{ artists: Artist[]; albums: Album[]; tracks: Track[]; }
- Server should answer with
POST /favs/track/:id
- add track to the favorites- Server should answer with
status code
201 and corresponding message if track withid === trackId
exists - Server should answer with
status code
400 and corresponding message iftrackId
is invalid (notuuid
) - Server should answer with
status code
422 and corresponding message if track withid === trackId
doesn't exist
- Server should answer with
DELETE /favs/track/:id
- delete track from favorites- Server should answer with
status code
204 if the track was in favorites and now it's deleted id is found and deleted - Server should answer with
status code
400 and corresponding message iftrackId
is invalid (notuuid
) - Server should answer with
status code
404 and corresponding message if corresponding track is not favorite
- Server should answer with
POST /favs/album/:id
- add album to the favorites- Server should answer with
status code
201 and corresponding message if album withid === albumId
exists - Server should answer with
status code
400 and corresponding message ifalbumId
is invalid (notuuid
) - Server should answer with
status code
422 and corresponding message if album withid === albumId
doesn't exist
- Server should answer with
DELETE /favs/album/:id
- delete album from favorites- Server should answer with
status code
204 if the album was in favorites and now it's deleted id is found and deleted - Server should answer with
status code
400 and corresponding message ifalbumId
is invalid (notuuid
) - Server should answer with
status code
404 and corresponding message if corresponding album is not favorite
- Server should answer with
POST /favs/artist/:id
- add artist to the favorites- Server should answer with
status code
201 and corresponding message if artist withid === artistId
exists - Server should answer with
status code
400 and corresponding message ifartistId
is invalid (notuuid
) - Server should answer with
status code
422 and corresponding message if artist withid === artistId
doesn't exist
- Server should answer with
DELETE /favs/artist/:id
- delete artist from favorites- Server should answer with
status code
204 if the artist was in favorites and now it's deleted id is found and deleted - Server should answer with
status code
400 and corresponding message ifartistId
is invalid (notuuid
) - Server should answer with
status code
404 and corresponding message if corresponding artist is not favorite
- Server should answer with
-
For now, these endpoints should operate only with in-memory (hardcoded) data, in the next tasks we will use a DB for it. You should organize your modules with the consideration that the data source will be changed soon.
-
An
application/json
format should be used for request and response body. -
Do not put everything in one file - use a separate file for application creation (bootstrapping), for controllers (routers) and code related to business logic. Also split files to different modules depends on a domain (user-related, artist-related, etc...).
-
User
's password should be excluded from server response. -
When you delete
Artist
,Album
orTrack
, it'sid
should be deleted from favorites (if was there) and references to it in other entities should becomenull
. For example:Artist
is deleted => thisartistId
in correspondingAlbums
's andTrack
's becomenull
+ this artist'sid
is deleted from favorites, same logic forAlbum
andTrack
. -
Non-existing entity can't be added to
Favorites
. -
To run the service
npm start
command should be used. -
Service should listen on PORT
4000
by default, PORT value is stored in.env
file. -
Incoming requests should be validated.
-
You can fix and use OpenAPI file in
doc
folder.
Hints
- To generate all entities
id
s use uuid package or Node.js analogue.