Skip to content

evandrodutra/ruby-dev-cls-1

 
 

Repository files navigation

File System Manager API

Description

Develop a model layer for a file system persisted in a SQL database where it's possible to create directories and files. The directories can contain subdirectories and files. The file contents can be persisted as blob, S3, or on disk.

The solution should be written primarily in Ruby using the Ruby on Rails framework.

Requirements

  • Docker and Docker Compose
  • Ruby 3.4.3

Optional

  • jq (sudo apt-get install jq or brew install jq)
  • curl

Setup

  1. Clone the repository:
git clone <repository-url>
cd ruby-dev-test-1
  1. Build the Docker image:
docker compose build
  1. Setup the database:
docker compose run app bin/rails db:setup

Running the Application

Start the application:

docker compose up

Running migrations

docker compose run app bin/rails db:migrate

The API will be available at http://localhost:1234

API Endpoints

Directories

List Root Directories

Returns all root-level directories.

curl -X GET http://localhost:1234/directories | jq

Get Specific Directory

Returns a specific directory and its complete subtree.

curl -X GET http://localhost:1234/directories/:id | jq

Create Directory

Creates a new directory. Set parent_id to create a subdirectory.

# Create root directory
curl -X POST http://localhost:1234/directories \
  -H "Content-Type: application/json" \
  -d '{
    "directory": {
      "name": "New Root Directory",
      "parent_id": null
    }
  }' | jq

# Create subdirectory
curl -X POST http://localhost:1234/directories \
  -H "Content-Type: application/json" \
  -d '{
    "directory": {
      "name": "Subdirectory",
      "parent_id": 1
    }
  }' | jq

Delete a specific directory.

curl -X DELETE http://localhost:1234/directories/:id | jq

Files

Upload Files

Upload one or multiple files to a directory.

# Upload single file
(echo "File 1 content" > /tmp/file1.txt && \
 curl -X POST http://localhost:1234/directories/:directory_id/files \
   -F "files[]=@/tmp/file1.txt" | jq && \
 rm /tmp/file1.txt)

# Upload multiple files
(echo "File 1 content" > /tmp/file1.txt && \
 echo "File 2 content" > /tmp/file2.txt && \
 curl -X POST http://localhost:1234/directories/:directory_id/files \
   -F "files[]=@/tmp/file1.txt" \
   -F "files[]=@/tmp/file2.txt" | jq && \
 rm /tmp/file1.txt /tmp/file2.txt)

Delete File

Delete a specific file from a directory.

curl -X DELETE http://localhost:1234/directories/:directory_id/files/:id | jq

Running Tests

  1. Install development dependencies:
docker compose run app bundle install
  1. Run the test suite:
docker compose run -e RAILS_ENV=test app bash -c "bin/rails db:migrate && bundle exec rspec"

Troubleshooting

  1. Remove all containers and volumes:
docker compose down -v

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 98.7%
  • Dockerfile 1.3%