forked from pokers/backend_template
-
Notifications
You must be signed in to change notification settings - Fork 2
[BMOL-28] POST v1/oneliner 구현 #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SeongEon-Kim
wants to merge
3
commits into
main
Choose a base branch
from
BMOL-28
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,54 @@ | ||
| const { OnelinerService } = require('../services') | ||
|
|
||
|
|
||
| const postOneliner = async (ctx) => { | ||
| const userId = ctx.request.headers.user_id; | ||
|
|
||
| const { | ||
| book_id, | ||
| title, | ||
| authors, | ||
| oneliner, | ||
| color, | ||
| top, | ||
| left, | ||
| font, | ||
| font_size, | ||
| bg_image_url | ||
| } = ctx.request.body; | ||
|
|
||
| const onelinerService = new OnelinerService(); | ||
|
|
||
| const result = await onelinerService.postOneliner(userId, book_id, | ||
| title, | ||
| authors, | ||
| oneliner, | ||
| color, | ||
| top, | ||
| left, | ||
| font, | ||
| font_size, | ||
| bg_image_url); | ||
|
|
||
| const data = { | ||
| oneliner: | ||
| result.data | ||
|
|
||
| } | ||
| const meta = { | ||
| sortType: "latest", | ||
| continuousToken: "0", | ||
| currentPage: "0", | ||
| requestId: ctx.state.requestId, | ||
| now: +new Date(), | ||
| }; | ||
|
|
||
| ctx.body = { | ||
| data: data, | ||
| meta | ||
| }; | ||
| }; | ||
|
|
||
| module.exports = { | ||
| postOneliner | ||
| } | ||
This file contains hidden or 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 hidden or 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,46 @@ | ||
| const { OnelinerRepository } = require('./repositories/onelinerRepository') | ||
|
|
||
| class OnelinerDao { | ||
| constructor(){ | ||
| this._daoName = 'OnelinerDao' | ||
| } | ||
|
|
||
| get daoName(){ | ||
| return this._daoName | ||
| } | ||
|
|
||
|
|
||
| async postOneliner(userId, book_id, title, authors,oneliner, color,top,left,font,font_size,bg_image_url){ | ||
|
|
||
| const OnelinerRepo = new OnelinerRepository(); | ||
| const userInfo = await OnelinerRepo.getUserInfoByUserId(userId); | ||
|
|
||
| const profileImageUrlJSON = JSON.stringify(userInfo[0].profile_image_url); | ||
| const nicknameJSON = JSON.stringify(userInfo[0].nickname); | ||
| const authorsJSON = JSON.stringify(authors); | ||
|
|
||
| const onelinerInfo = await OnelinerRepo.postOneliner( | ||
| profileImageUrlJSON, | ||
| nicknameJSON, | ||
| userId, | ||
| book_id, | ||
| title, | ||
| authorsJSON, | ||
| oneliner, | ||
| color, | ||
| top, | ||
| left, | ||
| font, | ||
| font_size, | ||
| bg_image_url) | ||
|
|
||
| const onelinerInfoResult = await OnelinerRepo.getOnelinerInfoByBookId(onelinerInfo.book_id) | ||
|
|
||
| const result = { | ||
| data : onelinerInfoResult, | ||
| } | ||
| return result | ||
| } | ||
| } | ||
|
|
||
| module.exports = { OnelinerDao } |
This file contains hidden or 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,65 @@ | ||
| const pgClient = require('../connections/postgresql') | ||
|
|
||
| class OnelinerRepository { | ||
| constructor(){ | ||
| this._repositoryName = 'OnelinerRepository' | ||
| } | ||
| get name(){ | ||
| return this._repositoryName | ||
| } | ||
| // 결과 호출을 위한 쿼리 | ||
| async getOnelinerInfoByBookId(book_id){ | ||
| const query = pgClient.select('*') | ||
| .from('tbl_oneliner') | ||
| .where('tbl_oneliner.book_id', book_id) | ||
| return query | ||
| } | ||
| // UserInfo를 가져오기 위한 쿼리 (profile_image, nickname) | ||
| async getUserInfoByUserId(user_id){ | ||
| const query = pgClient.select('profile_image_url','nickname') | ||
| .from('tbl_account') | ||
| .where('tbl_account.id', user_id) | ||
| return query | ||
| } | ||
|
|
||
| async postOneliner( | ||
| profile_image_url, | ||
| nickname, | ||
| userId, | ||
| book_id, | ||
| title, | ||
| authors, | ||
| oneliner, | ||
| color, | ||
| top, | ||
| left, | ||
| font, | ||
| font_size, | ||
| bg_image_url) { | ||
|
|
||
| const query = pgClient('tbl_oneliner').insert({ | ||
| id: pgClient.raw("gen_random_uuid()"), | ||
| user_id: userId, | ||
| profile_image: profile_image_url, | ||
| nickname: nickname, | ||
| book_id: book_id, | ||
| title: title, | ||
| authors: authors, | ||
| oneliner: oneliner, | ||
| color: color, | ||
| top: top, | ||
| left: left, | ||
| font: font, | ||
| font_size: font_size, | ||
| bg_image_url: bg_image_url | ||
| }).returning('book_id'); | ||
| const result = await query; // 쿼리 실행 및 결과 받기 | ||
|
|
||
| return result[0]; // book_id 반환 | ||
| } | ||
|
|
||
| } | ||
|
|
||
| module.exports = { | ||
| OnelinerRepository, | ||
| }; |
This file contains hidden or 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 hidden or 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,15 @@ | ||
| const Router = require("koa-router"); | ||
| const onelinerController = require("../../controllers/onelinerController"); | ||
|
|
||
| const onelinerRouteAPIV1 = (root)=>{ | ||
| const router = Router(); | ||
|
|
||
| router.post('/', onelinerController.postOneliner); | ||
|
|
||
| root.use('/oneliner', router.routes()) | ||
| } | ||
|
|
||
| const onelinerRouteV1 = (root)=>{ | ||
| onelinerRouteAPIV1(root) | ||
| } | ||
| module.exports = { onelinerRouteV1 } |
This file contains hidden or 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 hidden or 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 @@ | ||
| const { | ||
| OnelinerDao | ||
| } = require("../dao/onelinerDao"); | ||
|
|
||
| const validator = require('validator') | ||
| const { InvalidUUID, AccountNotFound, MyBookNotFound } = require('./errorService'); | ||
|
|
||
| class OnelinerService { | ||
| constructor(){ | ||
| this._serviceName = 'onelinerService' | ||
| } | ||
|
|
||
| get serviceName(){ | ||
| return this._serviceName | ||
| } | ||
|
|
||
| async postOneliner(userId, book_id, title, authors, oneliner, color, top, left, font, font_size, bg_image_url){ | ||
|
||
| const onelinerDao = new OnelinerDao() | ||
| const onelinerRows = await onelinerDao.postOneliner( | ||
| userId, | ||
| book_id, | ||
| title, | ||
| authors, | ||
| oneliner, | ||
| color, | ||
| top, | ||
| left, | ||
| font, | ||
| font_size, | ||
| bg_image_url) | ||
|
|
||
| return onelinerRows | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
| module.exports = { OnelinerService }; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이렇게 함수 parameter가 많은경우 object로 묶어서 전달하는게 좋아요
const result = await onelinerService.postOneliner({userId, book_id, title, authors, oneliner, color, top, left, font, font_size, bg_image_url});