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

Commit

Permalink
Merge pull request #65 from flying-coders/thread-answer-1
Browse files Browse the repository at this point in the history
Thread answer 1
  • Loading branch information
kaboel committed Apr 21, 2019
2 parents 532256d + 5a4e840 commit bd524b4
Show file tree
Hide file tree
Showing 20 changed files with 624 additions and 441 deletions.
4 changes: 4 additions & 0 deletions app/Doctor.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public function city() {
return $this->belongsTo('App\City', 'city_id');
}

public function thread() {
return $this->hasMany('App\Thread', 'doctor_id');
}

/**
* @param $str
* @return string
Expand Down
117 changes: 85 additions & 32 deletions app/Http/Controllers/ThreadAnswerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,107 @@

namespace App\Http\Controllers;

use App\Thread;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class ThreadAnswerController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
public function __construct()
{
//
$this->middleware('auth:doctor');
}

/**
* Show the form for creating a new resource.
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
public function index($id)
{
//
$doctor = $this->currentUser();
if($doctor->id != $id) {
return redirect()->back()->with('warning', 'Anda tidak berhak mengakses laman tersebut.');
}

$data = [
'doctor' => $doctor,
'thread' => Thread::where('doctor_id', $doctor->id)->paginate(15)
];
return view('pages.profile-thread')->with('data', $data);
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
* @param Request $request
* @param $id
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
* @throws \Illuminate\Validation\ValidationException
*/
public function store(Request $request)
public function store(Request $request, $id)
{
//
}
$this->validate($request, [
'answer' => 'required|min:150'
]);

/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
$doctor = $this->currentUser();
$thread = Thread::find($id);

$thread->doctor_id = $doctor->id;
$thread->answer = $request->input('answer');
$thread->status = true;

if($thread->save()) {
return redirect(route('doctor.thread.show', $id))->with('success', 'Jawaban terkirim !');
}
return redirect()->back()->with('failed', 'Gagal mengirim jawaban.');
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
* @param $id
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function edit($id)
{
//
$thread = Thread::find($id);
if(!$thread) {
abort(404);
}

$doctor = $this->currentUser();
$data = [
'doctor' => $doctor,
'thread' => $thread
];

return view('pages.ext.edit-thread')->with('data', $data);
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
* @param Request $request
* @param $id
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
* @throws \Illuminate\Validation\ValidationException
*/
public function update(Request $request, $id)
{
//
$this->validate($request, [
'answer' => 'required|min:150'
]);

$thread = Thread::find($id);
$thread->answer = $request->input('answer');
$thread->status = true;

if($thread->save()) {
return redirect(route('doctor.thread.show', $id))->with('success', 'Perubahan jawaban terkirim !');
}
return redirect()->back()->with('failed', 'Gagal mengirim perubahan jawaban.');
}

/**
Expand All @@ -79,6 +113,25 @@ public function update(Request $request, $id)
*/
public function destroy($id)
{
//
$thread = Thread::find($id);
if($thread->doctor_id != $this->currentUser()->id) {
return redirect()->back()->with('warning', 'Anda tidak berhak menghapus jawaban untuk diskusi tersebut.');
}

$thread->doctor_id = null;
$thread->answer = null;
$thread->status = false;
if($thread->save()) {
return redirect()->back()->with('success', 'Jawaban dihapus !');
}
return redirect()->back()->with('failed', 'Gagal mengahapus jawaban.');
}

/**
* @return mixed
*/
private function currentUser()
{
return Auth::guard('doctor')->user();
}
}
15 changes: 11 additions & 4 deletions app/Http/Controllers/ThreadAskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,22 @@ public function destroy($id)
return redirect()->back()->with('failed', 'Gagal menghapus ulasan.');
}


