Skip to content

Commit

Permalink
[Fix] #24 - 타 회원 가계부 상세보기 기능 구현
Browse files Browse the repository at this point in the history
- 3 table을 join하여 데이터를 가져온다
- 현재 로그인 중인 유저를 제외한 나머지 유저의 가계부 타입별(지출,수입) 가계부 데이터를 가져온다
  • Loading branch information
StarFace90 committed Jul 8, 2022
1 parent 00c568d commit 8614b81
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 152 deletions.
37 changes: 21 additions & 16 deletions src/controllers/moneybook_detail/moneybookDetailController.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import moneybookDetailService from "../../services/moneybook_detail/moneybookDetailService.js";
import statusCode from "./../../utils/statusCode.js";
import message from "./../../utils/responseMessage.js";
import { errResponse, response } from "./../../utils/response.js";
import moneybookDetailService from '../../services/moneybook_detail/moneybookDetailService.js';
import statusCode from './../../utils/statusCode.js';
import message from './../../utils/responseMessage.js';
import { errResponse, response } from './../../utils/response.js';

const moneybookDetailController = {
createMoneybook: async (req, res) => {
/**
* @author 오주환
* @version 1.0 22.07.06 가계부 상세내역 추가
*/
console.log(moneybookDetailService);
const moneybook = await moneybookDetailService.createMoneybook(req);

if (moneybook === 0) {
Expand All @@ -23,15 +24,19 @@ const moneybookDetailController = {
.send(response(statusCode.CREATED, message.SUCCESS, moneybook));
}
},
/**
* @author 박성용
* @version 1.0 22.7.6 최초 작성
*/

getAnotherUsersMoneybook: async (req, res) => {
/**
* @author 박성용
* @version 1.0 22.7.6 최초 작성
* 다른 유저들의 가계부 정보를 가져옵니다
*/

// eslint-disable-next-line no-unused-vars
const { moneybook_id } = req.params;
const { userId } = req;
const { type } = req.query;
const data = { moneybook_id, type };
const data = { userId, type };

try {
const result = await moneybookDetailService.anotherUsersMoneybooks(data);
return res.status(result.status).send(result);
Expand All @@ -56,7 +61,7 @@ const moneybookDetailController = {
.send(errResponse(statusCode.UNAUTHORIZED, message.UNAUTHORIZED));
} else if (moneybook.length === 0) {
return res.json(
response(statusCode.NO_CONTENT, message.NO_CONTENT, moneybook)
response(statusCode.NO_CONTENT, message.NO_CONTENT, moneybook),
);
} else {
return res
Expand All @@ -73,7 +78,7 @@ const moneybookDetailController = {

if (moneybook === -1) {
return res.send(
errResponse(statusCode.UNAUTHORIZED, message.UNAUTHORIZED)
errResponse(statusCode.UNAUTHORIZED, message.UNAUTHORIZED),
);
} else if (moneybook[0] === 0) {
return res.send(errResponse(statusCode.NO_CONTENT, message.NO_CONTENT));
Expand All @@ -89,11 +94,11 @@ const moneybookDetailController = {
* @version 1.0 22.07.07 가계부 상세내역 삭제
*/
const moneybook = await moneybookDetailService.deleteMoneybook(req);
console.log("moneybook: ", moneybook);
console.log('moneybook: ', moneybook);

if (moneybook === 0) {
return res.send(
errResponse(statusCode.UNAUTHORIZED, message.UNAUTHORIZED)
errResponse(statusCode.UNAUTHORIZED, message.UNAUTHORIZED),
);
} else if (moneybook === -1) {
return res.send(errResponse(statusCode.NO_CONTENT, message.NO_CONTENT));
Expand All @@ -109,13 +114,13 @@ const moneybookDetailController = {
* @version 1.0 22.07.07 가계부 상세내역 복구
*/
const moneybook = await moneybookDetailService.recoverMoneybook(req);
console.log("moneybook: ", moneybook);
console.log('moneybook: ', moneybook);

if (moneybook === 0) {
return res.send(errResponse(statusCode.NO_CONTENT, message.NO_CONTENT));
} else if (moneybook === -1) {
return res.send(
errResponse(statusCode.UNAUTHORIZED, message.UNAUTHORIZED)
errResponse(statusCode.UNAUTHORIZED, message.UNAUTHORIZED),
);
} else {
return res
Expand Down
1 change: 1 addition & 0 deletions src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import MoneybookDetailRouter from "./moneybook_detail/index.js";

router.use("/users", userRouter);
router.use("/moneybooks", MoneybookRouter);
router.use("/moneybooks", MoneybookDetailRouter);
router.use("/moneybook-detail", MoneybookDetailRouter);

export default router;
25 changes: 14 additions & 11 deletions src/routes/moneybook_detail/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Router } from "express";
import moneybookDetailController from "./../../controllers/moneybook_detail/moneybookDetailController.js";
import { Router } from 'express';
import moneybookDetailController from './../../controllers/moneybook_detail/moneybookDetailController.js';
import authJWT from '../../middlewares/auth.js';
const router = Router();

/**
* @author 오주환
* @version 1.0 22.07.07 가계부 상세내역 생성
*/
router.post("/:moneybook_id", moneybookDetailController.createMoneybook);
router.post('/:moneybook_id', moneybookDetailController.createMoneybook);
/**
* @author 오주환
* @version 1.0 22.07.07 가계부 상세내역 전체 조회
Expand All @@ -16,23 +17,25 @@ router.post("/:moneybook_id", moneybookDetailController.createMoneybook);
* @author 오주환
* @version 1.0 22.07.07 가계부 상세내역 수정
*/
router.patch("/:moneybook_id", moneybookDetailController.updateMoneybook);
router.patch('/:moneybook_id', moneybookDetailController.updateMoneybook);
/**
* @author 오주환
* @version 1.0 22.07.07 가계부 상세내역 삭게
*/
router.delete("/:moneybook_id", moneybookDetailController.deleteMoneybook);
router.delete('/:moneybook_id', moneybookDetailController.deleteMoneybook);
/**
* @author 오주환
* @version 1.0 22.07.07 가계부 상세내역 복구
*/
router.patch(
"/recovery/:moneybook_id",
moneybookDetailController.recoverMoneybook
);
router.get(
"/:moneybook_id",
moneybookDetailController.getAnotherUsersMoneybook
'/recovery/:moneybook_id',
moneybookDetailController.recoverMoneybook,
);

/**
* @author 박성용
* @version 1.0 22.07.07 다른 유저의 가계부 상세 조회
*/
router.get('/', authJWT, moneybookDetailController.getAnotherUsersMoneybook);

export default router;
Loading

0 comments on commit 8614b81

Please sign in to comment.