Skip to content
This repository has been archived by the owner on Dec 3, 2019. It is now read-only.

Commit

Permalink
Merge branch 'release/0.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
kphrx committed Jun 22, 2018
2 parents 67ecdff + 8c88e69 commit 11f27d8
Show file tree
Hide file tree
Showing 55 changed files with 2,805 additions and 557 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ TWITTER_SECRET=

GITHUB_KEY=
GITHUB_SECRET=

GOOGLE_MAPS_JS_API_KEY=
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ Homestead.yaml

# Coverage directory used by tools like istanbul
/coverage

15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ Changelog.

## [Unreleased]

## [Version 0.4 (Pre-Release)][0.4] - 2018-06-23
### Added
- Entries list to index page.
- Entry page & kinds template.
- Entries filter.
- EntryDetails table.
- Google Maps JavaScript API key.

### Changed
- XML Document database to file.
- Optimize entries table.

## [Version 0.3 (Pre-Release)][0.3] - 2018-06-03
### Added
- Support Social login.
Expand Down Expand Up @@ -40,7 +52,8 @@ Changelog.
- Subscribe check.
- Save received feed.

[Unreleased]: https://github.com/kPherox/JMA-Publish-Sharer/compare/v0.3...develop
[Unreleased]: https://github.com/kPherox/JMA-Publish-Sharer/compare/v0.4...develop
[0.4]: https://github.com/kPherox/JMA-Publish-Sharer/compare/v0.3...v0.4
[0.3]: https://github.com/kPherox/JMA-Publish-Sharer/compare/v0.2.2...v0.3
[0.2.2]: https://github.com/kPherox/JMA-Publish-Sharer/compare/v0.2.1...v0.2.2
[0.2.1]: https://github.com/kPherox/JMA-Publish-Sharer/compare/v0.2...v0.2.1
Expand Down
62 changes: 60 additions & 2 deletions app/Eloquents/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;

class Entry extends Model
{
Expand All @@ -13,7 +16,10 @@ class Entry extends Model
* @var array
*/
protected $fillable = [
'uuid', 'kind_of_info', 'feed_uuid', 'observatory_name', 'headline', 'url', 'updated',
'feed_uuid',
'observatory_name',
'headline',
'updated',
];

/**
Expand All @@ -24,10 +30,62 @@ class Entry extends Model
protected $hidden = [];

/**
* Relation feed
* Relation: belong to feed.
**/
public function feed() : BelongsTo
{
return $this->belongsTo('App\Eloquents\Feed', 'feed_uuid', 'uuid');
}

/**
* Relation: has many entry details.
**/
public function entryDetails() : HasMany
{
return $this->hasMany('App\Eloquents\EntryDetail');
}

/**
* Local Scope: where observatory_name.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $observatory
**/
public function scopeWhereObservatoryName(Builder $query, string $observatory) : Builder
{
$observatories = self::select('observatory_name')
->groupBy('observatory_name')
->get()
->filter(function ($entry) use ($observatory) {
$splitedObservatory = collect(preg_split( "/( | )/", $entry->observatory_name));
return ($entry->observatory_name === $observatory || $splitedObservatory->contains($observatory));
})->map(function ($entry) {
return $entry->observatory_name;
});

return $query->whereIn('observatory_name', $observatories);
}

/**
* Mutator: parse headline.
**/
public function getParsedHeadlineAttribute() : Collection
{
preg_match('/【(.*)】(.*)/', $this->headline, $headline);
return collect([
'original' => $headline[0],
'title' => $headline[1],
'headline' => $headline[2],
]);
}

/**
* Mutator: entryDetails kinds.
**/
public function getChildrenKindsAttribute() : Collection
{
return $this->entryDetails->sortByKind()->map(function ($detail) {
return $detail->kind_of_info;
});
}
}
47 changes: 47 additions & 0 deletions app/Eloquents/EntryDetail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace App\Eloquents;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class EntryDetail extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'entry_id',
'kind_of_info',
'url',
'uuid',
'xml_document',
];

/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'xml_document',
];

/**
* Relation: belong to entry.
**/
public function entry() : BelongsTo
{
return $this->belongsTo('App\Eloquents\Entry');
}

/**
* Use key name when route binding.
**/
public function getRouteKeyName() : string
{
return 'uuid';
}
}
26 changes: 24 additions & 2 deletions app/Eloquents/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Builder;

