Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Conversations #1629

Merged
merged 72 commits into from
Aug 31, 2018
Merged
Show file tree
Hide file tree
Changes from 63 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
c13c3e8
wip
djaiss Jul 27, 2018
806307e
wip
djaiss Jul 27, 2018
79972b1
Apply fixes from StyleCI
djaiss Jul 29, 2018
efb634f
wip
djaiss Aug 1, 2018
0cc1952
Merge branch '2018-07-26-feat-conversations' of github.com:monicahq/m…
djaiss Aug 1, 2018
4027750
Apply fixes from StyleCI
djaiss Aug 1, 2018
6def1b5
wip
djaiss Aug 1, 2018
2068757
Apply fixes from StyleCI
djaiss Aug 1, 2018
99c7f38
wip
djaiss Aug 2, 2018
36080dd
wip
djaiss Aug 2, 2018
d562348
wip
djaiss Aug 2, 2018
8a12498
Apply fixes from StyleCI
djaiss Aug 2, 2018
808aa1c
Merge branch 'master' into 2018-07-26-feat-conversations
djaiss Aug 2, 2018
92324d8
wip
djaiss Aug 2, 2018
aff9608
more tests
djaiss Aug 3, 2018
a115b6f
woip
djaiss Aug 5, 2018
bdc9b86
wip
djaiss Aug 5, 2018
5c3ecb7
Apply fixes from StyleCI
djaiss Aug 5, 2018
56032ba
add missing methods
djaiss Aug 6, 2018
62b0824
add seeding data
djaiss Aug 6, 2018
5999751
Apply fixes from StyleCI
djaiss Aug 7, 2018
5e2bef6
Merge branch 'master' into 2018-07-26-feat-conversations
djaiss Aug 16, 2018
8043083
wip
djaiss Aug 16, 2018
2c9fa76
merge master
djaiss Aug 19, 2018
7a75549
wip
djaiss Aug 19, 2018
121e4ab
Apply fixes from StyleCI
djaiss Aug 19, 2018
a9e1548
add tests for deletion
djaiss Aug 19, 2018
ddb38f1
wip
djaiss Aug 19, 2018
628fb0b
Merge branch '2018-07-26-feat-conversations' of github.com:monicahq/m…
djaiss Aug 19, 2018
b732a5d
wip
djaiss Aug 20, 2018
9cdfd4e
Apply fixes from StyleCI
djaiss Aug 20, 2018
b7cc745
chore(assets): Update assets
MonicaBot Aug 20, 2018
f3449d5
wip
djaiss Aug 21, 2018
e3f14db
Merge branch '2018-07-26-feat-conversations' of github.com:monicahq/m…
djaiss Aug 21, 2018
ee337d5
chore(assets): Update assets
MonicaBot Aug 21, 2018
eb4e436
wip
djaiss Aug 22, 2018
e083fa6
chore(assets): Update assets
MonicaBot Aug 22, 2018
5d480a9
wip
djaiss Aug 22, 2018
46b4ac5
Merge branch '2018-07-26-feat-conversations' of github.com:monicahq/m…
djaiss Aug 23, 2018
dc5574e
Apply fixes from StyleCI
djaiss Aug 23, 2018
d916420
chore(assets): Update assets
MonicaBot Aug 23, 2018
bc31405
wip
djaiss Aug 23, 2018
e9f43bb
chore(assets): Update assets
MonicaBot Aug 23, 2018
65fec3c
wip
djaiss Aug 24, 2018
d6e941e
wip
djaiss Aug 24, 2018
3f76f95
chore(assets): Update assets
MonicaBot Aug 24, 2018
fd68f31
add good table
djaiss Aug 24, 2018
31159e7
chore(assets): Update assets
MonicaBot Aug 24, 2018
84a06e6
wip
djaiss Aug 25, 2018
fba4d29
chore(assets): Update assets
MonicaBot Aug 25, 2018
21c9738
wip
djaiss Aug 26, 2018
b13ba1b
wip
djaiss Aug 26, 2018
1c8172c
wip
djaiss Aug 28, 2018
de3be9c
wip
djaiss Aug 28, 2018
08d6106
Merge branch 'master' into 2018-07-26-feat-conversations
djaiss Aug 28, 2018
d2b10ef
Apply fixes from StyleCI
djaiss Aug 28, 2018
260838a
chore(assets): Update assets
MonicaBot Aug 28, 2018
5537686
Edition now complete
djaiss Aug 29, 2018
f0ab2ef
finish edit and delete feature
djaiss Aug 29, 2018
fa0fa31
chore(assets): Update assets
MonicaBot Aug 29, 2018
cb1fd88
fix failing tests
djaiss Aug 29, 2018
c671ce7
Merge branch '2018-07-26-feat-conversations' of github.com:monicahq/m…
djaiss Aug 29, 2018
71b80f9
fix psalm and a few Sonar errors
djaiss Aug 29, 2018
19ba1b2
add calculate statistics
djaiss Aug 29, 2018
f418768
Apply fixes from StyleCI
djaiss Aug 29, 2018
8481a61
add cypress tests
djaiss Aug 30, 2018
9a2b934
fix seeder
djaiss Aug 30, 2018
999cd07
Apply fixes from StyleCI
djaiss Aug 30, 2018
67390da
chore(assets): Update assets
MonicaBot Aug 30, 2018
81d96fc
Finalize all tasks
djaiss Aug 30, 2018
be56df9
changelog entry
djaiss Aug 30, 2018
fc640a9
Merge branch 'master' into 2018-07-26-feat-conversations
djaiss Aug 31, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
- [ ] Read the [CONTRIBUTING document](https://github.com/monicahq/monica/blob/master/CONTRIBUTING.md) before submitting your PR.
- [ ] If the PR is related to an issue or fix one, don't forget to indicate it.
- [ ] Make sure that the change you propose is the smallest possible.
- [ ] If you change the UI, make sure to ask repositories administrators first about your changes.
- [ ] Screenshots are included if the PR changes the UI.
- [ ] If you change the UI, make sure the user experience is consistent with the current interface.

#### Code-related tasks
- [ ] Tests added for this feature/bug.
- [ ] Impact on the seeders.
- [ ] Impact on the API.
- [ ] If API is impacted, maintain the API's documentation.

#### If the code changes the SQL schema
- [ ] Impact on account export.
Expand Down
139 changes: 139 additions & 0 deletions app/Http/Controllers/Api/Contact/ApiConversationController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<?php

namespace App\Http\Controllers\Api\Contact;

use Illuminate\Http\Request;
use App\Models\Contact\Conversation;
use Illuminate\Database\QueryException;
use App\Http\Controllers\Api\ApiController;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use App\Services\Contact\Conversation\CreateConversation;
use App\Services\Contact\Conversation\UpdateConversation;
use App\Services\Contact\Conversation\DestroyConversation;
use App\Http\Resources\Conversation\Conversation as ConversationResource;

class ApiConversationController extends ApiController
{
/**
* Get the list of conversations.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
try {
$conversations = auth()->user()->account->conversations()
->orderBy($this->sort, $this->sortDirection)
->paginate($this->getLimitPerPage());
} catch (QueryException $e) {
return $this->respondInvalidQuery();
}

return ConversationResource::collection($conversations);
}

/**
* Get the detail of a given conversation.
*
* @param Request $request
* @return \Illuminate\Http\Response
*/
public function show(Request $request, $conversationId)
{
try {
$conversation = Conversation::where('account_id', auth()->user()->account_id)
->findOrFail($conversationId);
} catch (ModelNotFoundException $e) {
return $this->respondNotFound();
}

return new ConversationResource($conversation);
}

/**
* Store the conversation.
*
* @param Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
try {
$conversation = (new CreateConversation)->execute(
$request->all()
+
[
'account_id' => auth()->user()->account->id,
]
);
} catch (ModelNotFoundException $e) {
return $this->respondNotFound();
} catch (\Exception $e) {
return $this->setHTTPStatusCode(500)
->setErrorCode(41)
->respondWithError(config('api.error_codes.41'));
} catch (QueryException $e) {
return $this->respondInvalidQuery();
}

return new ConversationResource($conversation);
}

/**
* Update the conversation.
*
* @param Request $request
* @param int $conversationId
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $conversationId)
{
try {
$conversation = (new UpdateConversation)->execute(
$request->all()
+
[
'account_id' => auth()->user()->account->id,
'conversation_id' => $conversationId,
]
);
} catch (ModelNotFoundException $e) {
return $this->respondNotFound();
} catch (\Exception $e) {
return $this->setHTTPStatusCode(500)
->setErrorCode(41)
->respondWithError(config('api.error_codes.41'));
} catch (QueryException $e) {
return $this->respondInvalidQuery();
}

return new ConversationResource($conversation);
}

/**
* Destroy the conversation.
*
* @param Request $request
* @param int $conversationId
* @return \Illuminate\Http\Response
*/
public function destroy(Request $request, $conversationId)
{
try {
$conversation = (new DestroyConversation)->execute([
'account_id' => auth()->user()->account->id,
'conversation_id' => $conversationId,
]);
} catch (ModelNotFoundException $e) {
return $this->respondNotFound();
} catch (\Exception $e) {
return $this->setHTTPStatusCode(500)
->setErrorCode(41)
->respondWithError(config('api.error_codes.41'));
} catch (QueryException $e) {
return $this->respondInvalidQuery();
}

return $this->respondObjectDeleted((int) $conversationId);
}
}
131 changes: 131 additions & 0 deletions app/Http/Controllers/Api/Contact/ApiMessageController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php

namespace App\Http\Controllers\Api\Contact;

use Illuminate\Http\Request;
use App\Models\Contact\Message;
use App\Models\Contact\Conversation;
use Illuminate\Database\QueryException;
use App\Http\Controllers\Api\ApiController;
use App\Services\Contact\Conversation\UpdateMessage;
use App\Services\Contact\Conversation\DestroyMessage;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use App\Services\Contact\Conversation\AddMessageToConversation;
use App\Http\Resources\Conversation\Conversation as ConversationResource;

class ApiMessageController extends ApiController
{
/**
* Store the message.
*
* @param Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request, int $conversationId)
{
try {
$conversation = Conversation::findOrFail($conversationId);
} catch (ModelNotFoundException $e) {
return $this->respondNotFound();
}

try {
(new AddMessageToConversation)->execute(
$request->all()
+
[
'account_id' => auth()->user()->account->id,
'conversation_id' => $conversation->id,
'contact_id' => $conversation->contact->id,
]
);
} catch (ModelNotFoundException $e) {
return $this->respondNotFound();
} catch (\Exception $e) {
return $this->setHTTPStatusCode(500)
->setErrorCode(41)
->respondWithError(config('api.error_codes.41'));
} catch (QueryException $e) {
return $this->respondInvalidQuery();
}

return new ConversationResource($conversation);
}

/**
* Update the message.
*
* @param Request $request
* @param int $conversationId
* @param int $messageId
* @return \Illuminate\Http\Response
*/
public function update(Request $request, int $conversationId, int $messageId)
{
try {
$conversation = Conversation::findOrFail($conversationId);
$message = Message::findOrFail($messageId);
} catch (ModelNotFoundException $e) {
return $this->respondNotFound();
}

try {
(new UpdateMessage)->execute(
$request->all()
+
[
'account_id' => auth()->user()->account->id,
'conversation_id' => $conversationId,
'message_id' => $messageId,
'contact_id' => $conversation->contact->id,
]
);
} catch (ModelNotFoundException $e) {
return $this->respondNotFound();
} catch (\Exception $e) {
return $this->setHTTPStatusCode(500)
->setErrorCode(41)
->respondWithError(config('api.error_codes.41'));
} catch (QueryException $e) {
return $this->respondInvalidQuery();
}

return new ConversationResource($conversation);
}

/**
* Destroy the message.
*
* @param Request $request
* @param int $conversationId
* @param int $messageId
* @return \Illuminate\Http\Response
*/
public function destroy(Request $request, int $conversationId, int $messageId)
{
try {
Conversation::findOrFail($conversationId);
Message::findOrFail($messageId);
} catch (ModelNotFoundException $e) {
return $this->respondNotFound();
}

try {
(new DestroyMessage)->execute([
'account_id' => auth()->user()->account->id,
'conversation_id' => $conversationId,
'message_id' => $messageId,
]);
} catch (ModelNotFoundException $e) {
return $this->respondNotFound();
} catch (\Exception $e) {
return $this->setHTTPStatusCode(500)
->setErrorCode(41)
->respondWithError(config('api.error_codes.41'));
} catch (QueryException $e) {
return $this->respondInvalidQuery();
}

return $this->respondObjectDeleted((int) $messageId);
}
}
Loading