Skip to content

Commit

Permalink
Merge pull request #59 from xTeamTEICM/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Jordan Kostelidis authored Dec 18, 2017
2 parents 3e271b3 + 8b3ec83 commit 0385c67
Show file tree
Hide file tree
Showing 38 changed files with 1,019 additions and 5,854 deletions.
5 changes: 4 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_SECRET=

FCM_SERVER_KEY=AAAAdFX6a_s:APA91bFd8ImrkEBtsHfMnPUISRvFkyHcXoPme5VKMC-I2028ybYLY_6cRmGIq8gjrHEA1iRSuPJjtoQ_YwvxkdZknYHBJ5gXnWDTnCtQtmJSNqIdv4TGwmpFyDjGA1rZquFsgET_9tK9
FCM_SENDER_ID=499658681339
File renamed without changes.
42 changes: 0 additions & 42 deletions app/Console/Commands/helloWorldController.php

This file was deleted.

14 changes: 0 additions & 14 deletions app/Discounts.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Http\Controllers\AuthApi;
namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Http\Controllers\AuthApi;
namespace App\Http\Controllers\Auth;

use App\User;
use Illuminate\Http\Request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,36 @@

class categoryController extends Controller
{
//
public function list () {

public function list()
{
return category::all();
}
public function get($id){

public function get($id)
{
return category::find($id);
}
public function post(){
//TODO EXEI Security issue -> mporei o opoiosdipote na valei katigoria

public function post()
{
$category = new category();
$category->title = Input::get('title');
$category->save();
return $category;
}
public function update(){

public function update()
{
$category = category::find(Input::get('id'));
$category->title = Input::get('title');
$category->save();
return $category;
}
public function remove($title){
//$category = new category();

public function remove($title)
{
$category = category::find($title);
//return $category;
$category->delete();
}

Expand Down
21 changes: 21 additions & 0 deletions app/Http/Controllers/DeviceTokenController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;

class deviceTokenController extends Controller
{
public function setDeviceToken(Request $request)
{
$this->validate($request, [
'deviceToken' => 'required|String',
]);

$id = auth('api')->user()->id;
User::query()
->where("id", "=", $id)
->update(['deviceToken' => request('deviceToken')]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,37 @@

class discountController extends Controller
{
public function list(){

public function list()
{
return Discount::all();

}


public function get($id){

public function get($id)
{
$request = new Request();
$request['id'] = $id;

$data = $this->validate($request, [
'id' => 'required|numeric'
]);



return Discount::query()->where('shopId', '=', $data['id'])->first();




}

public function post(Request $request){

public function post(Request $request)
{
$data = $this->validate($request, [

'shopId' => 'required|numeric',
'category' => 'required|numeric',
'originalPrice' => 'required|numeric',
'currentPrice' => 'required|numeric',
'description' => 'required|string',
'image' => 'required|string'
]);

//trexei alla den ksero giati, einai arga kleinoun ta matia, i need coffeeeeeeeeeee

$userId = Auth::user()->id;
$shopId = Shop::query()->where('ownerId','=',$userId)->value('id');



$discount = new Discount();
$discount->shopId = $shopId;
$discount->shopId = $data['shopId'];
$discount->category = $data['category'];
$discount->originalPrice = $data['originalPrice'];
$discount->currentPrice = $data['currentPrice'];
Expand All @@ -65,18 +51,26 @@ public function post(Request $request){

$discount->save();
$discount->push();
return $discount;

$fcm = new FCMController();
$fcm->sentToMultiple(
User::pluck('deviceToken')->toArray(),
'Υπάρχουν νέες προσφορές',
'Δείτε τώρα τις νέες προσφορές',
[],//data
'postedNewDiscount'
);

return $discount;
}


public function put($id, Request $request){

public function put($id, Request $request)
{
$request['id'] = $id;

$data = $this->validate($request, [

'shopId' => 'required|numeric',
'id' => 'required|numeric',
'category' => 'required|numeric',
'originalPrice' => 'required|numeric',
Expand All @@ -85,15 +79,8 @@ public function put($id, Request $request){
'image' => 'required|string'
]);





$userId = Auth::user()->id;
$shopId = Shop::query()->where('ownerId','=',$userId)->value('id');

$discount = Discount::query()->where('shopId','=',$shopId)
->where('id', '=', $data['id'])->first();
$discount = Discount::query()->where('shopId', '=', $data['shopId'])
->where('id', '=', $data['id'])->first();

if ($discount != null) {
$discount->category = $data['category'];
Expand All @@ -102,33 +89,24 @@ public function put($id, Request $request){
$discount->description = $data['description'];
$discount->image = $data['image'];


$discount->save();
$discount->push();
return $discount;
}

else {

} else {
return "";
}
}


public function delete($id)
public function delete($id, Request $request)
{
$request = new Request();
$request['id'] = $id;

$data = $this->validate($request, [
'shopId' => 'required|numeric',
'id' => 'required|numeric'
]);

$userId = Auth::user()->id;
$shopId = Shop::query()->where('ownerId','=',$userId)->value('id');

$discount = Discount::query()->where('shopId','=',$shopId)
->find($data['id']);
$discount = Discount::query()->where('shopId', '=', $data['shopId'])->find($data['id']);

if ($discount != null) {
$discount->delete();
Expand Down
66 changes: 66 additions & 0 deletions app/Http/Controllers/FCMController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace App\Http\Controllers;


use LaravelFCM\Facades\FCM;
use LaravelFCM\Message\OptionsBuilder;
use LaravelFCM\Message\PayloadDataBuilder;
use LaravelFCM\Message\PayloadNotificationBuilder;

class FCMController extends Controller
{
public function sentToOne($userToken, $Title, $Body, $Data, $ClickAction)
{
$optionBuilder = new OptionsBuilder();
$optionBuilder->setTimeToLive(60 * 20);

$notificationBuilder = new PayloadNotificationBuilder($Title);
$notificationBuilder->setBody($Body)->setSound('default')->setClickAction($ClickAction);

$dataBuilder = new PayloadDataBuilder();
$dataBuilder->addData($Data);

$option = $optionBuilder->build();
$notification = $notificationBuilder->build();
$data = $dataBuilder->build();

$downstreamResponse = FCM::sendTo($userToken, $option, $notification, $data);

//return Array - you must remove all this tokens in your database
$downstreamResponse->tokensToDelete();

//return Array (key : oldToken, value : new token - you must change the token in your database )
$downstreamResponse->tokensToModify();

//return Array - you should try to resend the message to the tokens in the array
$downstreamResponse->tokensToRetry();
}

public function sentToMultiple($userTokens, $Title, $Body, $Data, $ClickAction)
{
$optionBuilder = new OptionsBuilder();
$optionBuilder->setTimeToLive(60 * 20);

$notificationBuilder = new PayloadNotificationBuilder($Title);
$notificationBuilder->setBody($Body)->setSound('default')->setClickAction($ClickAction);

$dataBuilder = new PayloadDataBuilder();
$dataBuilder->addData($Data);

$option = $optionBuilder->build();
$notification = $notificationBuilder->build();
$data = $dataBuilder->build();

$downstreamResponse = FCM::sendTo($userTokens, $option, $notification, $data);

//return Array - you must remove all this tokens in your database
$downstreamResponse->tokensToDelete();

//return Array (key : oldToken, value : new token - you must change the token in your database )
$downstreamResponse->tokensToModify();

//return Array - you should try to resend the message to the tokens in the array
$downstreamResponse->tokensToRetry();
}
}
Loading

0 comments on commit 0385c67

Please sign in to comment.