export class ResumeController {
constructor(resumesService) {
this.resumesService = resumesService;
}
// 생성
createResume = async (req, res, next) => {
const { userId } = req.user;
const { title, content, status = "APPLY" } = req.body;
console.log(userId);
const createdResume = await this.resumesService.createResume(userId, title, content, status);
return res.status(201).json({ message: "게시글 생성에 성공하였습니다" });
};
export class ResumesService {
constructor(resumesRepository) {
this.resumesRepository = resumesRepository;
}
// 생성
createResume = async (userId, title, content) => {
const status = "APPLY";
// await new Promise((resolve) => setTimeout(resolve, 3000)); 슬랙 알람??
const resume = await this.resumesRepository.createResume(userId, title, content, status);
const Statuses = ["APPLY", "DROP", "PASS", "INTERVIEW1", "INTERVIEW2", "FINAL_PASS"];
if (!Statuses.includes(status)) {
throw new Error("이력서 상태가 이상합니다.");
}
// await sendTodayData(); 슬랙 알람??
return resume;
};
export class ResumesRepository {
constructor(prisma) {
this.prisma = prisma;
}
// 생성
createResume = async (userId, title, content, status) => {
const resume = await this.prisma.resumes.create({
data: {
userId: +userId,
title,
content,
status,
},
});
return resume;
};
import express from "express";
import { prisma } from "../model/index.js";
import authMiddleware from "../middlewares/auth.middleware.js";
import { ResumeController } from "../src/controllers/resumeController.js";
import { ResumesService } from "../src/services/resumesService.js";
import { ResumesRepository } from "../src/repositories/resumesRepository.js";
// import jwt from "jsonwebtoken";
// import bcrypt from "bcrypt";
const router = express.Router();
const resumesRepository = new ResumesRepository(prisma);
const resumesService = new ResumesService(resumesRepository);
// PostsController의 인스턴스를 생성합니다.
const resumesController = new ResumeController(resumesService);
// 이력서 생성 API
router.post("/resume", authMiddleware, resumesController.createResume);
기존에 router를 3계층 분리 하여 생성 코드만 가져와봤다.
이런식으로 각각에 계층에 맞게 코드를 작성하여 실행하면 된다.(근데 나도 아직 잘 모르겠따..!)
controller, service, repository의 각각 역할