Skip to content

Commit 7c2801d

Browse files
authored
Merge pull request #94 from HiEventsDev/develop
main <- develop
2 parents 685ef32 + 9d78493 commit 7c2801d

File tree

43 files changed

+923
-492
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+923
-492
lines changed

backend/app/DomainObjects/Generated/QuestionDomainObjectAbstract.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ abstract class QuestionDomainObjectAbstract extends \HiEvents\DomainObjects\Abst
2222
final public const DELETED_AT = 'deleted_at';
2323
final public const ORDER = 'order';
2424
final public const IS_HIDDEN = 'is_hidden';
25+
final public const DESCRIPTION = 'description';
2526

2627
protected int $id;
2728
protected int $event_id;
@@ -35,6 +36,7 @@ abstract class QuestionDomainObjectAbstract extends \HiEvents\DomainObjects\Abst
3536
protected ?string $deleted_at = null;
3637
protected int $order = 1;
3738
protected bool $is_hidden = false;
39+
protected ?string $description = null;
3840

3941
public function toArray(): array
4042
{
@@ -51,6 +53,7 @@ public function toArray(): array
5153
'deleted_at' => $this->deleted_at ?? null,
5254
'order' => $this->order ?? null,
5355
'is_hidden' => $this->is_hidden ?? null,
56+
'description' => $this->description ?? null,
5457
];
5558
}
5659

@@ -185,4 +188,15 @@ public function getIsHidden(): bool
185188
{
186189
return $this->is_hidden;
187190
}
191+
192+
public function setDescription(?string $description): self
193+
{
194+
$this->description = $description;
195+
return $this;
196+
}
197+
198+
public function getDescription(): ?string
199+
{
200+
return $this->description;
201+
}
188202
}

backend/app/DomainObjects/QuestionAndAnswerViewDomainObject.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace HiEvents\DomainObjects;
44

5-
use HiEvents\DomainObjects\Enums\QuestionTypeEnum;
6-
75
/**
86
* As this is related to a view, and not a table, this was not auto-generated.
97
*/

backend/app/Http/Actions/Questions/CreateQuestionAction.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ public function __invoke(UpsertQuestionRequest $request, int $eventId): JsonResp
3333
'ticket_ids' => $request->input('ticket_ids'),
3434
'belongs_to' => $request->input('belongs_to'),
3535
'is_hidden' => $request->boolean('is_hidden'),
36+
'description' => $request->input('description'),
3637
]));
3738

38-
return $this->resourceResponse(QuestionResource::class, $question, ResponseCodes::HTTP_CREATED);
39+
return $this->resourceResponse(
40+
resource: QuestionResource::class,
41+
data: $question,
42+
statusCode: ResponseCodes::HTTP_CREATED
43+
);
3944
}
4045
}

backend/app/Http/Actions/Questions/EditQuestionAction.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use HiEvents\Services\Handlers\Question\DTO\UpsertQuestionDTO;
1212
use HiEvents\Services\Handlers\Question\EditQuestionHandler;
1313
use Illuminate\Http\JsonResponse;
14+
use Throwable;
1415

1516
class EditQuestionAction extends BaseAction
1617
{
@@ -21,20 +22,26 @@ public function __construct(EditQuestionHandler $editQuestionHandler)
2122
$this->editQuestionHandler = $editQuestionHandler;
2223
}
2324

25+
/**
26+
* @throws Throwable
27+
*/
2428
public function __invoke(UpsertQuestionRequest $request, int $eventId, int $questionId): JsonResponse
2529
{
2630
$this->isActionAuthorized($eventId, EventDomainObject::class);
2731

28-
$question = $this->editQuestionHandler->handle($questionId, UpsertQuestionDTO::fromArray([
29-
'title' => $request->input('title'),
30-
'type' => QuestionTypeEnum::fromName($request->input('type')),
31-
'required' => $request->boolean('required'),
32-
'options' => $request->input('options'),
33-
'event_id' => $eventId,
34-
'ticket_ids' => $request->input('ticket_ids'),
35-
'is_hidden' => $request->boolean('is_hidden'),
36-
'belongs_to' => QuestionBelongsTo::fromName($request->input('belongs_to')),
37-
]));
32+
$question = $this->editQuestionHandler->handle(
33+
questionId: $questionId,
34+
createQuestionDTO: UpsertQuestionDTO::fromArray([
35+
'title' => $request->input('title'),
36+
'type' => QuestionTypeEnum::fromName($request->input('type')),
37+
'required' => $request->boolean('required'),
38+
'options' => $request->input('options'),
39+
'event_id' => $eventId,
40+
'ticket_ids' => $request->input('ticket_ids'),
41+
'is_hidden' => $request->boolean('is_hidden'),
42+
'belongs_to' => QuestionBelongsTo::fromName($request->input('belongs_to')),
43+
'description' => $request->input('description'),
44+
]));
3845

3946
return $this->resourceResponse(QuestionResource::class, $question);
4047
}

backend/app/Http/Request/Questions/UpsertQuestionRequest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22

33
namespace HiEvents\Http\Request\Questions;
44

5-
use Illuminate\Validation\Rule;
65
use HiEvents\DomainObjects\Enums\QuestionBelongsTo;
76
use HiEvents\DomainObjects\Enums\QuestionTypeEnum;
87
use HiEvents\Http\Request\BaseRequest;
8+
use Illuminate\Validation\Rule;
99

