Skip to content

Commit d44a285

Browse files
author
Renato Marinho
committed
Add NoteService
1 parent 693cb6b commit d44a285

File tree

3 files changed

+50
-14
lines changed

3 files changed

+50
-14
lines changed

app/Http/Controllers/Web/NoteController.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,26 @@ class NoteController extends Controller
1818
{
1919
public function store(NoteRequest $request)
2020
{
21-
$data = [
22-
'noteable_id' => $request->noteable_id,
23-
'noteable_type' => $request->noteable_type,
24-
'title' => $request->title,
25-
];
26-
27-
Note::create($data);
21+
resolve('NoteService')->create($request);
2822

2923
return back()->with('success', trans('gitscrum.added-successfully'));
3024
}
3125

3226
public function update(Request $request, $slug)
3327
{
34-
$note = Note::slug($slug)->first();
35-
36-
$note->closed_user_id = Auth::id();
37-
$note->closed_at = Carbon::now();
38-
$note->save();
28+
$request->request->add([
29+
'slug' => $slug
30+
]);
31+
32+
resolve('NoteService')->update($request);
3933

4034
return back()->with('success', trans('gitscrum.updated-successfully'));
4135
}
4236

4337
public function destroy($id)
4438
{
4539
$note = Note::find($id);
46-
//->where('user_id', Auth::user()->id)->firstOrFail();
40+
//->where('user_id', Auth::user()->id)->firstOrFail();
4741
$note->delete();
4842

4943
return back()->with('success', trans('gitscrum.deleted-successfully'));

app/Services/NoteService.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Laravel GitScrum <https://github.com/GitScrum-Community/laravel-gitscrum>
4+
*
5+
* The MIT License (MIT)
6+
* Copyright (c) 2017 Renato Marinho <renato.marinho@s2move.com>
7+
*/
8+
9+
namespace GitScrum\Services;
10+
11+
use Auth;
12+
use Illuminate\Http\Request;
13+
use Carbon\Carbon;
14+
use GitScrum\Http\Requests\NoteRequest;
15+
use GitScrum\Models\Note;
16+
17+
class NoteService extends Service
18+
{
19+
public function create(NoteRequest $request)
20+
{
21+
$data = [
22+
'noteable_id' => $request->noteable_id,
23+
'noteable_type' => $request->noteable_type,
24+
'title' => $request->title,
25+
];
26+
27+
$note = Note::create($data);
28+
29+
return $note;
30+
}
31+
32+
public function update(Request $request)
33+
{
34+
$note = Note::slug($request->slug)->first();
35+
36+
$note->closed_user_id = Auth::id();
37+
$note->closed_at = Carbon::now();
38+
39+
return $note->save();
40+
}
41+
}

config/app.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@
142142
'ConfigStatusService',
143143
'FavoriteService',
144144
'IssueService',
145-
'LabelService'
145+
'LabelService',
146+
'NoteService'
146147
],
147148

148149
/*

0 commit comments

Comments
 (0)