Giter Club home page Giter Club logo

project-platypus's Introduction

Project-Platypus

Back-End REST-API written in PHP using the Slim-Framework.

API Documentation

(work in progress)

General API URL: platypus.stair.ch/api/

Type Description
GET Used for retrieving resources.
POST Used for creating resources.
DELETE Used for deleting resources.

User

GET

  • all user: /user
  • user by id: /user/<id>

POST

  • new user: /user -> only user with @stud.hslu.ch email are allowed to register

Feedback

GET

  • all feedback: /feedback
  • all feedback with updated date > lastsync: /feedback?lastsync=val lastsync must be a unixtimestamp
  • feedback by ID: /feedback/<id>

not yet implemented

  • feedback by user ID: /feedback/?user_id=<id>
  • feedback by hashtag: /feedback/?hashtag[]=<hashtag1>&hashtag[]=<hashtag2>

POST

  • new feedback: /feedback

Hashtag

GET

  • all hashtag: /hashtag

Development

If you've used nix before you might find it usable to get all required dependencies automatically. See here nix.md.

Or just install the dependencies yourself:

PHP Development Web-Server

PHPs internal web server is used for development. That means the public/.htaccess file has no affect. Make sure to configure it properly when running this project on Apache or Nginx.

Dependencies

php-cli

You need to install the package to run php as a command line tool. In most distros this package is called php-cli.

composer

Visit getcomposer.org and install composer. There may also be a package available for your distribution.

You can also just download the composer.phar file and run php composer.phar instead of composer. This way you don't need to install anything.

If you've installed composer run one of the following commands (depending on how you've installed composer):

composer install
php composer.phar install

This will download an install the projects PHP dependencies into the ./vendor/ directory.

Running the Development Web Server

You can either run the Development Web-Server through composer or by using the ./serve.sh script.

./serve.sh
composer run start

In the past the version with the script was more reliable because composer has an internal timeout and the server may get killed after 3 minutes.

Database

Move the .env.example to .env and set up your database correctly. Only MySQL is supported as of now (because of the SQL script to import the database, eloquent would support other databases as well).

Use the devScripts/updateDb.sh script to bring your database to the newest state.
Warning: This script will delete your old data and SHOULD NOT be run in production environments.

Use this if if you want to initialise the database:

devScripts/updateDb.sh --renew --seed

Warning: --renew will drop the database you defined in .env. Run it without the renew if you want to set the permissions and create the database yourself.

Use the --docker option to use the mysqlclient inside a docker container.

Unit-Tests

PHPUnit is used as the testing framework. Use either of the following commands to run the tests:

phpunit # uses phpunit provided by the system
vendor/bin/phpunit # used phpunit provided by composer
composer run test # call phpunit through composer

the testsin tests/Functional use a testing database which can be configured in .testenv.

To initialise the test database used by the phpunit tests use the following command:

devScripts/updateDb.sh --renew --seed --test

Developer Info

How to setup your system

  1. create database: mysql -u root -p < ./db/db.sql
  2. add dummy data to your db: mysql -u platypus -p platypusDb < ./db/dummy_data_import.sql
  3. make sure you have to have JWT_SECRET AND JWT_TOKEN in your .env file
  4. run ./devScripts/registerUser.sh
  5. run ./devScripts/getToken.sh
  6. try to make a GET request on localhost:8080/api/v1/user with Header "Authorization" "Bearer %YourToken%" (you find your token under /tmp/project-platypus-token"

issues

mysql -h hostname -u username -p password databasename

If you have isues to connect via myslq, you may need to grant access. There is an example in ./db/db.sql

you may copy it via docker cp ./db/db.sql platypusDb:/tmp

project-platypus's People

Contributors

che4ter avatar mogria avatar wtjerry avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

project-platypus's Issues

make middleware to pass decoded JWT token as part of the request

in src/routes.php

    "callback" => function($request, $response, $arguments) use ($app) {
        // store decoded jwt token in container
        $container = $app->getContainer();
        $container["jwt"] = $arguments["decoded"];
        return true;
    },

Unfortunately slim-jwt-auth does not allow to pass the decoded JWT token as a request attribute and we need to inject the container everytime we use the AuthorizeRequest middleware.

Would be nice if a middleware would do this and the AuthorizeRequest could just validate a request attribute.

Use Travis CI as a Build Server

You may already know about it the service. But we could use travis-ci.org to have a Build Server for continious integration.

I cannot do this for this repository because I'm not the owner. So @Che4ter you will have to do this if you have any intrest in it.

It'll probably work the best if you use the PHP integration of travis CI itself: [https://docs.travis-ci.com/user/languages/php/]

Implement the /api/v1/feedback endpoint

The /api/v1/feedback endpoint is only partially implemented at the Moment.

The user_id shouldn't be aquired from the request parameter, instead it should be aquired from the JWT token. This way it shouldn't be possible to send a fake user_id (of an admin for example).

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.