Skip to content

Commit

Permalink
🔖 Release v1.11.9
Browse files Browse the repository at this point in the history
Release v1.11.9
  • Loading branch information
MrKrisKrisu authored Oct 22, 2021
2 parents 1e8a03d + 125da60 commit 3eb84c6
Show file tree
Hide file tree
Showing 119 changed files with 1,571 additions and 3,754 deletions.
6 changes: 6 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ class Kernel extends ConsoleKernel
* Define the application's command schedule.
*
* @param Schedule $schedule
*
* @return void
*/
protected function schedule(Schedule $schedule): void {
$schedule->command('trwl:cleanUpUsers')->daily();
$schedule->command('trwl:cleanUpHafasTrips')->daily();
$schedule->command('trwl:cleanUpPolylines')->daily();
$schedule->command('trwl:cleanUpUsers')->dailyAt("1:30");
$schedule->command('trwl:cleanUpHafasTrips')->dailyAt("1:35");
$schedule->command('trwl:cleanUpPolylines')->dailyAt("1:40");
$schedule->command('trwl:refreshTrips')->everyMinute();
}

Expand Down
6 changes: 5 additions & 1 deletion app/Http/Controllers/API/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

namespace App\Http\Controllers\API;

use App\Http\Controllers\API\ResponseController as ResponseController;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;

