Coder Social home page Coder Social logo

storage-service's Introduction

storage-service

File storage backend application.

This service stores files in a PostgreSQL database as BLOB(oid).

Requirements

SQL ERD

db-diagram

The file_size column store the size of the file as bytes.

Usage

You can deploy, build and test the app with the Makefile, add the option -j $(nproc) when convenient.

Depending on the type of 'compose' you are using, change the COMPOSE_CMD variable in the Makefile.

Container

Build the backend image.

make build-container

Or just deploy it, docker automatically builds the image it can't find it.

make deploy

Jar

Before building the jar file, start a postgreSQL instance. This is the configuration for the database connection in the application.yaml. So keep this in mind before building the jar.

spring:
  ...
  datasource:
    url: jdbc:postgresql://${POSTGRES_HOSTNAME:localhost}:${POSTGRES_PORT:5432}/${POSTGRES_DB:sn_storage_service}
    username: ${POSTGRES_USER:sn_user}
    password: ${POSTGRES_PASSWORD:sn_user}

Build the jar.

make build-jar

Tests

Remember to start a Docker daemon first. Because of Testcontainers.

make test

Consume the API

The application has four endpoints.

  • Upload a file:

    curl -F attachment=@<file path> -X POST 'http://<host>:<port>/files'
  • Update a file:

    Not implemented yet
  • Get a list of files:

    limit is the number of elements you want, must be greater than 1 e.g 10, 15, 20, etc.

    offset is the number of skipped elements in other words the page that wou want, must be a apositive number increased by ten e.g 0, 10, 20, 30, etc.

    curl -X GET 'http://<host>:<port>/files?limit=<number>&offset=<number>'
  • Download a file:

    curl -X GET -o <your output file path> 'http://<host>:<port>/files/<file id>'
  • Delete a file:

    curl -X DELETE 'http://<host>:<port>/files/<file id>'

storage-service's People

Contributors

sirnoob97 avatar

Stargazers

 avatar

Watchers

 avatar

storage-service's Issues

Deny invalid `File` info

As expressed here 8a15f11, these values must not be allowed and an exception must be thrown

Improve the SQL test script with the following constraint or use triggers if necessary:

  • Filename cannot be an empty string.
  • Mime-Type cannot be an empty string.
  • File size must be greater than zero.

File Service

Add service layer. FileService interface and its implementation

Delete `File` by id refactor

As described here, a refactor is necessary to prevent FileData orphans

/**
* BUG: This method should delete both {@link com.sirnoob97.storageservice.file.entity.File} and the {@link com.sirnoob97.storageservice.file.entity.FileData}
* without a previous search of the {@link com.sirnoob97.storageservice.file.entity.File} entity
*
* Refactor the native query to delete the related {@link com.sirnoob97.storageservice.file.entity.FileData}
* Or add a cascade on delete operations in the sql table
*/
@Override
public void deleteFile(long id) {
int ret = fileRepository.deleteFileById(id);
if (ret == 0) {
throw FILE_NOT_FOUND_EXCEPTION;
}
}

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.