Skip to content

Canti21/didacteca-solution

Repository files navigation

Book-user API

Solution repo for the technical interview

What it does

  • Create, read, update, delete users
  • Each user can have their own collection of books
  • The same book can't be added twice to the same user

Built with

  • Node.js & Express
  • TypeScript for better code quality
  • MySQL database

How to run

  1. Install packages

    npm install
  2. Build TypeScript

    npm run build
  3. Set up database

    • Start MySQL server
    • Create a database
    • Run the SQL in schema.sql
  4. Set up environment (create .env file)

    DB_HOST=localhost
    DB_USER=root
    DB_PASSWORD=your_password
    DB_NAME=your_database_name (it takes 'library' as a default)
    PORT=3000
  5. Start server

    npm run dev

API Endpoints

Users

  • POST /users - Create user
  • GET /users - Get all users
  • PUT /users/:id - Update user
  • DELETE /users/:id - Delete user

Books

  • POST /users/:userId/books - Add book to user
  • GET /users/:userId/books - Get user's books
  • PUT /users/:userId/books/:bookId - Update user's book
  • DELETE /users/:userId/books/:bookId - Delete user's book

Example

Create a user:

curl -X POST http://localhost:3000/users \
  -H "Content-Type: application/json" \
  -d '{"name":"John Doe","email":"john@example.com"}'

Add a book to user 1:

curl -X POST http://localhost:3000/users/1/books \
  -H "Content-Type: application/json" \
  -d '{"title":"1984","author":"George Orwell"}'

Default settings

  • Server port: 3000
  • MySQL port: 4000
  • Database user: root
  • No password

Change these in the .env file if needed.

About

Solution repo for the technical interview

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published