Coder Social home page Coder Social logo

api-test's Introduction

API Test

Tecnologías

  • Docker (python:3.10.4-alpine3.16)
  • Python (requests, urllib3, mysql-connector, dicttoxml, xmltodict)

Plan de trabajo

  • Reconocimiento del problema
  • Conocer las entradas y salidas
  • Creación de pruebas
  • Creación de API
  • Validación de pruebas y refactorizar de ser necesario

Endpoints

  • /realEstates/{id}?status={estado}&year={año}&city={ciudad}

     curl -i -X GET http://127.0.0.1:5000/realEstates/\?status=pre_venta\&year=2020\&city=bogota
  • /realEstates/{*id}/Likes

     curl -i -X POST -H "Authorization: Basic {BASE64 USER}" http://127.0.0.1:5000/realEstates/1/Likes

Los parámetros marcados con * son obligatorios, todos los demás son opcionales


Deploy

Configura las credenciales de la base de datos en el archivo .env

DB_HOST=
DB_DATABASE=
DB_USER=
DB_PASS=
DB_PORT=

Para ejecutar la API utiliza el siguiente comando, en caso de querer ejecutar las pruebas de los endpoints agrega al final del comando -t o --test

docker run --rm --env-file .env -p 5000:5000 -it $(docker build -q .)
# O ejecute el siguiente comando
# docker compose up -d

DB

  • Se crea la tabla de property_likes para el manejo del me gusta de los usuarios, no creo una llave única del usuario con la propiedad para que el usuario le puede darle me gusta más de una vez

property_likes

Esta tabla fue creada para el endpoint /realEstates/{*id}/Likes

CREATE TABLE `property_likes` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `property_id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `create_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  CONSTRAINT `property_likes_property_id_fk` FOREIGN KEY (`property_id`) REFERENCES `property` (`id`),
  CONSTRAINT `property_likes_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`)
) ENGINE=InnoDB
DEFAULT CHARSET=latin1;
  • Mejoras sugeridas a la base de datos:
    • En la tabla de property normalizar la columna city, year
       CREATE TABLE `property_city` (
       	`id` int(11) NOT NULL AUTO_INCREMENT,
       	`name` varchar(32) NOT NULL,
       	PRIMARY KEY (`id`)
       ) ENGINE=InnoDB DEFAULT CHARSET=latin1
       AS
       SELECT NULL AS id, city AS name
       FROM property
       WHERE city!=''
       GROUP BY 2
       ORDER BY 2 ASC;
      
       ALTER TABLE `property` MODIFY COLUMN city varchar(32) CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL NULL;
      
       CREATE TABLE `property_year` (
       	`id` int(11) NOT NULL AUTO_INCREMENT,
       	`year` int(4) NOT NULL,
       	PRIMARY KEY (`id`)
       ) ENGINE=InnoDB DEFAULT CHARSET=latin1
       AS
       SELECT NULL AS id, `year`
       FROM property
       WHERE `year` IS NOT NULL
       GROUP BY 2
       ORDER BY 2 ASC;
      
       UPDATE `property` p LEFT JOIN `property_city` pc ON p.city = pc.name SET p.city = pc.id;
       UPDATE `property` p INNER JOIN `property_year` py ON p.`year` = py.`year` SET p.`year` = py.id;
      
       ALTER TABLE `property` MODIFY COLUMN city INT(11) NULL;
    • En la tabla de property agregar columna status y asi dejar la tabla status_history solo para consulta del historial
       ALTER TABLE `property` ADD status int(11) NULL;
      
       UPDATE property p
       INNER JOIN (
       	SELECT property_id, status_id
       	FROM (
       		SELECT a.*,
       		@r := CASE
       			WHEN a.property_id = @prevcol THEN @r + 1
       			WHEN (@prevcol := a.property_id) = null THEN null
       			ELSE 1 END AS rn
       		FROM (
       			SELECT id, property_id, status_id
       			FROM status_history
       			ORDER BY property_id, id DESC
       			LIMIT 18446744073709551615
       		) a,
       		(SELECT @r := 0, @prevcol := null) X
       		ORDER BY a.property_id, a.id DESC
       	) a
       	WHERE a.rn=1
       ) sh ON p.id=sh.property_id
       INNER JOIN `status` s ON sh.status_id=s.id
       SET p.status = s.id;
    • En la tabla auth_user la columna password se debe encriptar para cumplir con la norma

api-test's People

Contributors

alecodev avatar dependabot[bot] avatar

Stargazers

Roman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.