Skip to content

Commit 48d1a77

Browse files
authored
Merge pull request #59 from codeit-moving/release
Release -> main 20241223 11:24
2 parents 904b6ba + 4f13129 commit 48d1a77

File tree

10 files changed

+503
-63
lines changed

10 files changed

+503
-63
lines changed

package-lock.json

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.0.0",
2+
"version": "1.1.0",
33
"dependencies": {
44
"@aws-sdk/s3-request-presigner": "^3.691.0",
55
"@prisma/client": "^5.20.0",

src/app.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import session from "express-session";
1515
import cookieConfig from "./config/cookie.config";
1616
import customerRouter from "./controllers/customerController";
1717
import userRouter from "./controllers/userController";
18+
import reviewRouter from "./controllers/reviewController";
1819
import notificationRouter from "./controllers/notificationController";
1920

2021
import confirmedQuoteRouter from "./controllers/confirmedQuoteController";
@@ -77,7 +78,7 @@ app.use("/oauth", oauthRouter);
7778
app.use("/customers", customerRouter);
7879
app.use("/users", userRouter);
7980
app.use("/notifications", notificationRouter);
80-
81+
app.use("/reviews", reviewRouter);
8182
app.use(errorHandler); //전체 에러 핸들링 미들웨어
8283

8384
app.listen(PORT || 3000, () => console.log("Server Started"));

src/controllers/quoteController.ts

Lines changed: 38 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,26 @@ import quoteValidation from "../middlewares/validations/quote";
77

88
const router = express.Router();
99

10-
// 견적서 생성 엔드포인트를 정의
10+
//견적서 상세 조회
11+
router.get(
12+
"/:id",
13+
passport.authenticate("jwt", { session: false }),
14+
asyncHandle(async (req, res, next) => {
15+
try {
16+
const { customerId } = req.user as { customerId: number };
17+
const { id: quoteId } = req.params;
18+
const quote = await quoteService.getQuoteById(
19+
customerId,
20+
parseInt(quoteId)
21+
);
22+
return res.status(200).send(quote);
23+
} catch (error) {
24+
next(error);
25+
}
26+
})
27+
);
28+
29+
// 견적서 생성하기
1130
router.post(
1231
"/",
1332
passport.authenticate("jwt", { session: false }),
@@ -24,16 +43,11 @@ router.post(
2443
comment
2544
);
2645

27-
// 견적서가 성공적으로 생성되었다는 응답을 보내요.
28-
return res.status(201).json({
29-
success: true,
30-
message: "견적서가 성공적으로 생성되었습니다.",
31-
data: quote, // 생성된 견적서 정보를 포함
32-
});
46+
return res.status(201).send(quote);
3347
})
3448
);
3549

36-
// 기사님이 작성한 견적서 목록을 조회하는 엔드포인트를 정의
50+
// (기사님이 작성한) 견적서 목록 조회
3751
router.get(
3852
"/mover",
3953
passport.authenticate("jwt", { session: false }),
@@ -56,19 +70,20 @@ router.get(
5670

5771
// 기본값 설정
5872
const limit = Number(req.query.limit) || 10;
59-
const cursor = req.query.cursor ? Number(req.query.cursor) : null;
60-
61-
const quotes = await quoteService.getQuoteList(moverId, { limit, cursor });
73+
const nextCursorId = req.query.nextCursorId
74+
? Number(req.query.nextCursorId)
75+
: null;
6276

63-
return res.status(200).json({
64-
success: true,
65-
message: "견적서 목록 조회 성공",
66-
data: quotes,
77+
const quotes = await quoteService.getQuoteList(moverId, {
78+
limit,
79+
cursor: nextCursorId, // 내부적으로는 cursor로 사용
6780
});
81+
82+
return res.status(200).send(quotes);
6883
})
6984
);
7085

71-
// 기사님이 작성한 특정 견적서의 상세 정보를 조회하는 엔드포인트를 정의
86+
// (기사님이 작성한)특정 견적서 상세 조회
7287
router.get(
7388
"/mover/:quoteId",
7489
passport.authenticate("jwt", { session: false }),
@@ -101,11 +116,7 @@ router.get(
101116

102117
const quote = await quoteService.getQuoteDetail(moverId, quoteId, cost);
103118

104-
return res.status(200).json({
105-
success: true,
106-
message: "견적서 상세 조회 성공",
107-
data: quote,
108-
});
119+
return res.status(200).send(quote);
109120
})
110121
);
111122

@@ -133,13 +144,13 @@ router.post(
133144
const result = await quoteService.rejectRequest(moverId, movingRequestId);
134145

135146
// 응답 추가
136-
res.status(200).json(result);
147+
res.status(200).send(result);
137148
})
138149
);
139150

