Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Feature/json export #171

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_size = 2

[{Makefile,**.mk}]
# Use tabs for indentation (Makefiles require tabs)
indent_style = tab
12 changes: 6 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ APP_ENV=local
APP_DEBUG=true
APP_KEY=B5CLY5YFG5c7X4aTLw13AxmtrkVTcUWb

DB_HOST=localhost
DB_HOST_READ=localhost
DB_DATABASE=muhit
DB_USERNAME=homestead
DB_PASSWORD=secret

RDS_HOST=127.0.0.1
DB_HOST=muhit-db
DB_HOST_READ=muhit-db
DB_DATABASE=muhit
DB_USERNAME=muhit
DB_PASSWORD=11235
RDS_HOST=muhit-redis

CACHE_DRIVER=redis
SESSION_DRIVER=redis
Expand Down
17 changes: 0 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,3 @@ before_deploy:
- rm -rf node_modules/
- zip -qr ../MuhitAPP-${TRAVIS_BUILD_NUMBER}.zip ./*
- mv ../MuhitAPP-${TRAVIS_BUILD_NUMBER}.zip ${TRAVIS_BUILD_DIR}/

deploy:
- provider: elasticbeanstalk
skip_cleanup: true
zip_file: MuhitAPP-${TRAVIS_BUILD_NUMBER}.zip
access_key_id:
secure: QQYc+cdhycjmxInCd1qCNeUQptZyJPAjHl5tAY6b54YuhWIzJapnXrWWeL0snebelzRvi82vk+Tc7YcK0zIzsXM62/K4OUqA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dkKJ1TbBI6Vp4hrMcwntRF1jKdoWVbOBTivrGodffhgB411OeHZKTvfPm3sgPttjnUq1OR4aHcjOm7LqIGBkNpN202R64OcBNFN25iWYH1JtCFDrexxiDcgCIuf2kAehVSe0Wfp7hRqF0UKIWyfv8s2mEq1YWMhrKs5a/5XkiyPSPzuUo5wl/osyavBHF3ZOCo2ot2msmA8EGuEcKPVLUw=
region: eu-west-1
app:
secure: LBezfVKi8ZOVae10OEVdjNNp7sM3qQcDKm7R+BPkwdqMK4TqgE1sdQVpBQw8F/2hIB7Eo7zI6HJKfoNqZfgtB9OMQjq2/wQYhMziJGNAe8n6fcuxXcHTv1vFpLk0LRDz3HXSKZQiGibw1pKAziZQHq/qqTrSZQzOHWoEHAzDI9J8H+hY0+Gb+RI/veN+0MyyOxDbD7TZkd4ByEJb1GlajIy0/DAZhvzd5jqyl1jODhV9VK5+JJNY+bUdjKQrSBopMZgEE8xSxvvQOcelgcMof9CqhwF921LsL9i7cgQNE7CeOeTbV3CDY8hOGlOwafZJGb4CZmLEXQVnfjBI2FcIpXCvFTVMIPJqEpywuWRCq4gB0KGw1IOEjRlfL/1kbgI3Bjsi/p1POeKL7Krm4DZE6p4hysx3zZLGDxIBswrzH4Gq5f8pw0xAJkxq6f3fQa5D/KBK7K9QI+v7+rbX6ezt7IHDDnIj1xxpdiKSDgkZc+4VjAGjaUWu/DBfff+bjpslQy9XcZ/ujZ8muHTbZOiuqpjw38zx3HVo/SQqRo435Bq1GHI4uSvS5ryaYAl3Obbgj6zKZNRzRA1EeRTEGcJYUDKpmuzKq0ZkoL8Fu6XjTV8z8UzHItjKrPPI7I5tDRA4m0MaDjYp5uuV8md9Ii9+ebsJDPb4yD7Lw8ghySo8AKQ=
env: app-live
bucket_name: muhit-travis-ci
on:
repo: Muhit-co/api
branch: master
57 changes: 57 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
FROM php:fpm-alpine3.10

RUN apk --update add wget \
curl \
git \
grep \
nginx \
build-base \
libmemcached-dev \
libmcrypt-dev \
libxml2-dev \
zlib-dev \
autoconf \
cyrus-sasl-dev \
libgsasl-dev \
supervisor \
re2c \
openssl \
nodejs \
npm

RUN docker-php-ext-install mysqli mbstring pdo pdo_mysql tokenizer xml opcache soap

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# install igbinary
RUN cd /tmp && \
wget https://github.com/igbinary/igbinary/archive/3.0.1.zip && \
unzip 3.0.1.zip && cd igbinary-3.0.1 && \
phpize && ./configure && make && make install && \
docker-php-ext-enable igbinary

# install memcached
RUN cd /tmp && \
wget https://github.com/php-memcached-dev/php-memcached/archive/v3.1.3.zip && \
unzip v3.1.3.zip && cd php-memcached-3.1.3 && \
phpize && ./configure --enable-memcached-igbinary && make && make install && \
docker-php-ext-enable memcached

# clean up and create www
RUN mkdir -p /var/www && \
rm -rf /tmp/*

WORKDIR /var/www/html

COPY . ./
RUN composer install
RUN chown -R www-data:www-data ./

# copy service configs and files
COPY docker/nginx.conf /etc/nginx/nginx.conf
COPY docker/php-uploads.ini /usr/local/etc/php/conf.d/uploads.ini
COPY docker/supervisord.conf /etc/supervisord.conf

EXPOSE 80

ENTRYPOINT ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"]
70 changes: 70 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
.PHONY: build build-prod composer dev check test docker-dev docker-build ci dev-db release gulp

# Install composer and node deps and run composer scripts.
build:
docker build -t muhit/web .

# This will install composer packages but will not run scripts.
build-prod:
composer install --no-scripts --no-dev

# Alias for building and running docker composer
dev: docker-dev

# Alias for running composer checks script
check:
composer checks

# Alias for running composer test script
test:
composer test

# Creates the development environment with docker compose
docker-dev:
-chmod -Rf 777 storage/
docker-compose -f docker-compose-dev.yml up

# Rebuilds the docker images if something changes.
docker-build:
docker-compose -f docker-compose-dev.yml build

# Alias to run on CI environment.
ci:
make build-prod

# Runs the artisan db commands
dev-db:
docker exec -i api_muhitweb_1 /usr/local/bin/php artisan migrate
docker exec -i api_muhitweb_1 /usr/local/bin/php artisan db:seed

# Removes everything in development database
dev-db-refresh:
docker exec -i api_muhitweb_1 /usr/local/bin/php artisan migrate:fresh

# Runs the rollback command on the docker
dev-rollback:
docker exec -i api_muhitweb_1 /usr/local/bin/php artisan migrate:rollback

# clears caches on docker
view-clear:
docker exec -i api_muhitweb_1 /usr/local/bin/php artisan view:clear
docker exec -i api_muhitweb_1 /usr/local/bin/php artisan view:cache

# install npm and run gulp
gulp:
docker exec -i api_muhitweb_1 npm install
docker exec -i api_muhitweb_1 ./node_modules/.bin/gulp --production

# reads the latest tag, creates a new release incrementing the patch number
release:
$(eval branch := $(shell git rev-parse --abbrev-ref HEAD))
$(eval v := $(shell git describe --tags --abbrev=0 | sed -Ee 's/^v|-.*//'))
$(eval f := 3)
$(eval n := $(shell echo $(v) | awk -F. -v OFS=. -v f=$(f) '{ $$f++ } 1'))
git flow release start $(n)
git flow release finish $(n)
git push origin develop
git push --tags
git checkout master
git push origin master
git checkout develop
79 changes: 79 additions & 0 deletions app/Console/Commands/DataExporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

