'update_backend_part'

parent 353f5595
APP_NAME=Lumen
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
APP_TIMEZONE=UTC
LOG_CHANNEL=stack
LOG_SLACK_WEBHOOK_URL=
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Activities;
use App\Models\Feedback;
use App\Models\ResultSummary;
use DB;
use Log;
class ActivitiesController extends Controller {
public function getActivities($id) {
try {
$activities = Feedback::Where('parent_id',$id)->get();
return response()->json([ 'activities' => $activities], 200);
} catch ( \Exception $e ) {
Log::error( $e );
return response()->json( ['message' => $e->getmessage()], 500 );
}
}
public function getMarks($id) {
try {
$summary = ResultSummary::Where('student_id',$id)->get();
return response()->json([ 'summary' => $summary], 200);
} catch ( \Exception $e ) {
Log::error( $e );
return response()->json( ['message' => $e->getmessage()], 500 );
}
}
public function create( Request $request ) {
try {
DB::beginTransaction();
$activities = new Feedback();
$activities->name = $request->name;
$activities->parent_id = $request->parent_id;
$activities->feedback = $request->feedback;
$activities->subject = $request->subject;
$activities->date = $request->date;
$activities->time = $request->time;
$activities->save();
DB::commit();
return response()->json([ 'activities' => $activities, 'message' => 'saved' ], 200 );
} catch (\Exception $e) {
DB::rollBack();
Log::error($e);
return response()->json([ 'message' => $e->getmessage() ], 500);
}
}
}
<?php
namespace App\Http\Controllers;
use App\Models\Parents;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class CommonController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
//
}
public function login(Request $request) {
$user = Parents::Where('email',$request->email)
->Where('password',$request->password)->first();
return response()->json( ['user'=> $user],200 );
}
}
...@@ -4,6 +4,7 @@ namespace App\Http\Controllers; ...@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\Conversations; use App\Models\Conversations;
use App\Models\Parents;
use App\Models\ConversationGroups; use App\Models\ConversationGroups;
use DB; use DB;
use Log; use Log;
...@@ -40,4 +41,52 @@ class ConversationsController extends Controller { ...@@ -40,4 +41,52 @@ class ConversationsController extends Controller {
return response()->json([ 'message' => $e->getmessage(), 'status'=>500 ], 500); return response()->json([ 'message' => $e->getmessage(), 'status'=>500 ], 500);
} }
} }
public function getChatById( $id ) {
try {
$conversations = Conversations::with('sender')->Where( 'conversation_group_id', $id )->get();
return response()->json([ 'conversations' => $conversations], 200);
} catch ( \Exception $e ) {
Log::error( $e );
return response()->json( ['message' => $e->getmessage()], 500 );
}
}
public function feedbacks( $id ) {
try {
$conversations = DB::table('conversations')
->select(DB::raw('count(id) as count, sentimental as type'))
->groupBy('sentimental')
->Where('conversation_group_id',$id)
->get();
return response()->json([ 'results' => $conversations], 200);
} catch ( \Exception $e ) {
Log::error( $e );
return response()->json( ['message' => $e->getmessage()], 500 );
}
}
public function item_create( Request $request ) {
try {
DB::beginTransaction();
$item = new Item();
$item->name = $request->name;
$item->type = $request->type;
$item->qty = $request->qty;
$item->save();
DB::commit();
// return response()->json([ 'conversations' => $conversations, 'message' => 'saved', 'status'=>200 ], 200 );
} catch (\Exception $e) {
DB::rollBack();
Log::error($e);
// return response()->json([ 'message' => $e->getmessage(), 'status'=>500 ], 500);
}
}
} }
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\QuizRecord;
use App\Models\Students;
use App\Models\User;
use DB;
use Log;
class QuizRecordController extends Controller {
public function quiz_records(Request $request) {
try {
$quiz_records = QuizRecord::where('date',$request->date)->get();
return response()->json([ 'quiz_records' => $quiz_records], 200);
} catch ( \Exception $e ) {
Log::error( $e );
return response()->json( ['message' => $e->getmessage()], 500 );
}
}
public function get_user_info( $id ) {
try {
$user = Students::where('student_id', $id)->first();
return response()->json([ 'user' => $user], 200);
} catch ( \Exception $e ) {
Log::error( $e );
return response()->json( ['message' => $e->getmessage()], 500 );
}
}
public function get_avg_time() {
try {
$QuizRecord = QuizRecord::get();
$QuizRecordCount = QuizRecord::count();
$duration = 0;
$avg_time = 0;
foreach ($QuizRecord as $item) {
$duration += $item->duration;
}
$avg_time = $duration/$QuizRecordCount;
response()->json( $avg_time );
// return response()->json([ 'avg_time' => $avg_time], 200);
} catch ( \Exception $e ) {
Log::error( $e );
return response()->json( ['message' => $e->getmessage()], 500 );
}
//return response()->json( $players_count );
}
}
...@@ -9,51 +9,18 @@ use Log; ...@@ -9,51 +9,18 @@ use Log;
class StudyMeterialsController extends Controller { class StudyMeterialsController extends Controller {
public function store( Request $request ) { public function lessons($type) {
try { try {
DB::beginTransaction(); if ($type == 0) {
$lessons = StudyMeterials::where('subject','Mathematics')->get();
// $request->validate([ }else{
$lessons = StudyMeterials::where('subject','Science')->get();
// 'image' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048',
// ]);
$doc_name = null;
if( $request->doc_url ) {
$doc_name = time().'.'.$request->doc_url->extension();
$request->doc_url->move(public_path('study_docs'), $doc_name);
} }
return response()->json([ 'lessons' => $lessons], 200);
$StudyMeterials = new StudyMeterials(); } catch ( \Exception $e ) {
$StudyMeterials->name = $request->name; Log::error( $e );
$StudyMeterials->doc_url = $doc_name; return response()->json([ 'message' => $e->getmessage()], 500 );
$StudyMeterials->save();
DB::commit();
return response()->json([ 'object' => $StudyMeterials, 'message' => 'created','status'=>201 ], 200);
} catch (\Exception $e) {
DB::rollBack();
Log::error($e);
return response()->json( ['message' => $e->getmessage(), 'status'=>500 ], 500 );
} }
} }
public function get_meterials() {
$meterials = [
0 => [
'subject' => 'English',
'url' => 'http://www.africau.edu/images/default/sample.pdf'
],
1 => [
'subject' => 'ICT',
'url' => 'http://www.africau.edu/images/default/sample.pdf'
],
];
return response()->json( $meterials );
}
} }
<?php
namespace App\Http\Middleware;
use Closure;
class CorsMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
header("Access-Control-Allow-Origin: *");
//ALLOW OPTIONS METHOD
$headers = [
'Access-Control-Allow-Methods' => 'POST,GET,OPTIONS,PUT,DELETE',
'Access-Control-Allow-Headers' => 'Content-Type, X-Auth-Token, Origin, Authorization',
];
if ($request->getMethod() == "OPTIONS"){
//The client-side application can set only headers allowed in Access-Control-Allow-Headers
return response()->json('OK',200,$headers);
}
$response = $next($request);
foreach ($headers as $key => $value) {
$response->header($key, $value);
}
return $response;
}
}
\ No newline at end of file
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Activities extends Model {
protected $table = 'activities';
protected $fillable = [
'user_id',
'content',
'date_time',
];
public $timestamps = false;
}
...@@ -13,6 +13,12 @@ class Conversations extends Model { ...@@ -13,6 +13,12 @@ class Conversations extends Model {
'receiver_id', 'receiver_id',
'message', 'message',
'is_read', 'is_read',
'sentimental',
]; ];
public $timestamps = true; public $timestamps = true;
public function sender()
{
return $this->belongsTo('App\Models\Parents', 'sender_id', 'parent_id');
}
} }
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Feedback extends Model {
protected $table = 'feedback';
protected $fillable = [
'name',
'parent_id',
'subject',
'feedback',
'date',
'time'
];
public $timestamps = false;
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Parents extends Model {
protected $table = 'tbl_parent';
protected $fillable = [
'parent_id',
'student_id',
'first_name',
'last_name',
'email',
'username',
'contact',
'address',
'gender'
];
public $timestamps = false;
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class QuizRecord extends Model {
protected $table = 'quizrecord';
protected $fillable = [
'recid',
'rollnum',
'duration',
'endtime',
'date',
'url',
'type'
];
public $timestamps = false;
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ResultSummary extends Model {
protected $table = 'tbl_result_summary';
protected $fillable = [
'summary_id',
'student_id',
'marks',
'activity_id',
'grade',
'subject',
];
public $timestamps = false;
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Students extends Model {
protected $table = 'tbl_student';
protected $fillable = [
'student_id',
'first_name',
'last_name',
'email',
'username',
'password',
'contact',
'grade',
'is_active',
'added_date',
'updated_date',
];
public $timestamps = false;
}
...@@ -6,11 +6,11 @@ use Illuminate\Database\Eloquent\Model; ...@@ -6,11 +6,11 @@ use Illuminate\Database\Eloquent\Model;
class StudyMeterials extends Model { class StudyMeterials extends Model {
protected $table = 'study_meterials'; protected $table = 'lessons';
protected $fillable = [ protected $fillable = [
'name', 'subject',
'doc_url', 'topic',
'category' 'content'
]; ];
public $timestamps = false; public $timestamps = false;
} }
...@@ -73,7 +73,7 @@ $app->configure('app'); ...@@ -73,7 +73,7 @@ $app->configure('app');
*/ */
$app->middleware([ $app->middleware([
App\Http\Middleware\CorsPolicy::class, App\Http\Middleware\CorsMiddleware::class,
App\Http\Middleware\HttpsProtocol::class App\Http\Middleware\HttpsProtocol::class
]); ]);
......
...@@ -18,23 +18,25 @@ $router->get('/', function () use ($router) { ...@@ -18,23 +18,25 @@ $router->get('/', function () use ($router) {
}); });
$router->group(['prefix' => 'api'], function () use ($router) { $router->group(['prefix' => 'api'], function () use ($router) {
$router->post('login', 'CommonController@login');
// Chat // Chat
$router->group(['prefix' => 'chat'], function () use ($router) { $router->group(['prefix' => 'chat'], function () use ($router) {
$router->post('create', 'ConversationsController@create'); $router->post('create', 'ConversationsController@create');
$router->get('get/{id}', 'ConversationsController@getChatById');
}); });
$router->group(['prefix' => 'video'], function () use ($router) { $router->group(['prefix' => 'activities'], function () use ($router) {
$router->get('get', 'VideoController@get_video'); $router->post('create', 'ActivitiesController@create');
}); $router->get('get/{id}', 'ActivitiesController@getActivities');
$router->group(['prefix' => 'study-meterials'], function () use ($router) {
$router->post('upload', 'StudyMeterialsController@store');
$router->get('get', 'StudyMeterialsController@get_meterials');
}); });
$router->get('lessons/{type}', 'StudyMeterialsController@lessons');
$router->post('quiz-records', 'QuizRecordController@quiz_records');
$router->get('user-info/{id}', 'QuizRecordController@get_user_info');
$router->get('feedbacks/{id}', 'ConversationsController@feedbacks');
$router->get('get-avg-time', 'QuizRecordController@get_avg_time');
$router->get('/students/getmarks/{id}', 'ActivitiesController@getMarks');
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment