Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
H
hw87AlenBolatov
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
Болатов Ален
hw87AlenBolatov
Commits
a6a8164e
Commit
a6a8164e
authored
Mar 15, 2023
by
Болатов Ален
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added track router and model
parent
ecb79a32
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
1 deletion
+60
-1
index.ts
backend/src/index.ts
+2
-0
albums.ts
backend/src/routes/albums.ts
+1
-1
track.ts
backend/src/routes/track.ts
+57
-0
No files found.
backend/src/index.ts
View file @
a6a8164e
...
@@ -4,6 +4,7 @@ import {artistRouter} from './routes/artist';
...
@@ -4,6 +4,7 @@ import {artistRouter} from './routes/artist';
import
cors
from
'cors'
;
import
cors
from
'cors'
;
import
{
albumRouter
}
from
'./routes/albums'
;
import
{
albumRouter
}
from
'./routes/albums'
;
import
{
connect
}
from
'mongoose'
;
import
{
connect
}
from
'mongoose'
;
import
{
trackRouter
}
from
'./routes/track'
;
const
app
:
Express
=
express
();
const
app
:
Express
=
express
();
app
.
use
(
json
());
app
.
use
(
json
());
...
@@ -11,6 +12,7 @@ app.use(cors());
...
@@ -11,6 +12,7 @@ app.use(cors());
app
.
use
(
'/artists'
,
artistRouter
);
app
.
use
(
'/artists'
,
artistRouter
);
app
.
use
(
'/albums'
,
albumRouter
);
app
.
use
(
'/albums'
,
albumRouter
);
app
.
use
(
'/tracks'
,
trackRouter
);
const
run
=
async
()
=>
{
const
run
=
async
()
=>
{
await
connect
(
`
${
process
.
env
.
MONGO_URL
}
/musicApp`
);
await
connect
(
`
${
process
.
env
.
MONGO_URL
}
/musicApp`
);
...
...
backend/src/routes/albums.ts
View file @
a6a8164e
...
@@ -8,7 +8,7 @@ import {IArtist} from './artist';
...
@@ -8,7 +8,7 @@ import {IArtist} from './artist';
const
upload
=
multer
({
dest
:
'uploads/albums'
});
const
upload
=
multer
({
dest
:
'uploads/albums'
});
const
router
=
express
.
Router
();
const
router
=
express
.
Router
();
interface
IAlbum
{
export
interface
IAlbum
{
name
:
string
;
name
:
string
;
albumImage
:
File
;
albumImage
:
File
;
year
:
number
;
year
:
number
;
...
...
backend/src/routes/track.ts
0 → 100644
View file @
a6a8164e
import
express
,
{
Request
,
Response
}
from
'express'
;
import
{
model
,
Schema
,
HydratedDocument
,
Types
}
from
'mongoose'
;
import
{
IAlbum
}
from
'./albums'
;
const
router
=
express
.
Router
();
interface
ITrack
{
name
:
string
;
album
:
Types
.
ObjectId
;
duration
:
string
;
}
const
Track
=
model
<
ITrack
>
(
'Track'
,
new
Schema
({
name
:
String
,
duration
:
String
,
album
:
{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
'Album'
,
},
})
);
router
.
get
(
'/'
,
async
(
req
:
Request
,
res
:
Response
)
=>
{
if
(
!
req
.
query
.
album
)
{
try
{
const
tracks
=
await
Track
.
find
().
populate
<
{
album
:
IAlbum
}
>
(
'album'
);
res
.
send
(
tracks
);
return
;
}
catch
(
err
:
unknown
)
{
res
.
send
(
'Could not get tracks'
);
}
}
try
{
const
albumTracks
=
await
Track
.
find
({
album
:
req
.
query
.
album
});
res
.
send
(
albumTracks
);
}
catch
(
err
:
unknown
)
{
res
.
send
(
`Could not find album tracks of
${
req
.
query
.
album
}
`
);
}
});
router
.
post
(
'/'
,
async
(
req
:
Request
,
res
:
Response
)
=>
{
try
{
const
track
:
HydratedDocument
<
ITrack
>
=
new
Track
({
name
:
req
.
body
.
name
,
album
:
req
.
body
.
album
,
duration
:
req
.
body
.
duration
,
});
await
track
.
save
();
res
.
send
(
`Saved track:
${
track
}
`
);
}
catch
(
err
:
unknown
)
{
res
.
send
(
'Could not create track'
);
}
});
export
{
router
as
trackRouter
};
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