Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
H
hw92
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
5
Issues
5
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
Болатов Ален
hw92
Commits
a16d2cc7
Commit
a16d2cc7
authored
Apr 01, 2023
by
Болатов Ален
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '
#14
' into 'dev'
created api for post comment and user See merge request
!13
parents
e59e054a
3a45714d
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
256 additions
and
0 deletions
+256
-0
commentApi.ts
frontend/src/api/commentApi.ts
+54
-0
instance.ts
frontend/src/api/instance.ts
+13
-0
postApi.ts
frontend/src/api/postApi.ts
+70
-0
userApi.ts
frontend/src/api/userApi.ts
+55
-0
EStatuses.ts
frontend/src/enums/EStatuses.ts
+4
-0
IComment.ts
frontend/src/interfaces/IComment.ts
+10
-0
ICommentDto.ts
frontend/src/interfaces/ICommentDto.ts
+5
-0
IDataBase.ts
frontend/src/interfaces/IDataBase.ts
+4
-0
IPost.ts
frontend/src/interfaces/IPost.ts
+8
-0
IPostDto.ts
frontend/src/interfaces/IPostDto.ts
+7
-0
IResponse.ts
frontend/src/interfaces/IResponse.ts
+7
-0
IUser.ts
frontend/src/interfaces/IUser.ts
+6
-0
IUserCreateDto.ts
frontend/src/interfaces/IUserCreateDto.ts
+6
-0
IUserGetDto.ts
frontend/src/interfaces/IUserGetDto.ts
+7
-0
interfaces.ts
frontend/src/interfaces/interfaces.ts
+0
-0
No files found.
frontend/src/api/commentApi.ts
0 → 100644
View file @
a16d2cc7
import
{
EStatuses
}
from
"../enums/EStatuses"
;
import
IComment
from
"../interfaces/IComment"
;
import
ICommentDto
from
"../interfaces/ICommentDto"
;
import
IResponse
from
"../interfaces/IResponse"
;
import
{
instance
}
from
"./instance"
;
class
CommentApi
{
public
getCommentsByPost
=
async
(
post_id
:
string
):
Promise
<
IResponse
<
IComment
[]
|
undefined
>>
=>
{
try
{
const
response
=
await
instance
.
get
(
`/comments?post_id=
${
post_id
}
`
)
return
response
.
data
}
catch
(
err
:
unknown
)
{
const
error
=
err
as
Error
const
response
:
IResponse
<
undefined
>
=
{
status
:
EStatuses
.
NOT_OK
,
message
:
error
.
message
,
result
:
undefined
}
return
response
}
}
public
createComment
=
async
(
commentDto
:
ICommentDto
):
Promise
<
IResponse
<
IComment
|
undefined
>>
=>
{
try
{
const
response
=
await
instance
.
post
(
`/comments`
,
commentDto
)
return
response
.
data
}
catch
(
err
:
unknown
)
{
const
error
=
err
as
Error
const
response
:
IResponse
<
undefined
>
=
{
status
:
EStatuses
.
NOT_OK
,
message
:
error
.
message
,
result
:
undefined
}
return
response
}
}
public
deleteCommentById
=
async
(
id
:
string
):
Promise
<
IResponse
<
IComment
|
undefined
>>
=>
{
try
{
const
response
=
await
instance
.
delete
(
`/comments/
${
id
}
`
)
return
response
.
data
}
catch
(
err
:
unknown
)
{
const
error
=
err
as
Error
const
response
:
IResponse
<
undefined
>
=
{
status
:
EStatuses
.
NOT_OK
,
result
:
undefined
,
message
:
error
.
message
}
return
response
}
}
}
export
const
commentsApi
=
new
CommentApi
()
\ No newline at end of file
frontend/src/api/instance.ts
0 → 100644
View file @
a16d2cc7
import
axios
,
{
AxiosRequestConfig
,
InternalAxiosRequestConfig
}
from
"axios"
;
export
const
instance
=
axios
.
create
({
baseURL
:
import
.
meta
.
env
.
VITE_BASE_URL
})
instance
.
interceptors
.
request
.
use
((
req
:
InternalAxiosRequestConfig
)
=>
{
const
token
=
localStorage
.
getItem
(
'token'
)
if
(
token
)
{
req
.
headers
.
Authorization
=
token
}
return
req
})
\ No newline at end of file
frontend/src/api/postApi.ts
0 → 100644
View file @
a16d2cc7
import
{
EStatuses
}
from
'../enums/EStatuses'
import
IPost
from
"../interfaces/IPost"
;
import
IResponse
from
"../interfaces/IResponse"
;
import
{
instance
}
from
"./instance"
;
class
PostApi
{
public
getPosts
=
async
():
Promise
<
IResponse
<
IPost
[]
|
undefined
>>
=>
{
try
{
const
response
=
await
instance
.
get
(
'/posts'
)
return
response
.
data
}
catch
(
err
:
unknown
)
{
const
error
=
err
as
Error
const
response
:
IResponse
<
undefined
>
=
{
status
:
EStatuses
.
NOT_OK
,
result
:
undefined
,
message
:
error
.
message
}
return
response
}
}
public
getPostById
=
async
(
id
:
string
):
Promise
<
IResponse
<
IPost
|
undefined
>>
=>
{
try
{
const
response
=
await
instance
.
get
(
`/posts/
${
id
}
`
)
return
response
.
data
}
catch
(
err
:
unknown
)
{
const
error
=
err
as
Error
const
response
:
IResponse
<
undefined
>
=
{
status
:
EStatuses
.
NOT_OK
,
result
:
undefined
,
message
:
error
.
message
}
return
response
}
}
public
createPost
=
async
(
post
:
FormData
):
Promise
<
IResponse
<
IPost
|
undefined
>>
=>
{
try
{
const
response
=
await
instance
.
post
(
`/posts`
,
post
)
return
response
.
data
}
catch
(
err
:
unknown
)
{
const
error
=
err
as
Error
const
response
:
IResponse
<
undefined
>
=
{
status
:
EStatuses
.
NOT_OK
,
result
:
undefined
,
message
:
error
.
message
}
return
response
}
}
public
deletePostById
=
async
(
id
:
string
):
Promise
<
IResponse
<
IPost
|
undefined
>>
=>
{
try
{
const
response
=
await
instance
.
delete
(
`/posts/
${
id
}
`
)
return
response
.
data
}
catch
(
err
:
unknown
)
{
const
error
=
err
as
Error
const
response
:
IResponse
<
undefined
>
=
{
status
:
EStatuses
.
NOT_OK
,
result
:
undefined
,
message
:
error
.
message
}
return
response
}
}
}
export
const
postApi
=
new
PostApi
()
\ No newline at end of file
frontend/src/api/userApi.ts
0 → 100644
View file @
a16d2cc7
import
{
EStatuses
}
from
"../enums/EStatuses"
import
IResponse
from
"../interfaces/IResponse"
import
IUserCreateDto
from
"../interfaces/IUserCreateDto"
import
IUserGetDto
from
"../interfaces/IUserGetDto"
import
{
instance
}
from
"./instance"
class
UserApi
{
public
login
=
async
(
user
:
IUserCreateDto
):
Promise
<
IResponse
<
IUserGetDto
|
undefined
>>
=>
{
try
{
const
response
=
await
instance
.
post
(
`/users/login`
,
user
)
return
response
.
data
}
catch
(
err
:
unknown
)
{
const
error
=
err
as
Error
const
response
:
IResponse
<
undefined
>
=
{
status
:
EStatuses
.
NOT_OK
,
result
:
undefined
,
message
:
error
.
message
}
return
response
}
}
public
register
=
async
(
user
:
IUserCreateDto
):
Promise
<
IResponse
<
IUserGetDto
|
undefined
>>
=>
{
try
{
const
response
=
await
instance
.
post
(
`/users`
,
user
)
return
response
.
data
}
catch
(
err
:
unknown
)
{
const
error
=
err
as
Error
const
response
:
IResponse
<
undefined
>
=
{
status
:
EStatuses
.
NOT_OK
,
result
:
undefined
,
message
:
error
.
message
}
return
response
}
}
public
checkToken
=
async
():
Promise
<
IResponse
<
IUserGetDto
|
undefined
>>
=>
{
try
{
const
response
=
await
instance
.
get
(
`/users/token`
)
return
response
.
data
}
catch
(
err
:
unknown
)
{
const
error
=
err
as
Error
const
response
:
IResponse
<
undefined
>
=
{
status
:
EStatuses
.
NOT_OK
,
result
:
undefined
,
message
:
error
.
message
}
return
response
}
}
}
export
const
userApi
=
new
UserApi
()
\ No newline at end of file
frontend/src/enums/EStatuses.ts
0 → 100644
View file @
a16d2cc7
export
const
enum
EStatuses
{
OK
=
1
,
NOT_OK
=
0
}
\ No newline at end of file
frontend/src/interfaces/IComment.ts
0 → 100644
View file @
a16d2cc7
import
IPost
from
"./IPost"
import
IUser
from
"./IUser"
export
default
interface
IComment
{
_id
:
string
user
:
IUser
post
:
IPost
comment
:
string
datetime
:
Date
}
\ No newline at end of file
frontend/src/interfaces/ICommentDto.ts
0 → 100644
View file @
a16d2cc7
import
IComment
from
"./IComment"
;
export
default
interface
ICommentDto
{
comment
:
IComment
[
'comment'
]
}
\ No newline at end of file
frontend/src/interfaces/IDataBase.ts
0 → 100644
View file @
a16d2cc7
export
default
interface
IDataBase
{
init
:
()
=>
Promise
<
void
>
close
:
()
=>
Promise
<
void
>
|
void
}
\ No newline at end of file
frontend/src/interfaces/IPost.ts
0 → 100644
View file @
a16d2cc7
export
default
interface
IPost
{
_id
:
string
title
:
string
description
:
string
image
:
File
|
undefined
|
string
datetime
:
Date
}
\ No newline at end of file
frontend/src/interfaces/IPostDto.ts
0 → 100644
View file @
a16d2cc7
import
IPost
from
"./IPost"
export
default
interface
IPostDto
{
title
:
IPost
[
'title'
]
description
:
IPost
[
'description'
]
image
:
File
|
undefined
|
string
}
\ No newline at end of file
frontend/src/interfaces/IResponse.ts
0 → 100644
View file @
a16d2cc7
import
{
EStatuses
}
from
'../enums/EStatuses'
export
default
interface
IResponse
<
T
>
{
result
:
T
message
:
string
status
:
EStatuses
}
\ No newline at end of file
frontend/src/interfaces/IUser.ts
0 → 100644
View file @
a16d2cc7
export
default
interface
IUser
{
_id
:
string
username
:
string
;
password
:
string
;
token
:
string
;
}
frontend/src/interfaces/IUserCreateDto.ts
0 → 100644
View file @
a16d2cc7
import
IUSer
from
"./IUser"
;
export
default
interface
IUserCreateDto
{
username
:
IUSer
[
'username'
]
password
:
IUSer
[
'password'
]
}
\ No newline at end of file
frontend/src/interfaces/IUserGetDto.ts
0 → 100644
View file @
a16d2cc7
import
IUSer
from
"./IUser"
;
export
default
interface
IUserGetDto
{
_id
:
IUSer
[
'_id'
]
username
:
IUSer
[
'username'
]
token
:
IUSer
[
'token'
]
}
\ No newline at end of file
frontend/src/interfaces/interfaces.ts
deleted
100644 → 0
View file @
e59e054a
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