140151
// (기사님이) 반려한 이사 요청 목록 조회
141152
router.get(
142-
"/mover/reject",
153+
"/mover/rejected",
143154
passport.authenticate("jwt", { session: false }),
144155
asyncHandle(async (req, res, next) => {
145156
const user = req.user as any;
@@ -158,37 +169,18 @@ router.get(
158169

159170
// 쿼리 파라미터 처리 (페이지네이션)
160171
const limit = parseInt(req.query.limit as string) || 10;
161-
const cursor = req.query.cursor
162-
? parseInt(req.query.cursor as string)
172+
const nextCursorId = req.query.nextCursorId
173+
? Number(req.query.nextCursorId)
163174
: null;
164175

165176
// 서비스 호출
166177
const result = await quoteService.getRejectedRequestList(moverId, {
167178
limit,
168-
cursor,
179+
cursor: nextCursorId,
169180
});
170181

171182
// 응답
172-
res.status(200).json(result);
173-
})
174-
);
175-
176-
//견적서 상세 조회
177-
router.get(
178-
"/:id",
179-
passport.authenticate("jwt", { session: false }),
180-
asyncHandle(async (req, res, next) => {
181-
try {
182-
const { customerId } = req.user as { customerId: number };
183-
const { id: quoteId } = req.params;
184-
const quote = await quoteService.getQuoteById(
185-
customerId,
186-
parseInt(quoteId)
187-
);
188-
return res.status(200).send(quote);
189-
} catch (error) {
190-
next(error);
191-
}
183+
res.status(200).send(result);
192184
})
193185
);
194186

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import { Router } from "express";
2+
import passport from "passport";
3+
import { asyncHandle } from "../utils/asyncHandler";
4+
import reviewService from "../services/reviewService";
5+
import customError from "../utils/interfaces/customError";
6+
7+
const router = Router();
8+
9+
// 리뷰 목록 조회 (기사 상세페이지용)
10+
router.get(
11+
"/mover/:moverId",
12+
asyncHandle(async (req, res) => {
13+
const moverId = parseInt(req.params.moverId);
14+
const { pageSize, pageNum } = req.query;
15+
16+
const result = await reviewService.getMoverReviewsList(moverId, {
17+
pageSize: pageSize ? parseInt(pageSize as string) : undefined,
18+
pageNum: pageNum ? parseInt(pageNum as string) : undefined,
19+
});
20+
21+
res.status(200).send(result);
22+
})
23+
);
24+
25+
// 내가 작성한 리뷰 목록 조회
26+
router.get(
27+
"/me",
28+
passport.authenticate("jwt", { session: false }),
29+
asyncHandle(async (req, res) => {
30+
const user = req.user as any;
31+
const customerId = user.customerId;
32+
33+
if (!customerId) {
34+
const error: customError = new Error("Bad Request");
35+
error.status = 400;
36+
error.message = "고객 ID가 필요합니다.";
37+
throw error;
38+
}
39+
40+
const { pageSize, pageNum } = req.query;
41+
42+
const result = await reviewService.getMyReviewsList(customerId, {
43+
pageSize: pageSize ? parseInt(pageSize as string) : undefined,
44+
pageNum: pageNum ? parseInt(pageNum as string) : undefined,
45+
});
46+
47+
res.status(200).send(result);
48+
})
49+
);
50+
51+
// 리뷰 생성하기
52+
router.post(
53+
"/",
54+
passport.authenticate("jwt", { session: false }),
55+
asyncHandle(async (req, res) => {
56+
const user = req.user as any;
57+
const customerId = user.customerId;
58+
59+
if (!customerId) {
60+
const error: customError = new Error("Bad Request");
61+
error.status = 400;
62+
error.message = "고객 ID가 필요합니다.";
63+
throw error;
64+
}
65+
66+
const { confirmedQuoteId, moverId, rating, content, imageUrl } = req.body;
67+
68+
if (!confirmedQuoteId || !moverId || !rating) {
69+
const error: customError = new Error("Bad Request");
70+
error.status = 400;
71+
error.message = "필수 항목이 누락되었습니다.";
72+
throw error;
73+
}
74+
75+
const result = await reviewService.createNewReview(customerId, {
76+
confirmedQuoteId,
77+
moverId,
78+
rating,
79+
content,
80+
imageUrl,
81+
});
82+
83+
res.status(200).send(result);
84+
})
85+
);
86+
87+
// 작성 가능한 리뷰 목록 조회
88+
router.get(
89+
"/available",
90+
passport.authenticate("jwt", { session: false }),
91+
asyncHandle(async (req, res) => {
92+
const user = req.user as any;
93+
const customerId = user.customerId;
94+
95+
if (!customerId) {
96+
const error: customError = new Error("Bad Request");
97+
error.status = 400;
98+
error.message = "고객 ID가 필요합니다.";
99+
throw error;
100+
}
101+
102+
const { pageSize, pageNum } = req.query;
103+
104+
const result = await reviewService.getAvailableReviewsList(customerId, {
105+
pageSize: pageSize ? parseInt(pageSize as string) : undefined,
106+
pageNum: pageNum ? parseInt(pageNum as string) : undefined,
107+
});
108+
109+
res.status(200).send(result);
110+
})
111+
);
112+
113+
export default router;

src/repositorys/quoteRepository.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ const getQuoteListByMoverId = (moverId: number, options: PaginationOptions) => {
203203
id: true,
204204
cost: true,
205205
comment: true,
206+
createAt: true,
206207
movingRequest: {
207208
select: {
208209
service: true, // service로 매핑 필요

0 commit comments

Comments
 (0)