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

Dev #40

Merged
merged 81 commits into from
Jul 7, 2024
Merged

Dev #40

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
1eba491
db
grulla99 Jun 23, 2024
3cb3c08
1
grulla99 Jun 23, 2024
dc72adb
merge branch 'dev' into sean
grulla99 Jun 23, 2024
60d7653
Merge branch 'dev' into sean
grulla99 Jun 27, 2024
6b7afd1
Merge branch 'dev' into sean
grulla99 Jun 30, 2024
675e8b5
Merge branch 'dev' into sean
grulla99 Jul 1, 2024
eda1134
Merge branch 'dev' into feature/requests
grulla99 Jul 1, 2024
6b3b9ac
Merge branch 'dev' into feature/requests
grulla99 Jul 2, 2024
ce9d792
✨ word 에러 메세지 추가
dev-Rhea Jul 2, 2024
24989c0
✨ 전체 단어목록 조회 추가
dev-Rhea Jul 2, 2024
6ce603d
✨ 전체 단어목록 경로 설정
dev-Rhea Jul 2, 2024
9f65a26
merge
dev-Rhea Jul 2, 2024
1dd8ab3
✨ 단어 조회 메세지 추가
dev-Rhea Jul 2, 2024
fd0ee0e
✨ 단어 목록 조회 함수 추가
dev-Rhea Jul 2, 2024
31243fc
✨ 단어 목록 조회 & 정렬 함수 추가
dev-Rhea Jul 2, 2024
27f1dd9
✨ 단어 목록 조회 함수 추가
dev-Rhea Jul 2, 2024
59fe458
✨ 전체 단어 목록 경로 추가
dev-Rhea Jul 2, 2024
45a1747
⚡️ Merge remote-tracking branch 'origin/dev' into feature/words
dev-Rhea Jul 2, 2024
cc5de14
Merge remote-tracking branch 'origin/main' into feature/words
dev-Rhea Jul 2, 2024
efe575d
🚧 요청목록작업
grulla99 Jul 2, 2024
4284afe
🚧 요청목록작업
grulla99 Jul 2, 2024
6ba7442
Merge remote-tracking branch 'refs/remotes/origin/dev' into dev
grulla99 Jul 2, 2024
ca984c7
Merge branch 'dev' into feature/requests
grulla99 Jul 2, 2024
a1a43e2
🐛 오타수정
grulla99 Jul 4, 2024
522221d
✨ 요청목록 api 및 오타수정
grulla99 Jul 4, 2024
b95a1c2
🔥 주석삭제
grulla99 Jul 4, 2024
0f8282e
🔥 오타삭제
grulla99 Jul 4, 2024
e18e133
💬 성공 에러 메세지 추가
grulla99 Jul 5, 2024
e420b77
✨ 사용자 요청정보, 모든 사용자 요청정보, 요청 삭제, 사용자 역할 가져오기 로직구현
grulla99 Jul 5, 2024
e57188a
🎨등로요청 로직 추가
trueS2 Jul 6, 2024
613f6a4
♻️ 등록 요청 로직 수정
trueS2 Jul 6, 2024
b34226e
🎨 함수명 변경 & 수정
dev-Rhea Jul 6, 2024
3d84510
✨ 사용자 요청 수정 구현
grulla99 Jul 6, 2024
01ce52b
Merge branch 'dev' into feature/requests-true
trueS2 Jul 6, 2024
1e8e6cf
Merge remote-tracking branch 'origin/main' into feature/words
dev-Rhea Jul 6, 2024
4487240
Merge remote-tracking branch 'origin/dev' into dev
grulla99 Jul 6, 2024
24dd243
🐛 Merge branch 'dev' into feature/requests ////컴플릭트해결
grulla99 Jul 6, 2024
a26cba2
🔥 코드 수정 및 삭제
grulla99 Jul 6, 2024
931f200
♻️ 오타 수정
trueS2 Jul 6, 2024
00dca2c
🔥 word에 있는 등록 요청 삭제
trueS2 Jul 6, 2024
08bcae7
🎨 등록 요청 모달 추가
trueS2 Jul 6, 2024
39f9f3d
♻️ 등록요청API 완료
trueS2 Jul 7, 2024
8ae7eb2
🎨 수정요청 API 시작
trueS2 Jul 7, 2024
c386b53
♻️ 등록요청 수정 및 완료
trueS2 Jul 7, 2024
4cd37bd
✅ 요청 성공, 실패 에러메세지 추가
grulla99 Jul 7, 2024
d646e18
✨ 요청상태 변경 구현
grulla99 Jul 7, 2024
0f4160d
🗃️ db 스키마 request 도큐먼트 suggestedBy 추가
grulla99 Jul 7, 2024
f38ee50
Merge pull request #34 from sen2y/feature/seny
sen2y Jul 7, 2024
f612f2b
✨ 승인된단어 word 추가 로직 구현
grulla99 Jul 7, 2024
91bec5d
🎨 닉네임 추가(완성전)
trueS2 Jul 7, 2024
3811e1a
🎨닉네임 추가
trueS2 Jul 7, 2024
3b0e4a0
Merge branch 'dev' into feature/requests-true
trueS2 Jul 7, 2024
2ec8280
🎨 변수명 변경
dev-Rhea Jul 7, 2024
6978bb5
🔥 머지 잘못해서 생긴 중복코드 삭제
dev-Rhea Jul 7, 2024
63e2610
🎨 변수명 변경
dev-Rhea Jul 7, 2024
7fcde65
Merge remote-tracking branch 'origin/dev' into feature/words
dev-Rhea Jul 7, 2024
5ecca81
🔥 request_id 삭제
grulla99 Jul 7, 2024
199d39b
♻️ 닉네임 추가 코드 수정 완료
trueS2 Jul 7, 2024
a1ba0e8
Merge remote-tracking branch 'origin/main' into feature/requests
grulla99 Jul 7, 2024
e632393
Merge remote-tracking branch 'origin/dev' into feature/requests
grulla99 Jul 7, 2024
2adff7d
🎨 등록&수정 요청 추가
trueS2 Jul 7, 2024
f3f6261
Merge pull request #35 from Murakano/feature/requests
grulla99 Jul 7, 2024
37fa2ce
♻️ 수정요청 수정
trueS2 Jul 7, 2024
33ad584
🎨 Merge remote-tracking branch 'origin/dev' into feature/words
dev-Rhea Jul 7, 2024
bdccfd7
💡 주석 추가
dev-Rhea Jul 7, 2024
455ffa0
🎨 철자 수정
dev-Rhea Jul 7, 2024
a62d391
⚡️ 검증 함수 추가
dev-Rhea Jul 7, 2024
8dba6b9
🎨 변수 수정
dev-Rhea Jul 7, 2024
48bdfb2
♻️ 등록&요청 API수정
trueS2 Jul 7, 2024
236e9a5
♻️ 등록&수정 요청 API 완성
trueS2 Jul 7, 2024
436b8fe
🔥 등록&수정 요청 API 필요없는 코드 지우기
trueS2 Jul 7, 2024
bd5ec4e
♻️ 등록&수정 요청 최종
trueS2 Jul 7, 2024
d7f5ace
Merge pull request #36 from Murakano/feature/words
dev-Rhea Jul 7, 2024
5968aba
Merge branch 'dev' into feature/requests-true
trueS2 Jul 7, 2024
5981b1b
x
trueS2 Jul 7, 2024
8743a47
⚡️ 관리자 반려, 승인 추가
grulla99 Jul 7, 2024
da8bfe3
Merge remote-tracking branch 'origin/dev' into feature/requests
grulla99 Jul 7, 2024
feea058
Merge pull request #37 from Murakano/feature/requests
grulla99 Jul 7, 2024
c9ffc18
Merge branch 'dev' into feature/requests-true
trueS2 Jul 7, 2024
24494bb
🔀 충돌 해결
trueS2 Jul 7, 2024
2ac4354
Merge pull request #39 from Murakano/feature/requests-true
trueS2 Jul 7, 2024
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
2 changes: 0 additions & 2 deletions README.md

