-
Notifications
You must be signed in to change notification settings - Fork 0
[25.02.28 / TASK-128] Feature - noti app & 공지 API #19
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { NextFunction, Request, RequestHandler, Response } from 'express'; | ||
| import logger from '@/configs/logger.config'; | ||
| import { NotiService } from "@/services/noti.service"; | ||
| import { NotiPostsResponseDto } from "@/types/dto/responses/notiResponse.type"; | ||
|
|
||
| export class NotiController { | ||
| constructor(private notiService: NotiService) { } | ||
|
|
||
| getAllNotiPosts: RequestHandler = async ( | ||
| req: Request, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. request는 DTO를 따로 사용하지 않으신건가요?? 맞다면 그 이유가 궁금합니다!
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. request 가 empty 한 API, 단순 get all 이라서 그렇습니다 :) |
||
| res: Response<NotiPostsResponseDto>, | ||
| next: NextFunction, | ||
| ) => { | ||
| try { | ||
| const result = await this.notiService.getAllNotiPosts(); | ||
| const response = new NotiPostsResponseDto( | ||
| true, | ||
| '전체 noti post 조회에 성공하였습니다.', | ||
| { posts: result }, | ||
| null, | ||
| ); | ||
| res.status(200).json(response); | ||
| } catch (error) { | ||
| logger.error('전체 조회 실패:', error); | ||
| next(error); | ||
| } | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { Pool } from 'pg'; | ||
| import logger from '@/configs/logger.config'; | ||
| import { DBError } from '@/exception'; | ||
|
|
||
| export class NotiRepository { | ||
| constructor(private pool: Pool) { } | ||
|
|
||
| async getAllNotiPosts(limit: number = 5) { | ||
| try { | ||
| const query = ` | ||
| SELECT | ||
| n.id, | ||
| n.title, | ||
| n.content, | ||
| n.created_at | ||
| FROM noti_notipost n | ||
| WHERE n.is_active = true | ||
| ORDER BY n.id DESC | ||
| LIMIT ${limit}; | ||
| `; | ||
|
|
||
| const result = await this.pool.query(query); | ||
| return result.rows; | ||
| } catch (error) { | ||
| logger.error('Noti Repo getAllNotiPosts Error : ', error); | ||
| throw new DBError('알림 조회 중 문제가 발생했습니다.'); | ||
| } | ||
| } | ||
Nuung marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import express, { Router } from 'express'; | ||
| import pool from '@/configs/db.config'; | ||
|
|
||
| import { authMiddleware } from '@/middlewares/auth.middleware'; | ||
| import { NotiRepository } from '@/repositories/noti.repository'; | ||
| import { NotiService } from '@/services/noti.service'; | ||
| import { NotiController } from '@/controllers/noti.controller'; | ||
|
|
||
| /** | ||
| * @swagger | ||
| * tags: | ||
| * name: Notifications | ||
| * description: 알림 관련 API | ||
| */ | ||
| const router: Router = express.Router(); | ||
|
|
||
| const notiRepository = new NotiRepository(pool); | ||
| const notiService = new NotiService(notiRepository); | ||
| const notiController = new NotiController(notiService); | ||
|
|
||
| /** | ||
| * @swagger | ||
| * /notis: | ||
| * get: | ||
| * summary: 공지 게시글 목록 전체 조회 | ||
| * description: 사용자의 알림 게시글 목록을 조회합니다 | ||
| * tags: [Notifications] | ||
| * security: | ||
| * - bearerAuth: [] | ||
| * responses: | ||
| * 200: | ||
| * description: 알림 게시글 목록 조회 성공 | ||
| * content: | ||
| * application/json: | ||
| * schema: | ||
| * $ref: '#/components/schemas/NotiPostsResponseDto' | ||
| * 401: | ||
| * description: 인증되지 않은 사용자 | ||
| * 500: | ||
| * description: 서버 에러 | ||
| */ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. public하게 open하기로 했던 스웨거 코드인건가요?! @Swagger를 사용하는군요! 처음 알고 갑니다!!
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 맞슴니다! 이게 가이드가 안되어 있었어서! http://localhost:8080/api-docs/ 에서 확인가능! |
||
| router.get('/notis', authMiddleware.login, notiController.getAllNotiPosts); | ||
|
|
||
| export default router; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { NotiRepository } from "@/repositories/noti.repository"; | ||
| import { NotiPost } from "@/types/models/NotiPost.type"; | ||
|
|
||
| export class NotiService { | ||
| constructor(private notiRepo: NotiRepository) {} | ||
|
|
||
| async getAllNotiPosts(): Promise<NotiPost[]> { | ||
| return await this.notiRepo.getAllNotiPosts(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { BaseResponseDto } from '@/types/dto/responses/baseResponse.type'; | ||
| import { NotiPost } from '@/types/models/NotiPost.type'; | ||
|
|
||
| /** | ||
| * @swagger | ||
| * components: | ||
| * schemas: | ||
| * NotiPostsResponseData: | ||
| * type: object | ||
| * properties: | ||
| * posts: | ||
| * type: array | ||
| * description: 알림 게시글 목록 | ||
| * items: | ||
| * $ref: '#/components/schemas/NotiPost' | ||
| */ | ||
| interface NotiPostsResponseData { | ||
| posts: NotiPost[]; | ||
| } | ||
|
|
||
| /** | ||
| * @swagger | ||
| * components: | ||
| * schemas: | ||
| * NotiPostsResponseDto: | ||
| * allOf: | ||
| * - $ref: '#/components/schemas/BaseResponseDto' | ||
| * - type: object | ||
| * properties: | ||
| * data: | ||
| * $ref: '#/components/schemas/NotiPostsResponseData' | ||
| */ | ||
| export class NotiPostsResponseDto extends BaseResponseDto<NotiPostsResponseData> { } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| export interface NotiPost { | ||
| id: number; | ||
| title: string; | ||
| content: string; | ||
| created_at: Date; | ||
| // is_active: boolean; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분은 혹시 왜 주석 처리됬을까요?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| // updated_at: Date; | ||
| // author?: User | null; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 저도 위 3개 라인 주석 처리하신 구체적인 이유가 궁금합니다!
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
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.
로컬에서 SSL을 사용하지 않는 구체적인 이유가 궁금합니다!
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.
로컬 SSL (지금 SSL 은 3.0 버전이 마지막이고 이꼴 TLS 1.3 이라고 보시면 됨) 을 하려면 인증서를 발급하고 cert / pem 등 설정이 필요한데, 로컬에 굳이 우리 모두가 힘들어지는 길을 걷기 싫어서랄까요! :)