Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
I
initial_project
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
Нұрасыл Қайратұлы
initial_project
Commits
9eff7f53
Commit
9eff7f53
authored
Jul 26, 2024
by
Nurasyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
3aa42b7d
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
978 additions
and
65 deletions
+978
-65
App.tsx
client/src/App.tsx
+1
-0
package-lock.json
server/package-lock.json
+892
-22
package.json
server/package.json
+3
-0
b549d141-6eec-4fd2-bb23-01a60970b06d.jpeg
.../public/uploads/b549d141-6eec-4fd2-bb23-01a60970b06d.jpeg
+0
-0
app.ts
server/src/app.ts
+13
-1
appDataSource.ts
server/src/appDataSource.ts
+14
-0
product.controller.ts
server/src/controllers/product.controller.ts
+2
-2
product.entity.ts
server/src/entities/product.entity.ts
+19
-0
product.repository.ts
server/src/repositories/product.repository.ts
+26
-0
product.service.ts
server/src/services/product.service.ts
+8
-40
No files found.
client/src/App.tsx
View file @
9eff7f53
...
...
@@ -7,6 +7,7 @@ import { NewProductForm } from './containers/NewProductForm';
function
App
()
{
return
(
<>
<
a
href=
""
></
a
>
<
CssBaseline
/>
<
header
>
<
AppToolbar
/>
...
...
server/package-lock.json
View file @
9eff7f53
This diff is collapsed.
Click to expand it.
server/package.json
View file @
9eff7f53
...
...
@@ -18,12 +18,15 @@
"cors"
:
"^2.8.5"
,
"express"
:
"^4.18.2"
,
"multer"
:
"^1.4.5-lts.1"
,
"mysql"
:
"^2.18.1"
,
"nanoid"
:
"^3.3.6"
,
"pg"
:
"^8.12.0"
,
"reflect-metadata"
:
"^0.2.1"
,
"save"
:
"^2.9.0"
,
"save-dev"
:
"^0.0.1-security"
,
"ts-node"
:
"^10.9.1"
,
"tslib"
:
"^2.6.0"
,
"typeorm"
:
"^0.3.20"
,
"typescript"
:
"^5.1.6"
},
"devDependencies"
:
{
...
...
server/public/uploads/b549d141-6eec-4fd2-bb23-01a60970b06d.jpeg
0 → 100644
View file @
9eff7f53
70.7 KB
server/src/app.ts
View file @
9eff7f53
...
...
@@ -2,6 +2,7 @@ import express from 'express';
import
{
Application
,
RequestHandler
}
from
'express'
;
import
{
AppInit
}
from
'./interfaces/AppInit.interface'
;
import
{
IRoute
}
from
'./interfaces/IRoute.interface'
;
import
{
AppDataSource
}
from
'./appDataSource'
;
class
App
{
public
app
:
Application
;
...
...
@@ -28,9 +29,20 @@ class App {
this
.
app
.
use
(
express
.
json
());
this
.
app
.
use
(
express
.
static
(
'public'
))
}
public
listen
()
{
public
async
listen
()
{
await
AppDataSource
.
initialize
()
.
then
(()
=>
{
console
.
log
(
"Data Source has been initialized!"
)
})
.
catch
((
err
)
=>
{
console
.
error
(
"Error during Data Source initialization"
,
err
)
})
this
.
app
.
listen
(
this
.
port
,
()
=>
{
console
.
log
(
`App listening on the http://localhost:
${
this
.
port
}
`
);
process
.
on
(
'exit'
,
()
=>
{
AppDataSource
.
destroy
();
})
});
}
}
...
...
server/src/appDataSource.ts
0 → 100644
View file @
9eff7f53
import
{
DataSource
}
from
"typeorm"
;
import
{
Product
}
from
"./entities/product.entity"
;
export
const
AppDataSource
=
new
DataSource
({
type
:
"postgres"
,
host
:
"localhost"
,
port
:
5432
,
username
:
"postgres"
,
password
:
"root"
,
database
:
"classwork"
,
schema
:
"classwork"
,
synchronize
:
true
,
entities
:
[
Product
]
})
\ No newline at end of file
server/src/controllers/product.controller.ts
View file @
9eff7f53
...
...
@@ -10,8 +10,8 @@ export class ProductController {
this
.
service
=
new
ProductService
();
}
getAllProducts
:
RequestHandler
=
(
req
,
res
):
void
=>
{
const
products
=
this
.
service
.
getAllProducts
();
getAllProducts
:
RequestHandler
=
async
(
req
,
res
):
Promise
<
void
>
=>
{
const
products
=
await
this
.
service
.
getAllProducts
();
res
.
send
(
products
);
};
...
...
server/src/entities/product.entity.ts
0 → 100644
View file @
9eff7f53
import
{
Entity
,
PrimaryGeneratedColumn
,
Column
}
from
"typeorm"
;
@
Entity
()
export
class
Product
{
@
PrimaryGeneratedColumn
()
id
!
:
number
;
@
Column
()
title
!
:
string
@
Column
()
description
!
:
string
@
Column
()
price
!
:
number
@
Column
({
nullable
:
true
})
image
!
:
string
}
\ No newline at end of file
server/src/repositories/product.repository.ts
0 → 100644
View file @
9eff7f53
import
{
AppDataSource
}
from
"@/appDataSource"
;
import
{
ProductDto
}
from
"@/dto/product.dto"
;
import
{
Product
}
from
"@/entities/product.entity"
;
import
{
Repository
}
from
"typeorm"
;
class
ProductRepo
{
private
repo
:
Repository
<
Product
>
constructor
()
{
this
.
repo
=
AppDataSource
.
getRepository
(
Product
)
}
async
create
(
body
:
ProductDto
)
{
return
await
this
.
repo
.
save
(
body
)
}
async
getAll
()
{
return
await
this
.
repo
.
find
()
}
async
getOne
(
id
:
number
)
{
return
await
this
.
repo
.
findOne
({
where
:
{
id
:
id
}})
}
}
export
const
productRepo
=
new
ProductRepo
()
\ No newline at end of file
server/src/services/product.service.ts
View file @
9eff7f53
import
{
IProduct
}
from
'@/interfaces/IProduct.interface'
;
import
path
from
'path'
;
import
*
as
fs
from
'fs'
;
import
{
ProductDto
}
from
'@/dto/product.dto'
;
const
filePath
=
path
.
join
(
__dirname
,
'../../data'
)
;
import
{
productRepo
}
from
'@/repositories/product.repository'
;
import
{
Product
}
from
'@/entities/product.entity'
;
export
class
ProductService
{
private
products
:
IProduct
[]
=
[];
constructor
()
{
this
.
init
();
}
init
():
void
{
try
{
const
fileContent
=
fs
.
readFileSync
(
`
${
filePath
}
/products.json`
);
this
.
products
=
JSON
.
parse
(
fileContent
.
toString
());
}
catch
(
e
)
{
this
.
products
=
[];
}
}
save
():
void
{
fs
.
writeFileSync
(
`
${
filePath
}
/products.json`
,
JSON
.
stringify
(
this
.
products
,
null
,
2
));
}
getAllProducts
=
():
IProduct
[]
=>
{
return
this
.
products
;
getAllProducts
=
async
():
Promise
<
Product
[]
>
=>
{
return
await
productRepo
.
getAll
()
};
getProduct
=
(
id
:
string
):
IProduct
=>
{
const
product
=
this
.
products
.
find
((
product
)
=>
product
.
id
===
id
);
if
(
product
)
{
return
product
;
}
throw
new
Error
(
'Invalid id'
);
getProduct
=
async
(
id
:
string
):
Promise
<
Product
|
null
>
=>
{
return
await
productRepo
.
getOne
(
parseInt
(
id
))
};
createProduct
=
(
data
:
ProductDto
):
IProduct
=>
{
const
product
=
{
...
data
,
id
:
Math
.
random
().
toString
()
};
this
.
products
.
push
(
product
);
this
.
save
();
return
product
;
createProduct
=
async
(
data
:
ProductDto
):
Promise
<
Product
>
=>
{
return
productRepo
.
create
(
data
)
};
}
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