-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
845 additions
and
98 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { ValidHttpResponse } from 'packages/handler/response/validHttp.response'; | ||
import { DEFAULT_PAGE, DEFAULT_PAGE_SIZE } from 'core/common/constants'; | ||
import { MessageDto } from 'core/common/dto'; | ||
import { | ||
AddCommentDto, | ||
COMMENT_PARENT_TYPE, | ||
CommentService, | ||
} from 'core/modules/comment'; | ||
|
||
class Controller { | ||
constructor() { | ||
this.commentService = CommentService; | ||
} | ||
|
||
createComment = async req => { | ||
const { parentType, parentId, content } = AddCommentDto(req.body); | ||
await this.commentService.createComment( | ||
parentId, | ||
parentType, | ||
content, | ||
req.user.payload.id, | ||
); | ||
return ValidHttpResponse.toOkResponse(MessageDto('Comment created')); | ||
}; | ||
|
||
getCommentPaginationByParentIdAndType = async req => { | ||
const parentId = req.params.id; | ||
const page = req.query.page || DEFAULT_PAGE; | ||
const size = req.query.size || DEFAULT_PAGE_SIZE; | ||
const parentType = req.query.keyword || 'POST'; | ||
const data = | ||
await this.commentService.getCommentPaginationByParentIdAndType( | ||
parentId, | ||
COMMENT_PARENT_TYPE[parentType], | ||
page, | ||
size, | ||
); | ||
|
||
return ValidHttpResponse.toOkResponse(data); | ||
}; | ||
} | ||
|
||
export const CommentController = new Controller(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Module } from 'packages/handler/Module'; | ||
import { RecordId, page, size, keyword } from 'core/common/swagger'; | ||
import { CommentController } from './comment.controller'; | ||
|
||
export const CommentResolver = Module.builder() | ||
.addPrefix({ | ||
prefixPath: '/comments', | ||
tag: 'comments', | ||
module: 'CommentModule', | ||
}) | ||
.register([ | ||
{ | ||
route: '', | ||
method: 'post', | ||
controller: CommentController.createComment, | ||
body: 'AddCommentDto', | ||
model: { $ref: 'MessageDto' }, | ||
preAuthorization: true, | ||
}, | ||
{ | ||
route: '/:id/nested', | ||
method: 'get', | ||
params: [page, size, keyword, RecordId], | ||
controller: CommentController.getCommentPaginationByParentIdAndType, | ||
model: { $ref: 'PaginationCommentDto' }, | ||
description: | ||
'Get list nested comments of a post or comment (Keyword POST or COMMENT)', | ||
}, | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { ValidHttpResponse } from 'packages/handler/response/validHttp.response'; | ||
import { MessageDto } from 'core/common/dto'; | ||
import { UserReactService } from 'core/modules/user-react/service/user-react.service'; | ||
import { | ||
AddUserReactDto, | ||
DeleteUserReactDto, | ||
} from 'core/modules/user-react/dto'; | ||
|
||
class Controller { | ||
constructor() { | ||
this.userReactService = UserReactService; | ||
} | ||
|
||
createUserReact = async req => { | ||
const { reactableId, reactableType, reactType } = AddUserReactDto( | ||
req.body, | ||
); | ||
await this.userReactService.createUserReact( | ||
req.user.payload.id, | ||
reactableId, | ||
reactableType, | ||
reactType, | ||
); | ||
return ValidHttpResponse.toOkResponse(MessageDto('UserReact created')); | ||
}; | ||
|
||
deleteUserReact = async req => { | ||
const { reactableType, reactableId } = DeleteUserReactDto(req.body); | ||
await this.userReactService.deleteUserReact( | ||
req.user.payload.id, | ||
reactableId, | ||
reactableType, | ||
); | ||
return ValidHttpResponse.toOkResponse(MessageDto('UserReact deleted')); | ||
}; | ||
} | ||
|
||
export const UserReactController = new Controller(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Module } from 'packages/handler/Module'; | ||
import { UserReactController } from './user-react.controller'; | ||
|
||
export const UserReactResolver = Module.builder() | ||
.addPrefix({ | ||
prefixPath: '/user-reacts', | ||
tag: 'user-reacts', | ||
module: 'UserReactModule', | ||
}) | ||
.register([ | ||
{ | ||
route: '', | ||
method: 'post', | ||
controller: UserReactController.createUserReact, | ||
body: 'AddUserReactDto', | ||
model: { $ref: 'MessageDto' }, | ||
preAuthorization: true, | ||
description: | ||
'Do LIKE or DISLIKE to a comment or post actioned by user', | ||
}, | ||
{ | ||
route: '', | ||
method: 'delete', | ||
controller: UserReactController.deleteUserReact, | ||
body: 'DeleteUserReactDto', | ||
model: { $ref: 'MessageDto' }, | ||
description: | ||
'Delete a LIKE or DISLIKE of a comment or post actioned by owner', | ||
preAuthorization: true, | ||
}, | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const DEFAULT_PAGE_SIZE = 50; | ||
export const DEFAULT_PAGE = 1; | ||
export const DEFAULT_KEYWORD = ''; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './cloudinary.constant'; | ||
export * from './default-params.constant'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './id-array.dto'; | ||
export * from './message.dto'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ApiDocument } from 'core/config/swagger.config'; | ||
import { SwaggerDocument } from 'packages/swagger'; | ||
|
||
ApiDocument.addModel('MessageDto', { | ||
message: SwaggerDocument.ApiProperty({ type: 'string', readOnly: true }), | ||
}); | ||
|
||
export const MessageDto = message => ({ | ||
message, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { SwaggerDocument } from '../../../packages/swagger'; | ||
|
||
export const keyword = SwaggerDocument.ApiParams({ | ||
name: 'keyword', | ||
paramsIn: 'query', | ||
required: false, | ||
type: 'string', | ||
description: 'keyword is used to query search', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { SwaggerDocument } from '../../../packages/swagger'; | ||
|
||
export const size = SwaggerDocument.ApiParams({ | ||
name: 'size', | ||
paramsIn: 'query', | ||
required: false, | ||
type: 'number', | ||
description: 'Number of items per page', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { SwaggerDocument } from '../../../packages/swagger'; | ||
|
||
export const page = SwaggerDocument.ApiParams({ | ||
name: 'page', | ||
paramsIn: 'query', | ||
required: false, | ||
type: 'number', | ||
description: 'get current page', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
backend/src/core/database/migrations/20240209194811_add_column_latiude_longitude_users.js
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
backend/src/core/database/migrations/20240307043035_create_posts.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* @param { import("knex").Knex } knex | ||
*/ | ||
const tableName = 'posts'; | ||
exports.up = async knex => { | ||
await knex.schema.createTable(tableName, table => { | ||
table.increments('id').unsigned().primary(); | ||
table.text('content'); | ||
table | ||
.integer('owner_id') | ||
.unsigned() | ||
.notNullable() | ||
.references('id') | ||
.inTable('users') | ||
.onDelete('CASCADE'); | ||
table.timestamp('updated_at').defaultTo(knex.fn.now()); | ||
}); | ||
|
||
await knex.raw(` | ||
CREATE TRIGGER update_timestamp | ||
BEFORE UPDATE | ||
ON ${tableName} | ||
FOR EACH ROW | ||
EXECUTE PROCEDURE update_timestamp(); | ||
`); | ||
}; | ||
/** | ||
* @param { import("knex").Knex } knex | ||
*/ | ||
exports.down = async knex => { | ||
await knex.schema.dropTable(tableName); | ||
await knex.raw(`DROP TRIGGER IF EXISTS update_timestamp ON ${tableName};`); | ||
}; |
25 changes: 25 additions & 0 deletions
25
backend/src/core/database/migrations/20240307043251_create_user_reacts.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* @param { import("knex").Knex } knex | ||
*/ | ||
const tableName = 'user_reacts'; | ||
exports.up = async knex => { | ||
await knex.schema.createTable(tableName, table => { | ||
table | ||
.integer('user_id') | ||
.unsigned() | ||
.notNullable() | ||
.references('id') | ||
.inTable('users') | ||
.onDelete('CASCADE'); | ||
table.integer('reactable_id').unsigned().notNullable(); | ||
table.integer('reactable_type').unsigned().notNullable(); | ||
table.integer('react_type').unsigned().notNullable(); | ||
table.primary(['user_id', 'reactable_id', 'reactable_type']); | ||
}); | ||
}; | ||
/** | ||
* @param { import("knex").Knex } knex | ||
*/ | ||
exports.down = async knex => { | ||
await knex.schema.dropTable(tableName); | ||
}; |
Oops, something went wrong.