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

db 에 category로 뉴스 조회하기 #11

Open
pol-dev-shinroo opened this issue Apr 7, 2023 · 0 comments
Open

db 에 category로 뉴스 조회하기 #11

pol-dev-shinroo opened this issue Apr 7, 2023 · 0 comments

Comments

@pol-dev-shinroo
Copy link
Contributor

import { Router } from "express";
import { Controller } from "@/controllers/controller.interface";
import validate from "./newsList.validation";
import { StatusCodes } from "http-status-codes";
import { asyncWrapper, validationMiddleware } from "@/middlewares/index";
import { newsRepository } from "@/database/repositories/news.repository";

class NewsListController implements Controller {
  public path = "/newsList";
  public router = Router();

  constructor() {
    this.initializeRoutes();
  }

  private initializeRoutes(): void {
    this.router
      .route(this.path)
      .post(validationMiddleware(validate.create), this.listByCategory);
  }

  private listByCategory = asyncWrapper(async (req, res) => {
    try {
      const { category } = req.body;
      console.log(category);
      const allnews = await newsRepository.findByCategory(category);
      console.log(allnews);
      return res.status(StatusCodes.OK).json({ result: true });
    } catch (err) {
      res.status(StatusCodes.INTERNAL_SERVER_ERROR).json({
        result: false,
        message: "problem with the database",
      });
    }
  });
}

export default NewsListController;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant