<repo_name>ahmedthewavemaker/swole-mate-api<file_sep>/migrations/001.do.create.workout.sql
CREATE TABLE workout (
     id INTEGER PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
    email   TEXT NOT NULL ,
    muscle    TEXT NOT NULL  ,
    exercise  TEXT NOT NULL    ,
    sets  INTEGER  ,
    reps    INTEGER  
)<file_sep>/test/workout-fixture.js
function makeWorkoutArray (){
    return [
        {
            id: 23,
            email: "<EMAIL>",
            muscle: "legs",
            exercise: "squats",
            sets: 3,
            reps: 15,
        },
        {
            id: 26,
            email: "<EMAIL>",
            muscle: "arms",
            exercise: "biceps",
            sets: 3,
            reps: 10,
        }
       
]    
}

module.exports = {makeWorkoutArray};<file_sep>/seeds/seed.workout.sql
INSERT INTO workout (id, email, muscle, exercise, sets, reps)
VALUES
(1, '<EMAIL>', 'chest', 'chest workout 1', 3, 10)

<file_sep>/seeds/truncate.sql
TRUNCATE workout RESTART IDENTITY CASCADE<file_sep>/src/config.js
module.exports = {
    PORT: process.env.PORT || 8000,
    NODE_ENV: process.env.NODE_ENV || 'development',
    REACT_APP_BASE_URL: process.env.REACT_APP_BASE_URL || "http://localhost:8000",
    CLIENT_ORIGIN: 'https://swole-mate-app.vercel.app/',
    DATABASE_URL:process.env.DATABASE_URL || 'postgresql://dunder_mifflin@localhost/swole-mate',
    TEST_DATABASE_URL:'postgresql://dunder_mifflin@localhost/swole-mate-test',
  }<file_sep>/Router/workout-router.js
const express = require('express')
const xss = require('xss')
const WorkoutService = require('./workout-service')
const workoutRouter = express.Router()
const jsonParser = express.json()



const serializeWorkout = workout=> ({
    id: workout.id,
    email: workout.email,
    muscle: workout.muscle,
    exercise: workout.exercise,
    sets: workout.sets,
    reps: workout.reps,
})


workoutRouter
.route('/')
.get((req, res, next) =>{
    const knexInstance = req.app.get('db')
    WorkoutService.getByEmail(knexInstance, req.query.email)
        .then(workouts =>{
            res.json(workouts.map(serializeWorkout))
        })
        .catch(next)
})
.post(jsonParser, (req, res, next) =>{
    const {email, muscle, exercise, sets, reps} = req.body;
    const newWorkout = {email, muscle, exercise, sets, reps}

    if(!email){ 
        return res
                .status(400)
                .json({message: "Missing 'email' in request body"})
    }


    if(!muscle){
        return res  
            .status(400)
            .json({message: "Missing 'muscle' in request body"})
    }

    if(!exercise){
        return res  
            .status(400)
            .json({message: "Missing 'exercise' in request body"})
    }

    if(!sets){
        return res  
            .status(400)
            .json({message: "Missing 'sets' in request body"})
    }

    if(!reps){
        return res  
            .status(400)
            .json({message: "Missing 'reps' in request body"})
    }
    WorkoutService.insertWorkout(
        req.app.get('db'), newWorkout
    )
        .then(workout =>{
            res 
                .status(201)
                .json(serializeWorkout(workout))
        })
        .catch(next)

})

workoutRouter
.route('/:workout_id')
.delete((req, res, next) => {
    WorkoutService.deleteWorkout(
      req.app.get('db'),
      req.params.workout_id
    )
    
      .then(numRowsAffected => {
        res.status(204).end()
      })
      .catch(next)
    })

module.exports = workoutRouter