class Feed extends Model
{
Expand All @@ -13,7 +14,9 @@ class Feed extends Model
* @var array
*/
protected $fillable = [
'uuid', 'url', 'updated',
'uuid',
'url',
'updated',
];

/**
Expand All @@ -24,11 +27,30 @@ class Feed extends Model
protected $hidden = [];

/**
* Relation entries
* Relation: has many entries.
**/
public function entries() : HasMany
{
return $this->hasMany('App\Eloquents\Entry', 'feed_uuid', 'uuid');
}

/**
* Local Scope: where url ($type.xml).
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $type
**/
public function scopeWhereType(Builder $query, string $type) : Builder
{
return $query->where('url', 'LIKE', '%'.$type.'.xml');
}

/**
* Mutator: feed type.
**/
public function getTypeAttribute() : string
{
return basename(parse_url($this->url, PHP_URL_PATH), '.xml');
}
}

19 changes: 17 additions & 2 deletions app/Eloquents/LinkedSocialAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,26 @@ class LinkedSocialAccount extends Model
* @var array
*/
protected $fillable = [
'provider_name', 'provider_id', 'name', 'nickname', 'avatar', 'token', 'token_secret'
'provider_name',
'provider_id',
'name',
'nickname',
'avatar',
'token',
'token_secret',
];

/**
* Relation user
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'token_secret',
];

/**
* Relation: belong to user.
**/
public function user() : BelongsTo
{
Expand Down
15 changes: 9 additions & 6 deletions app/Eloquents/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ class User extends Authenticatable
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
'name',
'email',
'password',
];

/**
Expand All @@ -25,11 +27,12 @@ class User extends Authenticatable
* @var array
*/
protected $hidden = [
'password', 'remember_token',
'password',
'remember_token',
];

/**
* Relation social accounts
* Relation: has many social accounts.
**/
public function accounts() : HasMany
{
Expand All @@ -39,23 +42,23 @@ public function accounts() : HasMany
/**
* Exists value of email column
**/
public function existsEmail() : Bool
public function existsEmail() : bool
{
return isset($this->email);
}

/**
* Exists value of password column
**/
public function existsPassword() : Bool
public function existsPassword() : bool
{
return isset($this->password);
}

/**
* Exists value of email column and password column
**/
public function existsEmailAndPassword() : Bool
public function existsEmailAndPassword() : bool
{
return $this->existsEmail() && $this->existsPassword();
}
Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/Auth/GitHubAccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use Illuminate\Http\RedirectResponse;

class GitHubAccountController extends SocialAccountController
Expand Down
32 changes: 20 additions & 12 deletions app/Http/Controllers/Auth/SocialAccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use App\Http\Controllers\Controller;
Expand All @@ -13,22 +12,24 @@ abstract class SocialAccountController extends Controller
/**
* Provider name.
*
* @var String
* @var string
**/
private $provider = '';
private $provider;

/**
* Getter for provider name.
**/
protected function getProvider() : String
protected function getProvider() : string
{
return $this->provider;
}

/**
* Setter for provider name.
*
* @param string $value
**/
protected function setProvider(String $value) : String
protected function setProvider(string $value) : string
{
return $this->provider = $value;
}
Expand All @@ -49,23 +50,28 @@ public function linkToUser() : RedirectResponse
/**
* Unlink account from User.
*
* @return RedirectResponse|JsonResponse
* @param \App\Services\SocialAccountsService $accountService
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
*/
public function unlinkFromUser(SocialAccountsService $accountService, Request $request)
public function unlinkFromUser(SocialAccountsService $accountService)
{
$isAjax = request()->ajax();

try {
$message = $accountService->deleteLinkedAccount($this->getProvider(), (Int)$request->id);
$message = $accountService->deleteLinkedAccount($this->getProvider(), (int)request('id'));
} catch (\Exception $e) {
abort_if(!$request->ajax(), 403, 'Can\'t delete');

return new JsonResponse([
if ($isAjax) {
return new JsonResponse([
'status' => 'Can\'t delete',
'statusCode' => 403,
'message' => $e->getMessage(),
], 403);
}

abort(403, 'Can\'t delete');
}

if ($request->ajax()) {
if ($isAjax) {
return new JsonResponse([
'status' => 'OK',
'statusCode' => 201,
Expand All @@ -78,6 +84,8 @@ public function unlinkFromUser(SocialAccountsService $accountService, Request $r

/**
* Obtain the user information
*
* @param \App\Services\SocialAccountsService $accountService
*/
public function handleProviderCallback(SocialAccountsService $accountService) : RedirectResponse
{
Expand Down
Loading

0 comments on commit 11f27d8

Please sign in to comment.