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
9da4cf60
Commit
9da4cf60
authored
Mar 14, 2023
by
Болатов Ален
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#3
added album model
parent
a0e4c63e
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
75 additions
and
10 deletions
+75
-10
index.ts
backend/src/index.ts
+9
-0
albums.ts
backend/src/routes/albums.ts
+60
-0
artist.ts
backend/src/routes/artist.ts
+6
-10
621b078823867fbd499df093487ce8cc
backend/uploads/albums/621b078823867fbd499df093487ce8cc
+0
-0
9b938678cfc356c56cb1df913d50a3f8
backend/uploads/albums/9b938678cfc356c56cb1df913d50a3f8
+0
-0
ae8f9bad9c5a8d0502d27057a4ea345c
backend/uploads/albums/ae8f9bad9c5a8d0502d27057a4ea345c
+0
-0
0170bb538bb3efc8dd5d589c827860d7
backend/uploads/artists/0170bb538bb3efc8dd5d589c827860d7
+0
-0
09e4015e5ddfbbb88c4260c4e1f431f7
backend/uploads/artists/09e4015e5ddfbbb88c4260c4e1f431f7
+0
-0
b81d539cee1aa1150e48c66d67422fac
backend/uploads/artists/b81d539cee1aa1150e48c66d67422fac
+0
-0
e09e0e9e5a29fd79786e726503571e18
backend/uploads/artists/e09e0e9e5a29fd79786e726503571e18
+0
-0
No files found.
backend/src/index.ts
View file @
9da4cf60
...
...
@@ -2,12 +2,21 @@ import express, {Express, json} from 'express';
import
'dotenv/config'
;
import
{
artistRouter
}
from
'./routes/artist'
;
import
cors
from
'cors'
;
import
{
albumRouter
}
from
'./routes/albums'
;
import
{
connect
}
from
'mongoose'
;
const
app
:
Express
=
express
();
app
.
use
(
json
());
app
.
use
(
cors
());
app
.
use
(
'/artists'
,
artistRouter
);
app
.
use
(
'/albums'
,
albumRouter
);
const
run
=
async
()
=>
{
await
connect
(
`
${
process
.
env
.
MONGO_URL
}
/musicApp`
);
};
run
().
catch
((
err
)
=>
console
.
log
(
err
));
app
.
listen
(
process
.
env
.
PORT
,
()
=>
{
console
.
log
(
'Server started on port '
+
process
.
env
.
PORT
);
...
...
backend/src/routes/albums.ts
0 → 100644
View file @
9da4cf60
import
express
,
{
Request
,
Response
}
from
'express'
;
import
{
model
,
Schema
,
HydratedDocument
,
Types
}
from
'mongoose'
;
import
multer
from
'multer'
;
import
fs
from
'fs'
;
import
path
from
'path'
;
import
{
IArtist
}
from
'./artist'
;
const
upload
=
multer
({
dest
:
'uploads/albums'
});
const
router
=
express
.
Router
();
interface
IAlbum
{
name
:
string
;
albumImage
:
File
;
year
:
number
;
artist
:
Types
.
ObjectId
;
}
const
Album
=
model
<
IAlbum
>
(
'Album'
,
new
Schema
({
artist
:
{
type
:
Schema
.
Types
.
ObjectId
,
ref
:
'Artist'
,
},
name
:
String
,
year
:
Number
,
albumImage
:
{
data
:
Buffer
,
contentType
:
String
,
},
})
);
router
.
get
(
'/'
,
async
(
req
:
Request
,
res
:
Response
)
=>
{
const
albums
=
await
Album
.
find
().
populate
<
{
artist
:
IArtist
}
>
(
'artist'
);
res
.
send
(
albums
);
});
router
.
post
(
'/'
,
upload
.
single
(
'albumImage'
),
async
(
req
:
Request
,
res
:
Response
)
=>
{
const
album
:
HydratedDocument
<
IAlbum
>
=
new
Album
({
name
:
req
.
body
.
name
,
albumImage
:
{
data
:
fs
.
readFileSync
(
path
.
join
(
'uploads/albums/'
+
req
.
file
?.
filename
)
),
contentType
:
'image'
,
},
year
:
req
.
body
.
year
,
artist
:
req
.
body
.
artist
,
});
await
album
.
save
();
res
.
send
(
'Sucessfully saved'
);
}
);
export
{
router
as
albumRouter
};
backend/src/routes/artist.ts
View file @
9da4cf60
import
express
,
{
Request
,
Response
}
from
'express'
;
import
{
model
,
Schema
,
connect
,
HydratedDocument
}
from
'mongoose'
;
import
{
model
,
Schema
,
HydratedDocument
}
from
'mongoose'
;
import
multer
from
'multer'
;
import
fs
from
'fs'
;
import
path
from
'path'
;
const
upload
=
multer
({
dest
:
'uploads/'
});
const
upload
=
multer
({
dest
:
'uploads/
artists
'
});
const
router
=
express
.
Router
();
interface
IArtist
{
export
interface
IArtist
{
name
:
string
;
image
:
File
;
description
:
string
;
...
...
@@ -30,12 +30,6 @@ const artistSchema = new Schema<IArtist>({
const
Artist
=
model
<
IArtist
>
(
'Artist'
,
artistSchema
);
const
run
=
async
()
=>
{
await
connect
(
`
${
process
.
env
.
MONGO_URL
}
/artist`
);
};
run
().
catch
((
err
)
=>
console
.
log
(
err
));
router
.
get
(
'/'
,
async
(
req
:
Request
,
res
:
Response
)
=>
{
const
artists
=
await
Artist
.
find
();
res
.
send
(
artists
);
...
...
@@ -49,7 +43,9 @@ router.post(
name
:
req
.
body
.
name
,
description
:
req
.
body
.
description
,
image
:
{
data
:
fs
.
readFileSync
(
path
.
join
(
'uploads/'
+
req
.
file
?.
filename
)),
data
:
fs
.
readFileSync
(
path
.
join
(
'uploads/artists/'
+
req
.
file
?.
filename
)
),
contentType
:
'image'
,
},
});
...
...
backend/uploads/albums/621b078823867fbd499df093487ce8cc
0 → 100644
View file @
9da4cf60
File added
backend/uploads/albums/9b938678cfc356c56cb1df913d50a3f8
0 → 100644
View file @
9da4cf60
File added
backend/uploads/albums/ae8f9bad9c5a8d0502d27057a4ea345c
0 → 100644
View file @
9da4cf60
File added
backend/uploads/
504fb468410c009000968b276ae8f92a
→
backend/uploads/
artists/0170bb538bb3efc8dd5d589c827860d7
View file @
9da4cf60
File moved
backend/uploads/artists/09e4015e5ddfbbb88c4260c4e1f431f7
0 → 100644
View file @
9da4cf60
File added
backend/uploads/artists/b81d539cee1aa1150e48c66d67422fac
0 → 100644
View file @
9da4cf60
File added
backend/uploads/artists/e09e0e9e5a29fd79786e726503571e18
0 → 100644
View file @
9da4cf60
File added
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