/**
* @deprecated Will be replaced by APIv1
*/
class AuthController extends ResponseController
{
//create user
Expand Down Expand Up @@ -44,6 +46,7 @@ public function signup(Request $request) {

/**
* @param Request $request
*
* @return \Illuminate\Http\JsonResponse
* @deprecated with apiv1
*/
Expand Down Expand Up @@ -72,6 +75,7 @@ public function login(Request $request) {

/**
* @param Request $request
*
* @return \Illuminate\Http\JsonResponse
* @deprecated with apiv1
*/
Expand Down
5 changes: 4 additions & 1 deletion app/Http/Controllers/API/NotificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Illuminate\Http\Request;
use Illuminate\Http\Response;

/**
* @deprecated Will be replaced by APIv1
*/
class NotificationController extends ResponseController
{
/**
Expand All @@ -23,7 +26,7 @@ public function index(): JsonResponse {
* Update the specified resource in storage.
*
* @param Request $request
* @param int $notificationID
* @param int $notificationID
*
* @return Response
*/
Expand Down
11 changes: 7 additions & 4 deletions app/Http/Controllers/API/ResponseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@

namespace App\Http\Controllers\API;

use App\Http\Controllers\Controller as Controller;
use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;

/**
* @deprecated Will be replaced by APIv1
*/
class ResponseController extends Controller
{
public function sendResponse($response): JsonResponse {
return response()->json($response, 200);
return response()->json($response);
}

public function sendv1Response(
array|string|object $data = null,
int $code = 200,
array $additional = null
int $code = 200,
array $additional = null
): JsonResponse {
if ($data === null) {
return response()->json(["status" => "success"], $code);
Expand Down
11 changes: 7 additions & 4 deletions app/Http/Controllers/API/StatusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
use Illuminate\Support\Facades\Validator;
use InvalidArgumentException;

/**
* @deprecated Will be replaced by APIv1
*/
class StatusController extends ResponseController
{

Expand Down Expand Up @@ -77,10 +80,10 @@ public function update(Request $request): JsonResponse {
}
try {
$editStatusResponse = StatusBackend::EditStatus(
user: Auth::user(),
statusId: $request['statusId'],
body: $request['body'],
business: $request['businessCheck'],
user: Auth::user(),
statusId: $request['statusId'],
body: $request['body'],
business: $request['businessCheck'],
visibility: null
);
} catch (ModelNotFoundException) {
Expand Down
11 changes: 10 additions & 1 deletion app/Http/Controllers/API/TransportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,19 @@
use Illuminate\Validation\Rule;
use Throwable;

/**
* @deprecated Will be replaced by APIv1
*/
class TransportController extends ResponseController
{
public function TrainAutocomplete($station): JsonResponse {
$trainAutocompleteResponse = TransportBackend::TrainAutocomplete($station);
$trainAutocompleteResponse = TransportBackend::getTrainStationAutocomplete($station)->map(function($station) {
return [
'id' => $station['ibnr'],
'name' => $station['name'],
'provider' => 'train'
];
});
return $this->sendResponse($trainAutocompleteResponse);
}

Expand Down
3 changes: 3 additions & 0 deletions app/Http/Controllers/API/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

/**
* @deprecated Will be replaced by APIv1
*/
class UserController extends ResponseController
{
public function show($username) {
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class LoginController extends Controller
*
* @var string
*/
protected $redirectTo = '/dashboard';
protected string $redirectTo = '/dashboard';

/**
* Create a new controller instance.
Expand All @@ -38,7 +38,7 @@ public function __construct() {
$this->middleware('guest')->except('logout');
}

protected function authenticated(Request $request, $user) {
protected function authenticated(Request $request, $user): void {
$user->update(['last_login' => Carbon::now()->toIso8601String()]);
}
}
19 changes: 11 additions & 8 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Contracts\Validation\Validator as ContractsValidator;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
Expand All @@ -28,7 +29,7 @@ class RegisterController extends Controller
*
* @var string
*/
protected $redirectTo = '/dashboard';
protected string $redirectTo = '/dashboard';

/**
* Create a new controller instance.
Expand All @@ -43,13 +44,14 @@ public function __construct() {
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*
* @return ContractsValidator
*/
protected function validator(array $data) {
protected function validator(array $data): ContractsValidator {
return Validator::make($data, [
'username' => ['required', 'string', 'max:15', 'regex:/^[a-zA-Z0-9_]*$/', 'unique:users'],
'username' => ['required', 'string', 'max:25', 'regex:/^[a-zA-Z0-9_]*$/', 'unique:users'],
'name' => ['required', 'string', 'max:50'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'email' => ['required', 'string', 'email:rfc,dns', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
}
Expand All @@ -58,13 +60,14 @@ protected function validator(array $data) {
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
*
* @return User
*/
protected function create(array $data) {
protected function create(array $data): User {
return User::create([
'username' => $data['username'],
'name' => $data['name'],
'email' => $data['email'],
'email' => strtolower($data['email']),
'password' => Hash::make($data['password']),
]);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/ResetPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ResetPasswordController extends Controller
*
* @var string
*/
protected $redirectTo = '/dashboard';
protected string $redirectTo = '/dashboard';

/**
* Create a new controller instance.
Expand Down
25 changes: 24 additions & 1 deletion app/Http/Controllers/Auth/VerificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\VerifiesEmails;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;

class VerificationController extends Controller
{
Expand All @@ -25,7 +28,7 @@ class VerificationController extends Controller
*
* @var string
*/
protected $redirectTo = '/dashboard';
protected string $redirectTo = '/dashboard';

/**
* Create a new controller instance.
Expand All @@ -37,4 +40,24 @@ public function __construct() {
$this->middleware('signed')->only('verify');
$this->middleware('throttle:6,1')->only('verify', 'resend');
}

/**
* Resend the email verification notification.
* Overrides function in parent because of the response
*
* @param Request $request
*
* @return JsonResponse|RedirectResponse
*/
public function resend(Request $request): JsonResponse|RedirectResponse {
if ($request->user()->hasVerifiedEmail()) {
return $request->wantsJson() ? new JsonResponse([], 204) : redirect($this->redirectPath());
}

$request->user()->sendEmailVerificationNotification();

return $request->wantsJson()
? new JsonResponse([], 202)
: back()->with('success', __('email.verification.sent'));
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/Backend/Admin/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static function getHafasAndPolylinesByDate(Carbon $since, Carbon $until):
})->sortBy('date');
}

private static function fillDates(Carbon $since, Carbon $until, $data, array $exampleData = []) {
private static function fillDates(Carbon $since, Carbon $until, $data, array $exampleData = []): void {
for ($date = $since->clone(); $date->isBefore($until); $date->addDay()) {
if (!$data->contains('date', $date->toDateString())) {
$row = new stdClass();
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Backend/Admin/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ private static function createSlug(string $name): string {

$i = "";
while (Event::where('slug', '=', $slug . $i)->first()) {
$i = $i == "" ? 1 : $i + 1;
$i = empty($i) ? 1 : $i + 1;
}
if ($i != "") {
if (!empty($i)) {
return $slug . $i;
}
return $slug;
Expand Down
8 changes: 6 additions & 2 deletions app/Http/Controllers/Backend/Admin/TelegramController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

use App\Http\Controllers\Controller;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;

abstract class TelegramController extends Controller
{
public static function sendAdminMessage(string $message) {
$client = new Client(['base_uri' => 'https://api.telegram.org']);
/**
* @throws GuzzleException
*/
public static function sendAdminMessage(string $message): void {
$client = new Client(['base_uri' => 'https://api.telegram.org']);
$client->get(strtr('/bot:token/sendMessage', [':token' => config('app.telegram.token')]), [
'query' => [
'chat_id' => config('app.telegram.admin_id'),
Expand Down
17 changes: 9 additions & 8 deletions app/Http/Controllers/Backend/GeoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ public static function calculateDistance(

/**
* Fallback calculation if no polyline is given. Calculates the length using the coordinates of the stations.
* @param HafasTrip $hafasTrip
*
* @param HafasTrip $hafasTrip
* @param TrainStopover $origin
* @param TrainStopover $destination
*
* @return float
*/
private static function calculateDistanceByStopovers(
Expand All @@ -73,10 +75,10 @@ private static function calculateDistanceByStopovers(
): int {
$stopovers = $hafasTrip->stopoversNEW->sortBy('departure');
$originStopoverIndex = $stopovers->search(function($item) use ($origin) {
return $item->id == $origin->id;
return $item->is($origin);
});
$destinationStopoverIndex = $stopovers->search(function($item) use ($destination) {
return $item->id == $destination->id;
return $item->is($destination);
});

$stopovers = $stopovers->slice($originStopoverIndex, $destinationStopoverIndex - $originStopoverIndex + 1);
Expand Down Expand Up @@ -111,11 +113,10 @@ public static function calculateDistanceBetweenCoordinates(

$equatorialRadiusInMeters = 6378137;

$pi = pi();
$latA = $latitudeA / 180 * $pi;
$lonA = $longitudeA / 180 * $pi;
$latB = $latitudeB / 180 * $pi;
$lonB = $longitudeB / 180 * $pi;
$latA = $latitudeA / 180 * M_PI;
$lonA = $longitudeA / 180 * M_PI;
$latB = $latitudeB / 180 * M_PI;
$lonB = $longitudeB / 180 * M_PI;
$distance = acos(sin($latA) * sin($latB) + cos($latA) * cos($latB) * cos($lonB - $lonA))
* $equatorialRadiusInMeters;

Expand Down
Loading

0 comments on commit 3eb84c6

Please sign in to comment.