Skip to content
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

registered meme #52

Merged
merged 15 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/controller/meme.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ const getMemeWithKeywords = async (req: CustomRequest, res: Response, next: Next
}
};

const createMeme = async (req: Request, res: Response, next: NextFunction) => {
const createMeme = async (req: CustomRequest, res: Response, next: NextFunction) => {
const user = req.requestedUser;

if (!_.has(req.body, 'title')) {
return next(new CustomError(`'title' field should be provided`, HttpCode.BAD_REQUEST));
}

if (!_.has(req.body, 'image')) {
if (!req.file) {
Hyun-git marked this conversation as resolved.
Show resolved Hide resolved
return next(new CustomError(`'image' field should be provided`, HttpCode.BAD_REQUEST));
}

Expand All @@ -77,8 +79,13 @@ const createMeme = async (req: Request, res: Response, next: NextFunction) => {
return next(new CustomError(`'keywordIds' field should be provided`, HttpCode.BAD_REQUEST));
}

const imageUrl = await MemeService.uploadMeme(req.file);

const createPayload: IMemeCreatePayload = {
...req.body,
deviceId: user.deviceId,
title: req.body.title,
image: imageUrl,
source: req.body.source,
keywordIds: req.body.keywordIds.map((id: string) => new Types.ObjectId(id)),
};

Expand Down
13 changes: 12 additions & 1 deletion src/controller/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,18 @@ const getSavedMemeList = async (req: CustomRequest, res: Response, next: NextFun
}
};

export { getUser, createUser, getLastSeenMemeList, getSavedMemeList };
const getRegisteredMemeList = async (req: CustomRequest, res: Response, next: NextFunction) => {
const user = req.requestedUser;

try {
const memeList = await UserService.getRegisteredMemeList(user);
return res.json(createSuccessResponse(HttpCode.OK, 'Get Registered Meme', memeList));
} catch (err) {
return next(new CustomError(err.message, err.status));
}
};

export { getUser, createUser, getLastSeenMemeList, getSavedMemeList, getRegisteredMemeList };

function getLevel(watch: number, reaction: number, share: number): number {
let level = 1;
Expand Down
6 changes: 6 additions & 0 deletions src/model/meme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@ import mongoose, { Schema, Document, Types } from 'mongoose';
import { IKeywordGetResponse } from './keyword';

export interface IMemeCreatePayload {
deviceId: string;
title: string;
keywordIds: Types.ObjectId[];
image: string;
source: string;
}

export interface IMemeUpdatePayload {
deviceId?: string;
title?: string;
keywordIds?: Types.ObjectId[];
source?: string;
isTodayMeme?: boolean;
}

export interface IMeme {
deviceId?: string;
title: string;
keywordIds: Types.ObjectId[];
image: string;
Expand All @@ -27,6 +30,7 @@ export interface IMeme {

export interface IMemeGetResponse {
_id: Types.ObjectId;
deviceId?: string;
title: string;
image: string;
reaction: number;
Expand All @@ -42,6 +46,7 @@ export interface IMemeGetResponse {

export interface IMemeDocument extends Document {
_id: Types.ObjectId;
deviceId?: string;
title: string;
keywordIds: Types.ObjectId[];
image: string;
Expand All @@ -55,6 +60,7 @@ export interface IMemeDocument extends Document {

const MemeSchema: Schema = new Schema(
{
deviceId: { type: String, default: '' },
title: { type: String, required: true },
keywordIds: { type: [Types.ObjectId], ref: 'Keyword', required: true, default: [] },
image: { type: String, required: true },
Expand Down
115 changes: 42 additions & 73 deletions src/routes/meme.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import express from 'express';
import multer from 'multer';

import {
deleteMeme,
Expand All @@ -21,6 +22,8 @@ import {
} from '../middleware/requestedInfo';

const router = express.Router();
const storage = multer.memoryStorage();
const upload = multer({ storage: storage });

/**
* @swagger
Expand Down Expand Up @@ -611,134 +614,100 @@ router.get('/search/:name', getRequestedUserInfo, searchMemeList); // 밈 검색
* @swagger
* /api/meme:
* post:
* summary: "밈 등록"
* tags: [Meme]
* summary: 밈 생성 (백오피스)
* description: 밈을 생성한다. (백오피스)
* parameters:
* - in: header
* name: x-device-id
* required: true
* schema:
* type: string
* description: "유저의 고유한 deviceId"
* requestBody:
* required: true
* content:
* application/json:
* multipart/form-data:
* schema:
* type: object
* properties:
* title:
* type: string
* example: "무한도전 정총무"
* description: 밈 제목
* description: "밈 제목"
* image:
* type: string
* example: "https://ppac-meme.s3.ap-northeast-2.amazonaws.com/17207029441190.png"
* description: 밈 이미지 주소
* type: file
* description: "밈 이미지 파일"
* source:
* type: string
* example: "무한도전 102화"
* description: 밈 출처
* description: "밈 출처"
* keywordIds:
* type: array
* items:
* type: string
* example: "667fee6dc58681a42d57dc37"
* description: 밈의 키워드 id 목록
* description: "키워드의 ObjectId 배열"
* description: "등록할 키워드의 ObjectId 목록"
* responses:
* 201:
* description: 생성된 밈 정보
* description: "Meme uploaded successfully"
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: string
* example: success
* example: "success"
* code:
* type: integer
* example: 201
* message:
* type: string
* example: Create Meme
* example: "Create Meme"
* data:
* type: object
* properties:
* _id:
* deviceId:
* type: string
* example: "6686af56f7c49ec21e3ef1c1"
* description: 밈 id
* example: "deviceId"
* title:
* type: string
* example: "무한도전 정총무"
* description: 밈 제목
* image:
* type: string
* example: "https://ppac-meme.s3.ap-northeast-2.amazonaws.com/17207029441190.png"
* description: 밈 이미지 주소
* source:
* type: string
* example: "무한도전 102화"
* description: 밈 출처
* example: "폰보는 루피"
* keywordIds:
* type: array
* items:
* type: string
* example: "667fee6dc58681a42d57dc37"
* description: 밈의 키워드 id 목록
* example: "667ff3d1239eeaf78630a283"
* image:
* type: string
* example: "https://ppac-meme.s3.ap-northeast-2.amazonaws.com/1727269791268"
* reaction:
* type: integer
* example: 0
* description: ㅋㅋㅋ 리액션 수 (생성 시 기본값 0)
* source:
* type: string
* example: "google"
* isTodayMeme:
* type: boolean
* example: false
* description: 추천 밈 여부
* isDeleted:
* type: boolean
* example: false
* _id:
* type: string
* example: "66f40b9f775ec854840d0519"
* createdAt:
* type: string
* format: date-time
* example: "2024-07-04T14:19:02.918Z"
* description: 생성 시각
* example: "2024-09-25T13:09:51.472Z"
* updatedAt:
* type: string
* format: date-time
* example: "2024-07-04T14:19:02.918Z"
* description: 업데이트 시각
* example: "2024-09-25T13:09:51.472Z"
* 400:
* description: 잘못된 요청 - requestBody 형식 확인 필요
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: string
* example: error
* code:
* type: integer
* example: 400
* message:
* type: string
* example: title field should be provided
* data:
* type: null
* example: null
* description: "Bad request (missing fields)"
* 500:
* description: Internal server error
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: string
* example: error
* code:
* type: integer
* example: 500
* message:
* type: string
* example: Internal server error
* data:
* type: null
* example: null
* description: "Internal server error"
*/
router.post('/', createMeme); // meme 생성
router.post('/', getRequestedUserInfo, upload.single('image'), createMeme);

/**
* @swagger
Expand Down
Loading
Loading