Skip to content

Commit

Permalink
✨ feat(api): add api for view list PRP (#29)
Browse files Browse the repository at this point in the history
* ✨ feat(api): add api for view list PRP

* ♻️ refactor(api): modify api url
  • Loading branch information
SollyJ authored Jan 12, 2023
1 parent ebd070a commit b6dd2cc
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
22 changes: 22 additions & 0 deletions src/api/routes/v1/individual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ import {
PersonalRollingPaperInputDTO,
PersonalRollingPaperDTO,
} from "@/interfaces/PersonalRollingPaper";
import { UserInputDTO } from "@/interfaces/User";

// ? routes에선 model 안쓰이는데 뺄까요??
import PersonalPost from "@/models/personalPost";
import PersonalRollingPaper from "@/models/personalRollingPaper";

import PersonalService from "@/services/individual";
import { Router, Request, Response, NextFunction } from "express";
import { Container } from "typedi";
Expand Down Expand Up @@ -69,6 +73,7 @@ export default (app: Router) => {
);

// 개인 롤링페이퍼 수정
// TODO

// 개인 롤링페이퍼 삭제
route.delete(
Expand All @@ -91,6 +96,23 @@ export default (app: Router) => {
),
);

// 개인 롤링페이퍼 목록 조회
route.get(
"/papers/list/:userId",
asyncHandler(async (req: Request<UserInputDTO>, res: Response) => {
logger.debug(req.params);

// 비즈니스 로직을 처리할 service객체 받아오기
const personalServiceInstance = Container.get(PersonalService);

const { personalRollingPapers } = await personalServiceInstance.viewListPersonalRollingPaper(
req.params as UserInputDTO,
);

return res.status(200).json({ result: personalRollingPapers });
}),
);

// !GET, req 참고하세요!
// 개인 롤링페이퍼 포스트 디테일 조회
route.get(
Expand Down
33 changes: 28 additions & 5 deletions src/services/individual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import {
PersonalPostDTO,
} from "@/interfaces/PersonalPost";

import {
UserInputDTO,
} from "@/interfaces/User";

@Service()
export default class PersonalService {
constructor(
Expand Down Expand Up @@ -92,11 +96,8 @@ export default class PersonalService {
}

// 개인 롤링페이퍼 수정해주는 함수
// ? 아마 title, public_type만 수정할수있을듯
public async updatePersonalRollingPaper() {
// TODO
}

// TODO

// 개인 롤링페이퍼 삭제해주는 함수
public async deletePersonalRollingPaper(
personalRollingPaperInputDTO: PersonalRollingPaperInputDTO,
Expand All @@ -114,6 +115,28 @@ export default class PersonalService {
}
}

// 개인 롤링페이퍼 목록 조회해주는 함수
public async viewListPersonalRollingPaper(
userInputDTO: UserInputDTO,
): Promise<{ personalRollingPapers: PersonalRollingPaper[] }> {
try {
const userId = userInputDTO.userId;

const personalRollingPapers = await this.personalRollingPaperModel.findAll({
where: { user_id: userId },
});

if(!personalRollingPapers) {
throw new Error("This user does not have any papers");
}

return { personalRollingPapers };
} catch (error) {
this.logger.error(error);
throw error;
}
}

// 포스트 아이디(UUID)를 DB에서 찾은 후 JSON으로 전달해주는 함수
public async viewDetailPost(
personalPostInputDTO: PersonalPostInputDTO,
Expand Down

0 comments on commit b6dd2cc

Please sign in to comment.