Skip to content

Commit

Permalink
Merge pull request #519 from Scents-Note/dev
Browse files Browse the repository at this point in the history
dev -> main
  • Loading branch information
neverlish authored Jun 24, 2023
2 parents 8ffcd8a + 03516ba commit 498409c
Show file tree
Hide file tree
Showing 55 changed files with 1,841 additions and 1,583 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"license": "GNU",
"private": true,
"dependencies": {
"@babel/plugin-proposal-decorators": "^7.22.3",
"@types/swagger-ui-express": "^4.1.3",
"@types/winston": "^2.4.4",
"aws-sdk": "^2.1101.0",
Expand Down Expand Up @@ -56,7 +57,6 @@
"@babel/core": "^7.17.8",
"@babel/node": "^7.16.8",
"@babel/plugin-proposal-class-properties": "^7.16.7",
"@babel/plugin-proposal-decorators": "^7.22.3",
"@babel/plugin-proposal-object-rest-spread": "^7.17.3",
"@babel/plugin-transform-runtime": "^7.17.0",
"@babel/preset-env": "^7.16.11",
Expand Down
155 changes: 151 additions & 4 deletions src/controllers/Admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,32 @@ import { AdminService } from '@src/service/AdminService';
import PerfumeService from '@src/service/PerfumeService';
import StatusCode from '@src/utils/statusCode';
import {
MSG_EXIST_DUPLICATE_ENTRY,
MSG_GET_ADDED_PERFUME_RECENT_SUCCESS,
MSG_GET_PERFUME_DETAIL_SUCCESS,
MSG_GET_SEARCH_INGREDIENT_SUCCESS,
MSG_LOGIN_SUCCESS,
} from '@src/utils/strings';
import { NextFunction, Request, RequestHandler, Response } from 'express';
import {
IngredientCategoryResponse,
IngredientFullResponse,
// IngredientResponse,
LoginResponse,
PerfumeDetailResponse,
PerfumeResponse,
ResponseDTO,
SimpleResponseDTO,
} from './definitions/response';
import { ListAndCountDTO } from '@src/data/dto';
import IngredientCategoryService from '@src/service/IngredientCategoryService';
import { DuplicatedEntryError } from '@src/utils/errors/errors';

let Admin: AdminService = new AdminService();
let Perfume: PerfumeService = new PerfumeService();
let Ingredient: IngredientService = new IngredientService();
let IngredientCategory: IngredientCategoryService =
new IngredientCategoryService();

/**
* @swagger
Expand Down Expand Up @@ -160,10 +168,10 @@ export const getPerfume: RequestHandler = async (
* in: query
* required: false
* type: string
# enum:
# - id
# - name
# - englishName
* enum:
* - id
* - name
* - englishName
* - name: keyword
* in: query
* required: false
Expand Down Expand Up @@ -290,3 +298,142 @@ export const getIngredientAll: RequestHandler = async (
)
);
};

/**
*
* @swagger
* /admin/ingredientCategories:
* get:
* tags:
* - admin
* summary: 재료 카테고리 목록 조회
* description: 재료 카테고리 리스트 조회 <br /> 반환 되는 정보 [재료]
* operationId: getIngredientCategoryList
* produces:
* - application/json
* parameters:
* - name: page
* in: query
* required: true
* type: integer
* format: int64
* - name: target
* in: query
* required: false
* type: string
* enum:
* - id
* - name
* - name: keyword
* in: query
* required: false
* type: string
* responses:
* 200:
* description: 성공
* schema:
* type: object
* properties:
* message:
* type: string
* example: Ingredient Category 목록 조회 성공
* data:
* type: object
* properties:
* count:
* type: integer
* example: 1
* rows:
* type: array
* items:
* allOf:
* - $ref: '#/definitions/IngredientResponse'
* 401:
* description: Token is missing or invalid
* x-swagger-router-controller: Admin
*/
export const getIngredientCategoryList: RequestHandler = async (
req: Request,
res: Response,
next: NextFunction
) => {
const page: number = Number(req.query.page);
if (isNaN(page)) {
next();
return;
}
const limit = 20;
const offset = (page - 1) * limit;

const categories = await IngredientCategory.readPage(
offset,
limit,
req.query
);

res.status(StatusCode.OK).json(
new ResponseDTO<ListAndCountDTO<IngredientCategoryResponse>>(
MSG_GET_SEARCH_INGREDIENT_SUCCESS,
categories.convertType(IngredientCategoryResponse.create)
)
);
};

/**
* @swagger
* /admin/ingredientCategories:
* post:
* tags:
* - admin
* summary: 재료 카테고리 추가
* description: 재료 카테고리 추가
* operationId: createIngredientCategory
* produces:
* - application/json
* parameters:
* - name: body
* in: body
* required: true
* schema:
* type: object
* properties:
* name:
* type: string
* responses:
* 200:
* description: success
* schema:
* type: object
* properties:
* message:
* type: string
* 400:
* description: 요청 실패
* 409:
* description: 같은 이름의 카테고리가 존재할 때
* schema:
* type: object
* x-swagger-router-controller: Admin
*/
export const createIngredientCategory: RequestHandler = async (
req: Request,
res: Response
) => {
const { name } = req.body;
try {
await IngredientCategory.create(name);
res.status(StatusCode.OK).json({
message: '성공',
});
} catch (e: any) {
if (e instanceof DuplicatedEntryError) {
res.status(StatusCode.CONFLICT).json(
new ResponseDTO(MSG_EXIST_DUPLICATE_ENTRY, false)
);
} else {
res.status(StatusCode.BAD_REQUEST).json(
new SimpleResponseDTO(e.message)
);
}
}
};
31 changes: 0 additions & 31 deletions src/controllers/Keyword.js

This file was deleted.

45 changes: 45 additions & 0 deletions src/controllers/Keyword.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict';

import KeywordService from '../service/KeywordService';
import { DEFAULT_PAGE_SIZE } from '@src/utils/constants';
import StatusCode from '../utils/statusCode';
import { NextFunction, Request, Response } from 'express';

const Keyword = new KeywordService();

export const getKeywordAll = async (
req: Request,
res: Response,
next: NextFunction
) => {
const pagingIndex = parseInt(req.query.pagingIndex?.toString() ?? '1');
const pagingSize = parseInt(
req.query.pagingSize?.toString() ?? `${DEFAULT_PAGE_SIZE}`
);
try {
const response = await Keyword.getKeywordAll(pagingIndex, pagingSize);
res.status(StatusCode.OK).json({
message: '키워드 목록 전체 조회 성공',
data: response,
});
} catch (err) {
next(err);
}
};

export const getKeywordOfPerfume = async (
req: Request,
res: Response,
next: NextFunction
) => {
const perfumeIdx = parseInt(req.params['perfumeIdx']);
try {
const response = await Keyword.getKeywordOfPerfume(perfumeIdx);
res.status(StatusCode.OK).json({
message: '향수별 키워드 전체 조회 성공',
data: response,
});
} catch (err) {
next(err);
}
};
4 changes: 3 additions & 1 deletion src/controllers/Perfume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ import {
DEFAULT_NEW_PERFUME_REQUEST_SIZE,
} from '@utils/constants';
import _ from 'lodash';
import { LikePerfumeService } from '@src/service/LikePerfumeService';

const LOG_TAG: string = '[Perfume/Controller]';

let Perfume: PerfumeService = new PerfumeService();
let SearchHistory: SearchHistoryService = new SearchHistoryService();
const LikePerfume: LikePerfumeService = new LikePerfumeService();

/**
* @swagger
Expand Down Expand Up @@ -343,7 +345,7 @@ const likePerfume: RequestHandler = (
req.params
)})`
);
Perfume.likePerfume(loginUserIdx, perfumeIdx)
LikePerfume.likePerfume(loginUserIdx, perfumeIdx)
.then((result: boolean) => {
LoggerHelper.logTruncated(
logger.debug,
Expand Down
Loading

0 comments on commit 498409c

Please sign in to comment.