namespace Muhit\Console\Commands;

use Illuminate\Console\Command;
use Muhit\Models\Tag;
use Muhit\Models\Hood;
use Muhit\Models\Issue;

class DataExporter extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'export {target}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Exports givin target as json.';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$target = $this->argument('target');
switch ($target) {
case 'tags':
$this->tags();
break;

case 'hoods':
$this->hoods();
break;
case 'issues':
$this->issues();
break;

default:
$this->comment("No default target");
break;
}
}

public function tags()
{
$tags = Tag::all();
echo $tags->toJson();
}

public function hoods()
{
$hoods = Hood::all();
echo $hoods->toJson();
}

public function issues()
{
$issues = Issue::with('comments.user', 'user', 'tags', 'images', 'updates')->get();
echo $issues->toJson();
}
}
1 change: 1 addition & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Kernel extends ConsoleKernel {
*/
protected $commands = [
'Muhit\Console\Commands\Inspire',
'Muhit\Console\Commands\DataExporter',
];

/**
Expand Down
9 changes: 9 additions & 0 deletions app/Models/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@ class Comment extends \Eloquent
{

protected $guarded = ['id'];
protected $hidden = [
'issue_id',
'user_id',
];

public function muhtar()
{
return $this->belongsTo(User::class, 'user_id');
}

public function user()
{
return $this->belongsTo(User::class, 'user_id');
}

public function issue()
{
return $this->belongsTo(Issue::class, 'issue_id');
Expand Down
7 changes: 5 additions & 2 deletions app/Models/Issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class Issue extends \Eloquent

protected $guarded = ['id'];
protected $dates = ['deleted_at'];
protected $hidden = [
'deleted_at',
];

public function tags()
{
Expand Down Expand Up @@ -40,8 +43,8 @@ public function comments()
public function toArray($user_id = null)
{
$array = parent::toArray();
$array['supporter_counter'] = (int)Redis::get('supporter_counter:' . $this->id);
$array['is_supported'] = (((int)Redis::zscore('issue_supporters:' . $this->id, $user_id) > 0) ? 1 : 0);
//$array['supporter_counter'] = (int)Redis::get('supporter_counter:' . $this->id);
//$array['is_supported'] = (((int)Redis::zscore('issue_supporters:' . $this->id, $user_id) > 0) ? 1 : 0);
return $array;
}

Expand Down
5 changes: 5 additions & 0 deletions app/Models/IssueImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@
class IssueImage extends \Eloquent
{
protected $guarded = ['id'];
protected $hidden = [
'created_at',
'updated_at',
'issue_id',
];
}
5 changes: 4 additions & 1 deletion app/Models/IssueUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@

class IssueUpdate extends \Eloquent
{

protected $hidden = [
'issue_id',
'updated_at',
];
}
14 changes: 8 additions & 6 deletions app/Models/Tag.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<?php namespace Muhit\Models;

use Redis;
use DB;

class Tag extends \Eloquent
{

protected $guarded = ['id'];
protected $appends = ['issue_counter'];
protected $hidden = [
'created_at',
'updated_at',
];

public function toArray()
public function getIssueCounterAttribute()
{
$array = parent::toArray();
$array['issue_counter'] = (int)Redis::get('tag_issue_counter:' . $this->id);

return $array;
return DB::table('issue_tag')->where('tag_id', $this->id)->count();
}
}
19 changes: 18 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,24 @@ class User extends \Eloquent implements AuthenticatableContract
*
* @var array
*/
protected $hidden = ['password', 'remember_token'];
protected $hidden = [
'password',
'remember_token',
'supported_issue_counter',
'opened_issue_counter',
'admin_type',
'verify_token',
'deleted_at',
'phone',
'password_token_expires_at',
'password_reset_token',
'coordinates',
'location',
'hood_id',
'level',
'updated_at',
'created_at',
];

protected $appends = ['full_name'];

Expand Down
Loading