private function currentUser() {
/**
* Get currently logged in user
*
* @return mixed
*/
private function currentUser()
{
return Auth::guard('web')->user();
}

/**
* @param string $topic
* @return ThreadTopic|null
*/
private function addTopic(string $topic) {
private function addTopic(string $topic)
{
$new = new ThreadTopic;
$new->topic_name = $topic;
if($new->save()) {
Expand All @@ -196,7 +202,8 @@ private function addTopic(string $topic) {
* @param int $id
* @return bool
*/
private function deleteTopic($id) {
private function deleteTopic($id)
{
$topic = ThreadTopic::find($id);
if($topic->delete()) {
return true;
Expand Down
107 changes: 64 additions & 43 deletions app/Http/Controllers/ThreadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,55 @@

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Thread;
use App\ThreadTopic;
use Illuminate\Support\Facades\Auth;

class ThreadController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
public function __construct()
{
// abort(503);
return view('pages.thread');
$this->middleware('auth:admin', ['except' => [
'index', 'show'
]]);
}

/**
* Show the form for creating a new resource.
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
* @param $query
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function create()
public function index($query)
{
//
}
$threads = null;
$count = null;
if($query == "all") {
$threads = Thread::orderBy('created_at', 'desc')->paginate(15);
} elseif($query == "answered") {
$threads = Thread::where('status', true)
->orderBy('created_at', 'desc')
->paginate(15);
} else {
$threads = Thread::where('status', false)
->orderBy('created_at', 'desc')
->paginate(15);
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
$data = [
'threads' => $threads,
'query' => $query,
'count' => [
'all' => count(Thread::all()),
'answered' => count(Thread::where('status', true)->get()),
'unanswered' => count(Thread::where('status', false)->get())
]
];

return view('pages.thread')->with('data', $data);
}


/**
* Display the specified resource.
*
Expand All @@ -46,40 +59,48 @@ public function store(Request $request)
*/
public function show($id)
{
//
}
$thread = Thread::find($id);
if(!$thread) {
abort(404);
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
$doctor = Auth::guard('doctor')->user();
$data = [
'thread' => $thread,
'doctor' => $doctor
];
return view('pages.ext.view-thread')->with('data', $data);
}


/**
* Update the specified resource in storage.
* Remove the specified resource from storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
public function destroy($id)
{
//
$thread = Thread::find($id);
if($thread->delete() && $this->deleteTopic($thread->id_topic)) {
return redirect(route('admin.thread.index', ['query' => "all"]))->with('success', 'Diskusi dihapus !');
}
return redirect()->back()->with('failed', 'Gagal menghapus diskusi.');
}


/**
* Remove the specified resource from storage.
* Delete topic with given id
*
* @param int $id
* @return \Illuminate\Http\Response
* @param $id
* @return bool
*/
public function destroy($id)
public function deleteTopic($id)
{
//
$topic = ThreadTopic::find($id);
if($topic->delete()) {
return true;
}
return false;
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,5 @@ Great, now you can try and login as admin by going to `localhost:8000/admin/logi

SIFIKS is open-source project licensed under the [MIT license](https://opensource.org/licenses/MIT).

## Domain
## Live Action
Please visit : https://sifiks.kodeskillet.com/.
2 changes: 1 addition & 1 deletion resources/views/ask-form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<button type="submit" class="btn btn-success btn-sm">
<strong>Kirim</strong>
</button>
<button type="reset" class="btn btn-danger btn-sm" onClick="CKEDITOR.instances.question.setData( '', function() { this.updateElement(); } )">
<button type="reset" class="btn btn-danger btn-sm" onclick="CKEDITOR.instances.question.setData( '', function() { this.updateElement(); } )">
<strong>Reset</strong>
</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/ask-view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
@include('layouts.inc.recent-thread')
</div>
<div class="col col-md-4">
<a href="{{ route('user.thread.create') }}"><img src="https://i.ibb.co/tCWCnKK/doctor.png" alt="doctor" border="0"width="350"></a>
<a href="{{ route('user.thread.create') }}"><img src="https://i.ibb.co/tCWCnKK/doctor.png" alt="doctor" width="350"></a>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit bd524b4

Please sign in to comment.