Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
H
Homework_89_Tsoy_Danil
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Цой Данил
Homework_89_Tsoy_Danil
Commits
c24e5de2
Commit
c24e5de2
authored
Mar 15, 2023
by
Цой Данил
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#4
added functions to post, and get tracks by their ids and what was added inside input
parent
0bc634c4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
4 deletions
+47
-4
albumsController.ts
src/controllers/albumsController.ts
+3
-3
tracksController.ts
src/controllers/tracksController.ts
+39
-0
index.ts
src/index.ts
+2
-0
tracksService.ts
src/services/tracksService.ts
+3
-1
No files found.
src/controllers/albumsController.ts
View file @
c24e5de2
...
...
@@ -23,8 +23,8 @@ export class AlbumsController {
constructor
()
{
this
.
router
=
express
.
Router
()
this
.
service
=
albumsService
this
.
router
.
get
(
'/'
,
this
.
getAlbums
Handler
)
this
.
router
.
get
(
'/:id'
,
this
.
getAlbums
Handler
)
this
.
router
.
get
(
'/'
,
this
.
getAlbums
)
this
.
router
.
get
(
'/:id'
,
this
.
getAlbums
)
this
.
router
.
post
(
'/'
,
upload
.
single
(
'coverImage'
),
this
.
addAlbum
)
}
...
...
@@ -32,7 +32,7 @@ export class AlbumsController {
return
this
.
router
;
}
private
getAlbums
Handler
=
async
(
req
:
Request
,
res
:
Response
):
Promise
<
void
>
=>
{
private
getAlbums
=
async
(
req
:
Request
,
res
:
Response
):
Promise
<
void
>
=>
{
const
response
=
await
this
.
service
.
getAlbums
(
req
)
if
(
response
.
status
===
EStatuses
.
FAILURE
){
res
.
status
(
418
).
send
(
response
)
...
...
src/controllers/tracksController.ts
0 → 100644
View file @
c24e5de2
import
express
,
{
Request
,
Response
,
Router
}
from
"express"
;
import
{
EStatuses
}
from
"../enum/EStatuses"
;
import
ITrackDto
from
"../interfaces/ITrackDto"
;
import
{
tracksService
,
TracksService
}
from
"../services/tracksService"
;
export
class
TracksController
{
private
router
:
Router
private
service
:
TracksService
constructor
()
{
this
.
router
=
express
.
Router
()
this
.
service
=
tracksService
this
.
router
.
get
(
'/'
,
this
.
getTracks
)
this
.
router
.
post
(
'/'
,
this
.
addTrack
)
}
getRouter
()
{
return
this
.
router
;
}
private
getTracks
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
const
response
=
await
this
.
service
.
getTracks
(
req
)
if
(
response
.
status
===
EStatuses
.
FAILURE
){
res
.
status
(
418
).
send
(
response
)
}
else
{
res
.
send
(
response
)
}
}
private
addTrack
=
async
(
req
:
Request
,
res
:
Response
)
=>
{
const
trackDto
:
ITrackDto
=
req
.
body
const
response
=
await
this
.
service
.
addTrack
(
trackDto
)
if
(
response
.
status
===
EStatuses
.
FAILURE
){
res
.
status
(
418
).
send
(
response
)
}
else
{
res
.
send
(
response
)
}
}
}
\ No newline at end of file
src/index.ts
View file @
c24e5de2
...
...
@@ -5,6 +5,7 @@ import { HealthCheckController } from "./controllers/healthCheck";
import
{
mongooseDB
}
from
"./repository/mongooseDB"
;
import
{
ArtistsController
}
from
"./controllers/artistsController"
;
import
{
AlbumsController
}
from
"./controllers/albumsController"
;
import
{
TracksController
}
from
"./controllers/tracksController"
;
dotenv
.
config
()
...
...
@@ -22,6 +23,7 @@ class App {
this
.
app
.
use
(
'/health-check'
,
new
HealthCheckController
().
getRouter
())
this
.
app
.
use
(
'/artists'
,
new
ArtistsController
().
getRouter
())
this
.
app
.
use
(
'/albums'
,
new
AlbumsController
().
getRouter
())
this
.
app
.
use
(
'/tracks'
,
new
TracksController
().
getRouter
())
this
.
app
.
listen
(
process
.
env
.
APP_PORT
,
()
=>
{
console
.
log
(
`Server is running on http://localhost:
${
process
.
env
.
APP_PORT
}
`
)
})
...
...
src/services/tracksService.ts
View file @
c24e5de2
...
...
@@ -54,4 +54,6 @@ export class TracksService {
return
response
}
}
}
\ No newline at end of file
}
export
const
tracksService
=
new
TracksService
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment