Skip to content
Merged
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
12 changes: 11 additions & 1 deletion src/repositories/folder.repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class FolderRepository {
});
}

// μœ μ €μ˜ 폴더 개수 쑰회 (κΈ°λ³Έ 폴더 포함됨)
// μœ μ €μ˜ 폴더 개수 쑰회 (κΈ°λ³Έ 폴더 포함)
async countByUserId(userId) {
return await prisma.folder.count({
where: { userId: userId },
Expand All @@ -25,6 +25,16 @@ class FolderRepository {
});
}

// μœ μ €κ°€ νŠΉμ • μ΄λ¦„μ˜ 폴더λ₯Ό 이미 κ°€μ§€κ³  μžˆλŠ”μ§€ 쑰회
async findByUserAndTitle(userId, folderTitle) {
return await prisma.folder.findFirst({
where: {
userId: userId,
folderTitle: folderTitle,
},
});
}

// 1. 폴더 생성
async addFolder(userId, data) {
const newFolder = await prisma.folder.create({
Expand Down
13 changes: 13 additions & 0 deletions src/services/folder.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ class FolderService {

const folderData = FolderDto.bodyToFolderDto(body);

const duplicateNameFolder = await folderRepository.findByUserAndTitle(userId, folderData.folderTitle);
if (duplicateNameFolder) {
throw new BadRequestError("DUPLICATE_NAME", "이미 μ‘΄μž¬ν•˜λŠ” 폴더 μ΄λ¦„μž…λ‹ˆλ‹€.");
}

const duplicateColorFolder = await folderRepository.findByUserAndColor(userId, folderData.color);
if (duplicateColorFolder) {
throw new BadRequestError("DUPLICATE_COLOR", "이미 μ‚¬μš© 쀑인 μƒ‰μƒμž…λ‹ˆλ‹€. λ‹€λ₯Έ 색상을 μ„ νƒν•΄μ£Όμ„Έμš”.");
Expand All @@ -39,6 +44,14 @@ class FolderService {
return FolderDto.responseFromFolder(folder);
}

// 이름이 λ³€κ²½λ˜λŠ” 경우, 쀑볡 이름 확인
if (updateData.folderTitle && updateData.folderTitle !== folder.folderTitle) {
const duplicateNameFolder = await folderRepository.findByUserAndTitle(userId, updateData.folderTitle);
if (duplicateNameFolder) {
throw new BadRequestError("DUPLICATE_NAME", "이미 μ‘΄μž¬ν•˜λŠ” 폴더 μ΄λ¦„μž…λ‹ˆλ‹€.");
}
}

// (4) 색상이 λ³€κ²½λ˜λŠ” κ²½μš°μ—λ§Œ 쀑볡 체크
if (updateData.color && updateData.color !== folder.color) {
const duplicateColorFolder = await folderRepository.findByUserAndColor(userId, updateData.color);
Expand Down
12 changes: 7 additions & 5 deletions src/swagger/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2609,7 +2609,7 @@ paths:
resultType: "FAIL"
code: 400
errorCode: "INVALID_NICKNAME"
reason: "λ‹‰λ„€μž„μ€ μ΅œλŒ€ 10μžκΉŒμ§€λ§Œ κ°€λŠ₯ν•©λ‹ˆλ‹€."
reason: "λ‹‰λ„€μž„μ€ μ΅œλŒ€ 100μžκΉŒμ§€λ§Œ κ°€λŠ₯ν•©λ‹ˆλ‹€."
data: null
'401':
description: |
Expand Down Expand Up @@ -2713,15 +2713,16 @@ paths:
- INVALID_COLOR: 색상 ν˜•μ‹μ΄ μ˜¬λ°”λ₯΄μ§€ μ•ŠμŒ (#123456 ν˜•μ‹ μ•„λ‹˜).
- MAX_FOLDER_LIMIT: 폴더 개수 5개 초과.
- DUPLICATE_COLOR: 이미 μ‚¬μš© 쀑인 색상.
- DUPLICATE_NAME: 이미 μ‚¬μš© 쀑인 폴더 이름.
content:
application/json:
schema:
type: object
example:
resultType: "FAIL"
code: 400
errorCode: "BAD_REQUEST | INVALID_INPUT_VALUE | INVALID_FOLDER_TITLE | COLOR_REQUIRED | INVALID_COLOR | MAX_FOLDER_LIMIT | DUPLICATE_COLOR"
reason: "인증 토큰이 ν˜•μ‹μ— λ§žμ§€ μ•ŠμŠ΅λ‹ˆλ‹€. | 폴더 이름은 ν•„μˆ˜μž…λ‹ˆλ‹€. | 폴더 이름은 μ΅œλŒ€ 11μžκΉŒμ§€λ§Œ κ°€λŠ₯ν•©λ‹ˆλ‹€. | 색상은 ν•„μˆ˜ μž…λ ₯ μ‚¬ν•­μž…λ‹ˆλ‹€. | 색상은 #을 ν¬ν•¨ν•œ 7자리 Hex μ½”λ“œμ—¬μ•Ό ν•©λ‹ˆλ‹€. | ν΄λ”λŠ” μ΅œλŒ€ 5κ°œκΉŒμ§€λ§Œ 생성할 수 μžˆμŠ΅λ‹ˆλ‹€. | 이미 μ‚¬μš© 쀑인 μƒ‰μƒμž…λ‹ˆλ‹€."
errorCode: "BAD_REQUEST | INVALID_INPUT_VALUE | INVALID_FOLDER_TITLE | COLOR_REQUIRED | INVALID_COLOR | MAX_FOLDER_LIMIT | DUPLICATE_COLOR | DUPLICATE_NAME"
reason: "인증 토큰이 ν˜•μ‹μ— λ§žμ§€ μ•ŠμŠ΅λ‹ˆλ‹€. | 폴더 이름은 ν•„μˆ˜μž…λ‹ˆλ‹€. | 폴더 이름은 μ΅œλŒ€ 11μžκΉŒμ§€λ§Œ κ°€λŠ₯ν•©λ‹ˆλ‹€. | 색상은 ν•„μˆ˜ μž…λ ₯ μ‚¬ν•­μž…λ‹ˆλ‹€. | 색상은 #을 ν¬ν•¨ν•œ 7자리 Hex μ½”λ“œμ—¬μ•Ό ν•©λ‹ˆλ‹€. | ν΄λ”λŠ” μ΅œλŒ€ 5κ°œκΉŒμ§€λ§Œ 생성할 수 μžˆμŠ΅λ‹ˆλ‹€. | 이미 μ‚¬μš© 쀑인 μƒ‰μƒμž…λ‹ˆλ‹€. | 이미 μ‘΄μž¬ν•˜λŠ” 폴더 μ΄λ¦„μž…λ‹ˆλ‹€."
data: null
'401':
description: |
Expand Down Expand Up @@ -2815,15 +2816,16 @@ paths:
- INVALID_COLOR: 색상 ν˜•μ‹μ΄ μ˜¬λ°”λ₯΄μ§€ μ•ŠμŒ.
- DUPLICATE_COLOR: 이미 μ‚¬μš© 쀑인 μƒ‰μƒμœΌλ‘œ λ³€κ²½ μ‹œλ„.
- PROTECTED_FOLDER: 'νŒ€' 폴더λ₯Ό μˆ˜μ •ν•˜λ €κ³  μ‹œλ„ν•¨.
- DUPLICATE_NAME: 이미 μ‚¬μš© 쀑인 폴더 μ΄λ¦„μœΌλ‘œ λ³€κ²½ μ‹œλ„.
content:
application/json:
schema:
type: object
example:
resultType: "FAIL"
code: 400
errorCode: "BAD_REQUEST | INVALID_FOLDER_TITLE | INVALID_COLOR | DUPLICATE_COLOR | PROTECTED_FOLDER"
reason: "인증 토큰이 ν˜•μ‹μ— λ§žμ§€ μ•ŠμŠ΅λ‹ˆλ‹€. | 폴더 이름은 μ΅œλŒ€ 11μžκΉŒμ§€λ§Œ κ°€λŠ₯ν•©λ‹ˆλ‹€. | 색상 ν˜•μ‹μ΄ μ˜¬λ°”λ₯΄μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. | 이미 μ‚¬μš© 쀑인 μƒ‰μƒμž…λ‹ˆλ‹€. | 'νŒ€' ν΄λ”λŠ” μˆ˜μ •ν•  수 μ—†μŠ΅λ‹ˆλ‹€."
errorCode: "BAD_REQUEST | INVALID_FOLDER_TITLE | INVALID_COLOR | DUPLICATE_COLOR | PROTECTED_FOLDER | DUPLICATE_NAME"
reason: "인증 토큰이 ν˜•μ‹μ— λ§žμ§€ μ•ŠμŠ΅λ‹ˆλ‹€. | 폴더 이름은 μ΅œλŒ€ 11μžκΉŒμ§€λ§Œ κ°€λŠ₯ν•©λ‹ˆλ‹€. | 색상 ν˜•μ‹μ΄ μ˜¬λ°”λ₯΄μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. | 이미 μ‚¬μš© 쀑인 μƒ‰μƒμž…λ‹ˆλ‹€. | 'νŒ€' ν΄λ”λŠ” μˆ˜μ •ν•  수 μ—†μŠ΅λ‹ˆλ‹€. | 이미 μ‘΄μž¬ν•˜λŠ” 폴더 μ΄λ¦„μž…λ‹ˆλ‹€."
data: null
'401':
description: |
Expand Down