1010
class UpsertQuestionRequest extends BaseRequest
1111
{
1212
public function rules(): array
1313
{
1414
return [
1515
'title' => ['string', 'required'],
16+
'description' => ['string', 'nullable', 'max:10000'],
1617
'type' => ['required', Rule::in(QuestionTypeEnum::valuesArray())],
1718
'ticket_ids' => ['array', 'required_if:belongs_to,TICKET'],
1819
'belongs_to' => [

backend/app/Resources/Question/QuestionAnswerViewResource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace HiEvents\Resources\Question;
44

5-
use Illuminate\Http\Request;
6-
use Illuminate\Http\Resources\Json\JsonResource;
75
use HiEvents\DomainObjects\Enums\QuestionTypeEnum;
86
use HiEvents\DomainObjects\QuestionAndAnswerViewDomainObject;
97
use HiEvents\Services\Domain\Question\QuestionAnswerFormatter;
8+
use Illuminate\Http\Request;
9+
use Illuminate\Http\Resources\Json\JsonResource;
1010

1111
/**
1212
* @mixin QuestionAndAnswerViewDomainObject

backend/app/Resources/Question/QuestionResource.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public function toArray(Request $request): array
1818
'id' => $this->getId(),
1919
'type' => $this->getType(),
2020
'title' => $this->getTitle(),
21+
'description' => $this->getDescription(),
2122
'options' => $this->getOptions(),
2223
'required' => $this->getRequired(),
2324
'event_id' => $this->getEventId(),

backend/app/Resources/Question/QuestionResourcePublic.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
namespace HiEvents\Resources\Question;
44

5-
use Illuminate\Http\Request;
65
use HiEvents\DomainObjects\QuestionDomainObject;
76
use HiEvents\Resources\BaseResource;
8-
use HiEvents\Resources\Ticket\TicketResourcePublic;
7+
use Illuminate\Http\Request;
98

109
/**
1110
* @mixin QuestionDomainObject
@@ -18,6 +17,7 @@ public function toArray(Request $request): array
1817
'id' => $this->getId(),
1918
'type' => $this->getType(),
2019
'title' => $this->getTitle(),
20+
'description' => $this->getDescription(),
2121
'options' => $this->getOptions(),
2222
'required' => $this->getRequired(),
2323
'event_id' => $this->getEventId(),

backend/app/Services/Domain/Question/CreateQuestionService.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
use HiEvents\DomainObjects\Generated\QuestionDomainObjectAbstract;
66
use HiEvents\DomainObjects\QuestionDomainObject;
77
use HiEvents\Repository\Interfaces\QuestionRepositoryInterface;
8+
use HTMLPurifier;
89
use Illuminate\Database\DatabaseManager;
910
use Throwable;
1011

1112
class CreateQuestionService
1213
{
1314
public function __construct(
1415
private readonly QuestionRepositoryInterface $questionRepository,
15-
private readonly DatabaseManager $databaseManager
16+
private readonly DatabaseManager $databaseManager,
17+
private readonly HTMLPurifier $purifier,
1618
)
1719
{
1820
}
@@ -33,6 +35,7 @@ public function createQuestion(
3335
QuestionDomainObjectAbstract::REQUIRED => $question->getRequired(),
3436
QuestionDomainObjectAbstract::OPTIONS => $question->getOptions(),
3537
QuestionDomainObjectAbstract::IS_HIDDEN => $question->getIsHidden(),
38+
QuestionDomainObjectAbstract::DESCRIPTION => $this->purifier->purify($question->getDescription()),
3639
], $ticketIds));
3740
}
3841
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace HiEvents\Services\Domain\Question;
4+
5+
use HiEvents\DomainObjects\Generated\QuestionDomainObjectAbstract;
6+
use HiEvents\DomainObjects\QuestionDomainObject;
7+
use HiEvents\DomainObjects\TicketDomainObject;
8+
use HiEvents\Repository\Interfaces\QuestionRepositoryInterface;
9+
use HTMLPurifier;
10+
use Illuminate\Database\DatabaseManager;
11+
use Throwable;
12+
13+
class EditQuestionService
14+
{
15+
public function __construct(
16+
private readonly QuestionRepositoryInterface $questionRepository,
17+
private readonly DatabaseManager $databaseManager,
18+
private readonly HTMLPurifier $purifier,
19+
)
20+
{
21+
}
22+
23+
/**
24+
* @throws Throwable
25+
*/
26+
public function editQuestion(
27+
QuestionDomainObject $question,
28+
array $ticketIds,
29+
): QuestionDomainObject
30+
{
31+
return $this->databaseManager->transaction(function () use ($question, $ticketIds) {
32+
$this->questionRepository->updateQuestion(
33+
questionId: $question->getId(),
34+
eventId: $question->getEventId(),
35+
attributes: [
36+
QuestionDomainObjectAbstract::TITLE => $question->getTitle(),
37+
QuestionDomainObjectAbstract::EVENT_ID => $question->getEventId(),
38+
QuestionDomainObjectAbstract::BELONGS_TO => $question->getBelongsTo(),
39+
QuestionDomainObjectAbstract::TYPE => $question->getType(),
40+
QuestionDomainObjectAbstract::REQUIRED => $question->getRequired(),
41+
QuestionDomainObjectAbstract::OPTIONS => $question->getOptions(),
42+
QuestionDomainObjectAbstract::IS_HIDDEN => $question->getIsHidden(),
43+
QuestionDomainObjectAbstract::DESCRIPTION => $this->purifier->purify($question->getDescription()),
44+
],
45+
ticketIds: $ticketIds
46+
);
47+
48+
return $this->questionRepository
49+
->loadRelation(TicketDomainObject::class)
50+
->findById($question->getId());
51+
});
52+
}
53+
}

0 commit comments

Comments
 (0)