Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
51 changes: 50 additions & 1 deletion src/controllers/tsoa.memo-folder.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '../services/memo-folder.service.tsoa.js';
import {memoImageDelete} from '../services/memo-image.service.tsoa.js';
import {bodyToMemoImagesToDelete} from '../dtos/memo-image.dto.tsoa.js';
import {DataValidationError} from '../errors.js';
import {DataValidationError, FolderValidationError} from '../errors.js';
import {
Response,
Body,
Expand Down Expand Up @@ -194,6 +194,19 @@ export class MemoFolderController extends Controller {
data: {folderName: 'string'},
},
})
@Response<ITsoaErrorResponse>(
StatusCodes.BAD_REQUEST,
'유효하지 않은 데이터 에러',
{
resultType: 'FAIL',
success: null,
error: {
errorCode: 'FOL-400',
reason: '폴더명을 1자 이상 입력해야 합니다.',
data: {folderName: ''},
},
},
)
@SuccessResponse(StatusCodes.OK, '폴더 생성 성공 응답')
@Example({
resultType: 'SUCCESS',
Expand All @@ -209,6 +222,11 @@ export class MemoFolderController extends Controller {
): Promise<ITsoaSuccessResponse<MemoFolderResponseDto>> {
try {
const userId = BigInt(req.user!.id);
if (body.folderName === null || body.folderName.trim().length === 0) {
throw new FolderValidationError({
folderName: body.folderName,
});
}
const memoFolder = await memoFolderCreate(userId, bodyToMemoFolder(body));
return new TsoaSuccessResponse(memoFolder);
} catch (error) {
Expand Down Expand Up @@ -507,6 +525,32 @@ export class MemoFolderController extends Controller {
data: {folderName: 'string'},
},
})
@Response<ITsoaErrorResponse>(
StatusCodes.BAD_REQUEST,
'유효하지 않은 검색 키워드 에러',
{
resultType: 'FAIL',
success: null,
error: {
errorCode: 'FOL-400',
reason: '입력 데이터가 유효하지 않습니다.',
data: {folderName: ' '},
},
},
)
@Response<ITsoaErrorResponse>(
StatusCodes.BAD_REQUEST,
'유효하지 않은 데이터 에러',
{
resultType: 'FAIL',
success: null,
error: {
errorCode: 'FOL-400',
reason: '폴더명을 1자 이상 입력해야 합니다.',
data: {folderName: ''},
},
},
)
@SuccessResponse(StatusCodes.OK, '폴더 이름 수정 성공 응답')
@Example({
resultType: 'SUCCESS',
Expand All @@ -530,6 +574,11 @@ export class MemoFolderController extends Controller {
): Promise<ITsoaSuccessResponse<MemoTextImageListResponseDto>> {
try {
const userId = BigInt(req.user!.id);
if (body.folderName === null || body.folderName.trim().length === 0) {
throw new FolderValidationError({
folderName: body.folderName,
});
}
const folderId = BigInt(folderIdParam);
const updatedMemoFolder = await memoFolderUpdate(
userId,
Expand Down
14 changes: 10 additions & 4 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ export class FolderDuplicateError extends BaseError {
}
}

export class FolderValidationError extends BaseError {
constructor(details: {folderName: string}) {
super(400, 'FOL-400', '폴더명을 1자 이상 입력해야 합니다.', details);
}
}

export class FolderNotChangeError extends BaseError {
constructor(details: {folderId: bigint}) {
const errorDetails = {
Expand Down Expand Up @@ -275,28 +281,28 @@ export class NaverGeoCodeError extends BaseError {

// 히스토리 관련 에러
export class NoDataFoundError extends BaseError {
constructor(details: {reason: string}){
constructor(details: {reason: string}) {
super(404, 'HIS-404', '조회를 요청한 데이터가 없습니다.', details);
}
}

// 어워드 중복 에러
export class DuplicateAwardError extends BaseError {
constructor(details: {reason: string}){
constructor(details: {reason: string}) {
super(400, 'HIS-400', '이미 해당 월의 어워드가 존재합니다.', details);
}
}

// 어워드 업데이트 에러
export class AwardUpdateError extends BaseError {
constructor(details: {reason: string}){
constructor(details: {reason: string}) {
super(400, 'HIS-400', '어워드 업데이트를 실패했습니다.', details);
}
}

// 어워드 사진 에러
export class AwardImageError extends BaseError {
constructor(details: {reason: string}){
constructor(details: {reason: string}) {
super(400, 'HIS-400', '어워드 사진 형식이 잘못되었습니다.', details);
}
}
Expand Down
39 changes: 39 additions & 0 deletions swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2214,6 +2214,32 @@
}
}
}
},
"Example 3": {
"value": {
"resultType": "FAIL",
"success": null,
"error": {
"errorCode": "FOL-400",
"reason": "입력 데이터가 유효하지 않습니다.",
"data": {
"folderName": " "
}
}
}
},
"Example 4": {
"value": {
"resultType": "FAIL",
"success": null,
"error": {
"errorCode": "FOL-400",
"reason": "폴더명을 1자 이상 입력해야 합니다.",
"data": {
"folderName": ""
}
}
}
}
}
}
Expand Down Expand Up @@ -2348,6 +2374,19 @@
}
}
}
},
"Example 2": {
"value": {
"resultType": "FAIL",
"success": null,
"error": {
"errorCode": "FOL-400",
"reason": "폴더명을 1자 이상 입력해야 합니다.",
"data": {
"folderName": ""
}
}
}
}
}
}
Expand Down