-
Notifications
You must be signed in to change notification settings - Fork 0
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
[GET] /notice/service?lastid=&size= 서비스 알림 조회 #22
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f0f892f
feat: 서비스 알림 읽음처리 api 작성
youngkwon02 9f309d0
style: serviceNoticeRead res message
youngkwon02 9ab0c47
fix: notification router relative path error
youngkwon02 eb4f61e
style: activeNoticeRead res message
youngkwon02 e5be423
feat: 활동 알림 읽음처리 api
youngkwon02 b17e287
feat: 서비스 알림 조회 without pagination
youngkwon02 52d56fe
feat: 서비스 알림 조회 Pagination
youngkwon02 bb067c0
refactor: 서비스 알림 조회 using Array.map
youngkwon02 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 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,34 @@ | ||
const functions = require('firebase-functions'); | ||
const util = require('../../../../lib/util'); | ||
const statusCode = require('../../../../constants/statusCode'); | ||
const responseMessage = require('../../../../constants/responseMessage'); | ||
const db = require('../../../../db/db'); | ||
const { noticeDB } = require('../../../../db'); | ||
|
||
/** | ||
* @활동_알림_읽음_처리 | ||
* @route PATCH /notice/active/read | ||
* @body | ||
* @error | ||
*/ | ||
|
||
module.exports = async (req, res) => { | ||
const user = req.user; | ||
const userId = user.userId; | ||
|
||
let client; | ||
|
||
try { | ||
client = await db.connect(req); | ||
await noticeDB.activeReadByUserId(client, userId); | ||
|
||
res.status(statusCode.OK).send(util.success(statusCode.OK, responseMessage.ACTIVE_READ_SUCCESS)); | ||
} catch (error) { | ||
functions.logger.error(`[ERROR] [${req.method.toUpperCase()}] ${req.originalUrl}`, `[CONTENT] ${error}`); | ||
console.log(error); | ||
|
||
res.status(statusCode.INTERNAL_SERVER_ERROR).send(util.fail(statusCode.INTERNAL_SERVER_ERROR, responseMessage.INTERNAL_SERVER_ERROR)); | ||
} finally { | ||
client.release(); | ||
} | ||
}; |
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,7 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const { checkUser } = require('../../../../middlewares/auth'); | ||
|
||
router.patch('/read', checkUser, require('./activeReadPATCH')); | ||
|
||
module.exports = router; |
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,6 +1,7 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
|
||
// router.post('/signup', require('./userSignupPOST')); | ||
router.use('/active', require('./active')); | ||
router.use('/service', require('./service')); | ||
|
||
module.exports = router; |
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,8 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const { checkUser } = require('../../../../middlewares/auth'); | ||
|
||
router.get('', checkUser, require('./serviceGET')); | ||
router.patch('/read', checkUser, require('./serviceReadPATCH')); | ||
|
||
module.exports = router; |
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,47 @@ | ||
const functions = require('firebase-functions'); | ||
const util = require('../../../../lib/util'); | ||
const statusCode = require('../../../../constants/statusCode'); | ||
const responseMessage = require('../../../../constants/responseMessage'); | ||
const db = require('../../../../db/db'); | ||
const { noticeDB } = require('../../../../db'); | ||
|
||
/** | ||
* @서비스_알림_조회 | ||
* @route GET /notice/service?lastid=&size= | ||
* @error | ||
*/ | ||
|
||
module.exports = async (req, res) => { | ||
const user = req.user; | ||
const userId = user.userId; | ||
const { lastid, size } = req.query; | ||
|
||
let client; | ||
|
||
try { | ||
client = await db.connect(req); | ||
|
||
const services = await noticeDB.getServicesByUserId(client, userId, lastid, size); | ||
const notices = []; | ||
|
||
for (let i = 0; i < services.length; i++) { | ||
const service = services[i]; | ||
const notice = { | ||
noticeId: service.notificationId, | ||
noticeTitle: service.title, | ||
noticeImg: service.thumbnail, | ||
noticeContent: service.content, | ||
createdAt: service.createdAt.toISOString().split('T')[0].replace(/-/g, '/'), | ||
}; | ||
notices.push(notice); | ||
} | ||
|
||
res.status(statusCode.OK).send(util.success(statusCode.OK, responseMessage.SERVICE_GET_SUCCESS, { notices })); | ||
} catch (error) { | ||
functions.logger.error(`[ERROR] [${req.method.toUpperCase()}] ${req.originalUrl}`, `[CONTENT] ${error}`); | ||
console.log(error); | ||
res.status(statusCode.INTERNAL_SERVER_ERROR).send(util.fail(statusCode.INTERNAL_SERVER_ERROR, responseMessage.INTERNAL_SERVER_ERROR)); | ||
} finally { | ||
client.release(); | ||
} | ||
}; |
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,34 @@ | ||
const functions = require('firebase-functions'); | ||
const util = require('../../../../lib/util'); | ||
const statusCode = require('../../../../constants/statusCode'); | ||
const responseMessage = require('../../../../constants/responseMessage'); | ||
const db = require('../../../../db/db'); | ||
const { noticeDB } = require('../../../../db'); | ||
|
||
/** | ||
* @서비스_알림_읽음_처리 | ||
* @route PATCH /notice/service/read | ||
* @body | ||
* @error | ||
*/ | ||
|
||
module.exports = async (req, res) => { | ||
const user = req.user; | ||
const userId = user.userId; | ||
|
||
let client; | ||
|
||
try { | ||
client = await db.connect(req); | ||
await noticeDB.serviceReadByUserId(client, userId); | ||
|
||
res.status(statusCode.OK).send(util.success(statusCode.OK, responseMessage.SERVICE_READ_SUCCESS)); | ||
} catch (error) { | ||
functions.logger.error(`[ERROR] [${req.method.toUpperCase()}] ${req.originalUrl}`, `[CONTENT] ${error}`); | ||
console.log(error); | ||
|
||
res.status(statusCode.INTERNAL_SERVER_ERROR).send(util.fail(statusCode.INTERNAL_SERVER_ERROR, responseMessage.INTERNAL_SERVER_ERROR)); | ||
} finally { | ||
client.release(); | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
module.exports = { | ||
userDB: require('./user'), | ||
roomDB: require('./room'), | ||
noticeDB: require('./notice'), | ||
}; |
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,53 @@ | ||
const _ = require('lodash'); | ||
const convertSnakeToCamel = require('../lib/convertSnakeToCamel'); | ||
|
||
const serviceReadByUserId = async (client, userId) => { | ||
const { rows } = await client.query( | ||
` | ||
UPDATE spark.notification | ||
SET is_read = TRUE, read_at = now(), updated_at = now() | ||
WHERE is_read = FALSE | ||
AND is_deleted = FALSE | ||
AND is_service = TRUE | ||
AND receiver_id = $1 | ||
RETURNING * | ||
`, | ||
[userId], | ||
); | ||
return convertSnakeToCamel.keysToCamel(rows); | ||
}; | ||
|
||
const activeReadByUserId = async (client, userId) => { | ||
const { rows } = await client.query( | ||
` | ||
UPDATE spark.notification | ||
SET is_read = TRUE, read_at = now(), updated_at = now() | ||
WHERE is_read = FALSE | ||
AND is_deleted = FALSE | ||
AND is_service = FALSE | ||
AND receiver_id = $1 | ||
RETURNING * | ||
`, | ||
[userId], | ||
); | ||
return convertSnakeToCamel.keysToCamel(rows); | ||
}; | ||
|
||
const getServicesByUserId = async (client, userId, lastid, size) => { | ||
const { rows } = await client.query( | ||
` | ||
SELECT * FROM spark.notification | ||
WHERE receiver_id = $1 | ||
AND is_deleted = FALSE | ||
AND is_service = TRUE | ||
AND notification_id < $2 | ||
AND created_at > current_timestamp + '-7 days' | ||
ORDER BY notification_id DESC | ||
LIMIT $3 | ||
`, | ||
[userId, lastid, size], | ||
); | ||
return convertSnakeToCamel.keysToCamel(rows); | ||
}; | ||
|
||
module.exports = { serviceReadByUserId, activeReadByUserId, getServicesByUserId }; |
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.
for문대신 .map 을 사용해도 좋을 것 같아 보여요!
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.
@xxeol2
map 사용해서 리팩터링 완료했는데, 잘 적용한건지 모르겠네요~!
감사합니당 :)
혹시 더 좋은 사용법 있으면 공유 부탁드려요!!! 😉