text: const router = require("express").Router();
  const { User, Post } = require("../../models");
  const sequelize = require("../../config/connection");
  const withAuth = require("../../utils/auth")
  
  
  router.get("/", (req, res) => {
    Post.findAll({
      include: [{
        model: User,
        attributes: ["username"],
      }]
  
    }).then((dbPostData) => res.json(dbPostData))
    .catch((err) => {
      console.log(err);
      res.status(500).json(err);
    })
  })
  
  router.post("/", (req, res) => {
      Post.create({
        title: req.body.title,
        content: req.body.content,
        user_id: req.session.user_id,
      })
        .then((dbPostData) => res.json(dbPostData))
        .catch((err) => {
          console.log(err);
          res.status(500).json(err);
        });
  });
  
  router.put("/:id", withAuth, (req, res) => {
    console.log(req.body.content)
    Post.update(
      {
        title: req.body.title,
        content: req.body.content,
        user_id: req.session.user_id,
      },
      {
        where: {
          id: req.params.id,
        },
      }
    )
      .then((dbPostData) => {
        if (!dbPostData) {
          res.status(404).json({ message: "No post found with this id" });
          return;
        }
        res.json(dbPostData);
      })
      .catch((err) => {
        console.log(err);
        res.status(500).json(err);
      });
  });
  
  
  router.delete("/:id", withAuth, (req, res) => {
    console.log("id", req.params.id);
    Post.destroy({
      where: {
        id: req.params.id,
      },
    })
      .then((dbPostData) => {
        if (!dbPostData) {
          res.status(404).json({ message: "No post found with this id" });
          return;
        }
        res.json(dbPostData);
      })
      .catch((err) => {
        console.log(err);
        res.status(500).json(err);
      });
  });
  
  
  
  module.exports = router;
  