This file was deleted.

7 changes: 7 additions & 0 deletions src/common/constants/error-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,15 @@ const ErrorMessage = Object.freeze({
RECENT_WORDS_ERROR: '최근 검색어 조회중 오류가 발생하였습니다.',
DELETE_RECENT_WORD_ERROR: '최근 검색어 삭제중 오류가 발생하였습니다.',
SEARCH_WORDS_ERROR: '검색 결과 조회 중 오류가 발생하였습니다.',
GET_WORDS_ERROR: '단어 조회 중 오류가 발생하였습니다.',
RANK_WORDS_ERROR: '인기 검색어 조회 중 오류가 발생하였습니다.',
RELATED_WORDS_ERROR: '연관 검색어 조회 중 오류가 발생하였습니다.',
REGISTER_WORDS_ERROR: '등록 요청 중 오류가 발생하였습니다.',

// REQUEST
GET_REQUESTS_ERROR: '요청 조회중 오류가 발생하였습니다.',
DELETE_REQUEST_ERROR: '요청 삭제중 오류가 발생하였습니다.',
UPDATE_REQUEST_STATE_ERROR: '요청 상태 변경중 오류가 발생하였습니다.',
});

module.exports = ErrorMessage;
17 changes: 15 additions & 2 deletions src/common/constants/success-message.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const SucesssMessage = Object.freeze({
const SuccessMessage = Object.freeze({
// USER - 회원가입
REGISTER_SUCCESSS: '회원가입 성공',
AVAILABLE_NICKNAME: '사용 가능한 닉네임입니다.',
Expand All @@ -20,7 +20,20 @@ const SucesssMessage = Object.freeze({
SEARCH_WORDS_SUCCESS: '검색어 조회 성공',
SEARCH_WORDS_NONE: '검색 결과가 없습니다.',
RANK_WORDS_SUCCESS: '인기 검색어 조회 성공',

// REQUEST - 요청
DELETE_REQUEST_SUCCESS: '요청 삭제 성공',
GET_REQUESTS_SUCCESS: '요청 조회 성공',
GET_ROLE_SUCCESS: '사용자 역할 조회 성공',
UPDATE_REQUEST_SUCCESS: '요청 수정 성공',
UPDATE_REQUEST_STATE_SUCCESS: '요청 상태 변경 성공',

// WORD - 조회
GET_WORDS_SUCCESS: '단어 조회 성공',
RELATED_WORDS_SUCCESS: '연관 검색어 조회 성공',

// Word - 등록요청
REGISTER_WORDS_SUCCESS: '등록 요청 성공',
});

module.exports = SucesssMessage;
module.exports = SuccessMessage;
1 change: 1 addition & 0 deletions src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ router.use('/users', userRouter);

router.use('/words', wordRouter);


// EB health check
router.get('/', (_, res) => {
res.status(200).json({ message: 'Success' });
Expand Down
95 changes: 95 additions & 0 deletions src/routes/user/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const passport = require('passport');
const jwt = require('jsonwebtoken');
const config = require('../../common/config');


const userService = require('./user.service');
const sendResponse = require('../../common/utils/response-handler');
const ErrorMessage = require('../../common/constants/error-message');
Expand Down Expand Up @@ -218,3 +219,97 @@ exports.delRecentSearch = async (req, res) => {
sendResponse.fail(req, res, ErrorMessage.DELETE_RECENT_WORD_ERROR);
}
};

// 새로운 단어 등록 및 수정
exports.postWords = async (req, res) => {
try {
const { _id } = req.user;
const { nickname } = req.params; // URL 파라미터에서 nickname 추출
const { formData, type } = req.body; // formData와 type을 요청 본문에서 분리

const result = await userService.postWords(_id, formData, nickname, type);

sendResponse.ok(res, {
message: SuccessMessage.REGISTER_WORDS_SUCCESS,
data: result
});
} catch (error) {
console.log("Error during postWords:", error);
sendResponse.fail(req, res, ErrorMessage.REGISTER_WORDS_ERROR);
}
};
exports.UserRequests = async (req, res) => {
try{
const { _id } = req.user;
const requests = await userService.getUserRequests(_id);
sendResponse.ok(res, {
message: SuccessMessage.GET_REQUESTS_SUCCESS,
data: { requests },
});
} catch (err) {
console.log(err);
sendResponse.fail(req, res, ErrorMessage.GET_REQUESTS_ERROR);
}
};

exports.UserRequestsAll = async (req, res) => {
try{
const requests = await userService.getUserRequestsAll();
sendResponse.ok(res, {
message: SuccessMessage.GET_REQUESTS_SUCCESS,
data: { requests },
});
} catch (err) {
console.log(err);
sendResponse.fail(req, res, ErrorMessage.GET_REQUESTS_ERROR);
}
}

exports.deleteRequest = async (req, res) => {
try{
const { _id } = req.user; // 현재 로그인한 사용자의 고유 식별자
const { word } = req.params;
await userService.deleteRequest(_id, word);
sendResponse.ok(res, {
message: SuccessMessage.DELETE_REQUEST_SUCCESS,
});
} catch (err) {
console.log(err);
sendResponse.fail(req, res, ErrorMessage.DELETE_REQUEST_ERROR);
}
}

exports.getRole = async (req, res) => {
const { _id } = req.user;
const role = await userService.getRole(_id);
sendResponse.ok(res, {
message: SuccessMessage.GET_ROLE_SUCCESS,
data: { role },
});
}

exports.updateRequest = async (req, res) => {
const { requestId } = req.params;
const { formData } = req.body;
await userService.updateRequest(requestId, formData);
sendResponse.ok(res, {
message: SuccessMessage.UPDATE_REQUEST_SUCCESS
});
}

exports.updateRequestState = async (req, res) => {
try {
const { _id} = req.user;
const { requestId } = req.params;
const { status, formData, requestType } = req.body;

await userService.updateRequestState(_id, requestId, status, formData, requestType);
sendResponse.ok(res, {
message: SuccessMessage.UPDATE_REQUEST_STATE_SUCCESS,
});
} catch (err) {
console.log(err);
sendResponse.fail(req, res, ErrorMessage.UPDATE_REQUEST_STATE_ERROR);
}
}

1 change: 1 addition & 0 deletions src/routes/user/user.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const requestSchema = new mongoose.Schema(
},
],
info: { type: String },
suggestedBy: { type: String, required: true },
type: { type: String, enum: ['add', 'mod'], required: true },
status: { type: String, enum: ['pend', 'rej', 'app'], default: 'pend' },
deletedAt: { type: Date, default: null },
Expand Down
172 changes: 172 additions & 0 deletions src/routes/user/user.repository.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const User = require('./user.model');
const mongoose = require('mongoose');
const { ObjectId } = mongoose.Types;

exports.createUser = async (userData) => {
try {
Expand Down Expand Up @@ -57,11 +59,14 @@ exports.delRecentSearch = async (_id, searchTerm) => {

exports.updateRecentSearch = async (_id, searchTerm) => {
try {
console.log("id", _id)
console.log("searchTerm", searchTerm)
const user = await User.findById(_id).exec();
if (!user) {
console.log('User not found');
}
const recentSearch = user.recentSearches.find((search) => search.searchTerm === searchTerm);
console.log("recentSearch", recentSearch)
if (recentSearch) {
// 검색어가 이미 존재하는 경우
if (recentSearch.deletedAt) {
Expand All @@ -80,3 +85,170 @@ exports.updateRecentSearch = async (_id, searchTerm) => {
console.error(err);
}
};

// 단어 추가 및 수정
exports.postWords = async (userId, formData, nickname, type) => {
try {
const user = await User.findById(userId).exec();
if (!user) {
throw new Error('User not found');
}

console.log("User before modification:", JSON.stringify(user.requests, null, 2));

if (type === 'add') {
user.requests.push({
word: formData.devTerm,
info: formData.addInfo,
awkPron: formData.awkPron,
comPron: formData.commonPron,
deletedAt: null,
status: 'pend',
type: 'add',
suggestedBy: nickname // nickname 추가
});
} else if (type === 'mod') {
const request = user.requests.find(req => req.word === formData.devTerm);
if (!request) {
user.requests.push({
word: formData.devTerm,
info: formData.addInfo,
awkPron: formData.awkPron,
comPron: formData.commonPron,
deletedAt: null,
status: 'pend',
type: 'mod',
suggestedBy: nickname // nickname 추가
})
} else {
console.log('이미 같은 단어 수정 요청이 존재합니다.');
throw new Error('Word not found');
}
} else {
throw new Error('Invalid type');
}

await user.save();
console.log("User after modification:", JSON.stringify(user.requests, null, 2));
return user.requests.find(req => req.word === formData.devTerm);
} catch (err) {
console.error(err);
throw err;
}
};

exports.getUserRequests = async (userId) => {
try {
const user = await User.findById(userId).select('requests').exec();
if (!user) {
throw new Error('User not found');
}
// requests 배열에서 deletedAt이 null인 항목만 필터링
const activeRequests = user.requests.filter(request => request.deletedAt === null);
return activeRequests;

} catch (err) {
console.error(err);
}
};

exports.getUserRequestsAll = async () => {
try {
const users = await User.find({}, { requests: 1, _id: 0 }); // 모든 유저의 requests 필드만 가져옴
const allRequests = [];

users.forEach(user => {
user.requests.forEach(request => {
if (request.deletedAt === null) {
allRequests.push(request);
}
});
});

return allRequests;
} catch (err) {
console.error(err);
}
}

exports.deleteRequest = async (userId, requestWord) => {
try {
const user = await User.findById(userId).select('requests').exec();
if (!user) {
console.log("사용자를 찾을 수 없음");
throw new Error('User not found');
}

const request = user.requests.find(req => req.word === requestWord && req.deletedAt === null);
if (request) {
console.log("삭제할 요청 찾음:", request);
request.deletedAt = Date.now(); // 요청을 삭제로 표시
await user.save();

console.log("요청 삭제 성공");
} else {
}
} catch (err) {
console.error(err);
}
}

exports.getRole = async (userId) => {
try {
const user = await User.findById(userId).select('role').exec();
return user.role;
} catch (err) {
console.error(err);
}
}

exports.updateRequest = async (requestId, formData) => {
try {
const user = await User.findOne({ 'requests._id': requestId }).select('requests').exec();
if (!user) {
throw new Error('User not found');
}

const request = user.requests.find(req => req._id.toString() === requestId && req.deletedAt === null);
if (request) {
// formData의 각 속성 값으로 request의 해당 속성 값 업데이트
if (formData.addInfo !== undefined) {
request.info = formData.addInfo;
}
if (formData.awkPron !== undefined) {
request.awkPron = formData.awkPron;
}
if (formData.commonPron !== undefined) {
request.comPron = formData.commonPron;
}
if (formData.devTerm !== undefined) {
request.word = formData.devTerm;
}

await user.save();
} else {
console.log('Request not found or already deleted');
}
} catch (err) {
console.error(err);
}
};

exports.updateRequestState = async (userId, requestId, status) => {
try {
console.log("updateRequestState 레포진입!!!!!!!!!!!!", userId, requestId, status)
const user = await User.findOneAndUpdate(
{ 'requests._id': requestId },
{ $set: { 'requests.$.status': status } },
{ new: true }
).exec();

if (!user) {
console.log('Request not found');
} else {
console.log('Request status updated successfully');
}

} catch (err) {
console.error(err);
}}
24 changes: 23 additions & 1 deletion src/routes/user/user.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ const {
logout,
recentSearches,
delRecentSearch,
postWords,
UserRequests,
UserRequestsAll,
deleteRequest,
updateRequest,
getRole,
updateRequestState,
} = require('./user.controller');
const { isLoggedIn, isNotLoggedIn } = require('../../common/utils/auth');
const { isLoggedIn, isNotLoggedIn, isUser } = require('../../common/utils/auth');
const userRouter = express.Router();

// 회원가입
Expand All @@ -31,4 +38,19 @@ userRouter.get('/profile', isLoggedIn, getProfile);
userRouter.get('/recent', isLoggedIn, recentSearches); // 최근 검색어 조회
userRouter.delete('/:searchTerm', isLoggedIn, delRecentSearch); // 최근 검색어 삭제

//등록 요청
userRouter.post('/requests/:nickname/new', isLoggedIn, postWords);

module.exports = userRouter;
// 요청 조회
userRouter.get('/requests', isLoggedIn, UserRequests); // 요청 목록 조회
userRouter.get('/requests/all', isLoggedIn, UserRequestsAll); // 모든 요청 목록 조회
userRouter.get('/role', isLoggedIn, getRole); // 사용자 역할 가져오기
userRouter.delete('/requests/:word', isLoggedIn, deleteRequest); // 사용자 요청 삭제
userRouter.post('/requests/:requestId', isLoggedIn, updateRequest); // 사용자 요청 수정


//요청 상태 변경
userRouter.post('/requests/:requestId/status', isLoggedIn, updateRequestState); // 사용자 요청 status 변경

module.exports = userRouter;
Loading