text: const express = require("express");
  const cors = require("cors");
  
  const { uuid } = require("uuidv4");
  
  const app = express();
  
  app.use(express.json());
  app.use(cors());
  
  const repositories = [];
  let contLike = 0;
  
  app.get("/repositories", (request, response) => {
     return response.status(200).send(repositories);
  });
  
  app.post("/repositories", (request, response) => {
    contLike = 0;
    const { title, url, techs, likes } = request.body;
  
  
    const repository = {id: uuid(), title, url, techs, likes: 0};
    repositories.push(repository);
    return response.json(repository);
  
  });
  
  app.put("/repositories/:id", (request, response) => {
      const { id } = request.params;
  
      const { title, url, techs } = request.body;
  
      const repositoryIndex = repositories.findIndex(repository => repository.id == id);
  
      if(repositoryIndex < 0){
        return response.status(400).json({ error: 'Project not found'});
      }
  
      const repository = {
        id,
        title,
        url,
        techs,
        likes: 0
    };
  
    repositories[repositoryIndex] = repository;
  
    return response.json(repository);
  
  });
  
  app.delete("/repositories/:id", (request, response) => {
    const { id } = request.params;
  
    const repositoryIndex = repositories.findIndex(repository => repository.id == id);
  
    if(repositoryIndex < 0){
      return response.status(400).json({ error: 'Project not found'});
    }
  
    repositories.splice(repositoryIndex, 1);
  
    return response.status(204).send();
  
  });
  
  app.post("/repositories/:id/like", (request, response) => {
    const { id } = request.params;
    // const { title, url, techs, likes } = request.body;
    
  
  
  
    const repositoryIndex = repositories.findIndex(repository => repository.id == id);
  
    if(repositoryIndex < 0){
      return response.status(400).json({ error: 'Project not found'});
      
    }
      contLike  = contLike + 1;
      const repository = {id, likes: contLike};
      
    
      repositories.push(repository);
      return response.json(repository);
    
  
    
  
    
  });
  
  module.exports = app;
  