2021-03-20 09:40:32 +00:00
# LocalSpend (Server)
2020-08-25 16:38:10 +00:00
2021-03-20 09:40:32 +00:00
Looking to discover if the value of spending local can be measured, understood and shown.
2017-04-21 22:48:37 +00:00
2021-03-20 09:40:32 +00:00
This repository contains the server application for the LocalSpend system. See also:
2020-08-25 16:38:10 +00:00
2021-03-20 09:40:32 +00:00
* the [Web application ](https://github.com/Pear-Trading/Foodloop-Web ); and
* the [mobile application ](https://github.com/Pear-Trading/LocalSpend-Tracker ).
2017-09-26 16:03:27 +00:00
2021-03-20 09:40:32 +00:00
## Current Status
2017-09-26 16:03:27 +00:00
2021-03-20 09:40:32 +00:00
| Branch | Status |
|---------------|------------------ |
| `master` | [![Build Status ](https://travis-ci.org/Pear-Trading/Foodloop-Server.svg?branch=master )](https://travis-ci.org/Pear-Trading/Foodloop-Server) |
| `development` | [![Build Status ](https://travis-ci.org/Pear-Trading/Foodloop-Server.svg?branch=development )](https://travis-ci.org/Pear-Trading/Foodloop-Server) |
2017-09-26 16:03:27 +00:00
2021-03-20 09:40:32 +00:00
## Table of Contents
2017-09-26 16:03:27 +00:00
2021-03-20 09:40:32 +00:00
* [Tech Stack ](#tech-stack )
* [Features ](#features )
* [Installation ](#installation )
* [Configuration ](#configuration )
* [Usage ](#usage )
* [Testing ](#testing )
* [Code Formatting ](#code-formatting )
* [Documentation ](#documentation )
* [Acknowledgments ](#acknowledgements )
* [License ](#license )
* [Contact ](#contact )
2017-09-26 16:03:27 +00:00
2021-03-20 09:40:32 +00:00
## Technology Stack
2018-03-20 19:24:48 +00:00
2021-03-20 09:40:32 +00:00
The server app. is written in [Perl ](https://www.perl.org/ ).
2018-03-20 19:24:48 +00:00
2021-03-20 11:52:59 +00:00
Admin. portal pages are templated using [HTML::EP ](https://metacpan.org/pod/distribution/HTML-EP/lib/HTML/EP.pod ).
2021-03-20 11:41:18 +00:00
| Technology | Description | Link |
|-------------|--------------------------------------|---------------------|
| Mojolicious | Perl Web framework | [Link][mojolicious] |
| PostgreSQL | Relational database managment system | [Link][postgresql] |
2021-03-20 11:52:59 +00:00
| SQLite | Relational database managment system | [Link][sqlite] |
2018-03-20 19:24:48 +00:00
2021-03-20 09:40:32 +00:00
[mojolicious]: https://mojolicious.org/
[postgresql]: https://www.postgresql.org/
2021-03-20 11:52:59 +00:00
[sqlite]: https://sqlite.org/index.html
2018-03-20 19:24:48 +00:00
2021-03-20 09:40:32 +00:00
## Features
2018-03-20 19:24:48 +00:00
2021-03-20 09:40:32 +00:00
This server app. provides:
2019-09-09 14:37:26 +00:00
2021-03-20 09:40:32 +00:00
- user creation, updating and deletion;
- organisation creation, updating and deletion;
2021-03-20 11:41:18 +00:00
- an admin. management portal;
2021-03-20 09:40:32 +00:00
- transaction logging;
- transaction history analysis; and
- leaderboard generation.
2019-09-09 14:37:26 +00:00
2021-03-20 09:40:32 +00:00
## Installation
2019-09-09 14:37:26 +00:00
2021-03-20 09:40:32 +00:00
1. Clone the repo. to your dev. environment (`git clone git@github.com:Pear-Trading/FoodLoop-Server.git`);
1. enter the new directory (`cd FoodLoop-Server`);
1. install the dependencies:
2020-08-25 16:50:11 +00:00
- ```shell script
2021-03-20 09:40:32 +00:00
cpanm --installdeps . \
--with-feature=sqlite \
--with-feature=codepoint-open
2020-08-25 16:50:11 +00:00
```
2021-03-20 09:40:32 +00:00
- if you are using a PostgreSQL database, replace `--with-feature=sqlite` with `--with-feature=postgres` .
1. install the database:
2021-03-20 11:41:18 +00:00
- run `./script/deploy_db install -c 'dbi:SQLite:dbname=foodloop.db'` ;
- development supports both SQLite and PostgreSQL (production uses PostgreSQL);
- for this example we will use SQLite; so
2021-03-20 09:40:32 +00:00
- as the default config. is set up for this, no configuration changes are needed initially.
1. set up the development users:
- `./script/pear-local_loop dev_data --force`
2021-03-20 11:41:18 +00:00
- **DO NOT RUN ON PROD!**
1. start the [Minion ](https://docs.mojolicious.org/Minion ) job scheduler:
2021-03-20 09:40:32 +00:00
- `./script/pear-local_loop minion worker`
1. import ward data:
1. Download the CSV(s) from [here ](https://www.doogal.co.uk/PostcodeDownloads.php ); and
1. run the following command:
- ```shell script
./script/pear-local_loop minion job \
--enqueue 'csv_postcode_import' \
--args '[ "⟨ path to CSV ⟩ ]'
```
1. set up postcodes:
1. import [Code-Point Open ](https://www.ordnancesurvey.co.uk/business-government/products/code-point-open ):
- a copy is included in `etc/` ;
- run `./script/pear-local_loop codepoint_open --outcodes LA1`
1. assign postcodes:
- ```shell script
./script/pear-local_loop minion job \
--enqueue entity_postcode_lookup
```
2018-03-20 19:24:48 +00:00
2021-03-20 09:40:32 +00:00
## Configuration
2019-09-09 17:03:08 +00:00
2021-03-20 09:40:32 +00:00
App. configuration settings are found in `pear-local_loop.⟨environment⟩.conf` .
2019-09-09 17:03:08 +00:00
2021-03-20 11:41:18 +00:00
[Firebase Cloud Messaging ](https://firebase.google.com/docs/cloud-messaging/ ) (FCM) credentials should be placed in a file called `localspend-47012.json` in root. This file is not tracked by Git; ask another developer for a copy.
Default user credentials are found in `lib/Pear/LocalLoop/Command/dev_data.pm` .
2018-03-20 19:24:48 +00:00
2021-03-20 09:40:32 +00:00
## Usage
2018-03-20 19:24:48 +00:00
2021-03-20 11:41:18 +00:00
- Run `./script/pear-local_loop minion worker` to start the Minion asynchronous job scheduler; and
- run `morbo script/pear-local_loop -l http://*:3000` to start the server on the specific hostname and port.
2019-09-09 14:37:26 +00:00
2021-03-20 09:40:32 +00:00
### Database Scripts
2019-09-09 14:37:26 +00:00
2021-03-20 09:40:32 +00:00
To upgrade the database after making changes to commit:
2019-09-09 14:37:26 +00:00
2021-03-20 09:40:32 +00:00
1. Increment the `$VERSION` number in `lib/Pear/LocalLoop/Schema.pm` ;
1. run `./script/deploy_db write_ddl -c 'dbi:SQLite:dbname=foodloop.db'` ; and
1. run `./script/deploy_db upgrade -c 'dbi:SQLite:dbname=foodloop.db'` .
2020-08-25 16:38:10 +00:00
2021-03-20 09:40:32 +00:00
Run `./script/pear-local_loop recalc_leaderboards` to update the leaderboards.
2020-08-25 16:38:10 +00:00
2021-03-20 09:40:32 +00:00
## Testing
- Run `prove -lr` to run the full test suite using [Test-Simple ](https://metacpan.org/release/Test-Simple ) (when using an SQLite database); and
- run `PEAR_TEST_PG=1 prove -lr` to run the full test suite (when using a PostgreSQL database).
2021-03-20 11:41:18 +00:00
Test files are found in the `t/` directory.
2021-03-20 09:40:32 +00:00
## Code Formatting
2019-07-03 16:36:36 +00:00
2021-03-20 12:09:50 +00:00
Run `for f in ./lib/**/*.pm; do perltidy -b $f; done` to format all Perl files
2021-03-20 13:22:29 +00:00
with [Perl-Tidy ](https://metacpan.org/release/Perl-Tidy ) (there is no built-in
option to format files recursively).
2021-03-20 12:09:50 +00:00
Run `perlcritic lib` to lint all Perl files with [Perl-Critic ](https://metacpan.org/release/Perl-Critic ).
2019-07-03 16:36:36 +00:00
2021-03-20 09:40:32 +00:00
## Documentation
2019-07-03 16:36:36 +00:00
2021-03-20 09:40:32 +00:00
TODO
2020-10-14 12:40:56 +00:00
2021-03-20 09:40:32 +00:00
## Acknowledgements
2020-10-14 12:40:56 +00:00
2021-03-20 09:40:32 +00:00
LocalLoop is the result of collaboration between the [Small Green Consultancy ](http://www.smallgreenconsultancy.co.uk/ ), [Shadowcat Systems ](https://shadow.cat/ ), [Independent Lancaster ](http://www.independent-lancaster.co.uk/ ) and the [Ethical Small Traders Association ](http://www.lancasteresta.org/ ).
2020-10-14 12:40:56 +00:00
2021-03-20 09:40:32 +00:00
## License
2020-10-14 12:40:56 +00:00
2021-03-20 09:40:32 +00:00
This project is released under the [MIT license ](https://mit-license.org/ ).
2020-10-14 12:40:56 +00:00
2021-03-20 09:40:32 +00:00
## Contact
2020-10-14 12:40:56 +00:00
2021-03-20 09:40:32 +00:00
| Name | Link(s) |
|----------------|-------------------|
| Mark Keating | [Email][mkeating] |
| Michael Hallam | [Email][mhallam] |
2020-10-14 12:40:56 +00:00
2021-03-20 09:40:32 +00:00
[mkeating]: mailto:m.keating@shadowcat.co.uk
[mhallam]: mailto:info@lancasteresta.org