From 7c6903469fb66fe9625639e9fe6e5226b02dd9d5 Mon Sep 17 00:00:00 2001 From: fyui001 Date: Wed, 1 Apr 2026 10:37:14 +0900 Subject: [PATCH 1/3] Add medication history delete API endpoint Co-Authored-By: Claude Opus 4.6 (1M context) --- .../Actions/DeleteMedicationHistoryAction.php | 66 +++++++++++++++++++ app/Services/MedicationHistoryService.php | 15 +++++ routes/api.php | 2 + 3 files changed, 83 insertions(+) create mode 100644 app/Http/Api/MedicationHistory/Actions/DeleteMedicationHistoryAction.php diff --git a/app/Http/Api/MedicationHistory/Actions/DeleteMedicationHistoryAction.php b/app/Http/Api/MedicationHistory/Actions/DeleteMedicationHistoryAction.php new file mode 100644 index 00000000..354cdcf6 --- /dev/null +++ b/app/Http/Api/MedicationHistory/Actions/DeleteMedicationHistoryAction.php @@ -0,0 +1,66 @@ +medicationHistoryService->delete(new MedicationHistoryId($id)); + + if ($result->isFailed()) { + return new ApiErrorResponder($result->getError()); + } + + return new EmptyResponder(); + } +} diff --git a/app/Services/MedicationHistoryService.php b/app/Services/MedicationHistoryService.php index 4ce96d6b..fbc7454e 100644 --- a/app/Services/MedicationHistoryService.php +++ b/app/Services/MedicationHistoryService.php @@ -109,6 +109,21 @@ public function updateMedicationHistory(MedicationHistory $medicationHistory): M return $this->medicationHistoryDomainService->update($medicationHistory); } + /** + * @param MedicationHistoryId $id + * @return ServiceResult + */ + public function delete(MedicationHistoryId $id): ServiceResult + { + try { + $this->medicationHistoryDomainService->delete($id); + + return ServiceResult::success(null); + } catch (NotFoundException) { + return ServiceResult::fail(ServiceError::NotFound); + } + } + /** * @param DrugId $drugId * @param UserId $userId diff --git a/routes/api.php b/routes/api.php index 5205221c..0f0e71d0 100644 --- a/routes/api.php +++ b/routes/api.php @@ -6,6 +6,7 @@ use App\Http\Api\Drug\Actions\GetDrugListAction; use App\Http\Api\Drug\Actions\UpdateDrugAction; use App\Http\Api\MedicationHistory\Actions\CreateMedicationHistoryAction; +use App\Http\Api\MedicationHistory\Actions\DeleteMedicationHistoryAction; use App\Http\Api\MedicationHistory\Actions\GetMedicationHistoryAction; use App\Http\Api\MedicationHistory\Actions\GetMedicationHistoryListAction; use App\Http\Api\MedicationHistory\Actions\UpdateMedicationHistoryAction; @@ -42,5 +43,6 @@ Route::post('/', CreateMedicationHistoryAction::class)->name('api.medication_histories.create'); Route::get('/{id}', GetMedicationHistoryAction::class)->name('api.medication_histories.detail'); Route::put('/{id}', UpdateMedicationHistoryAction::class)->name('api.medication_histories.update'); + Route::delete('/{id}', DeleteMedicationHistoryAction::class)->name('api.medication_histories.delete'); }); }); From 5626ba221a561d994e15ffc0d944af4189dcc25d Mon Sep 17 00:00:00 2001 From: fyui001 Date: Wed, 1 Apr 2026 10:37:18 +0900 Subject: [PATCH 2/3] Add medication date field to update medication history API Co-Authored-By: Claude Opus 4.6 (1M context) --- .../Actions/UpdateMedicationHistoryAction.php | 4 +++- .../Requests/UpdateMedicationHistoryRequest.php | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/Http/Api/MedicationHistory/Actions/UpdateMedicationHistoryAction.php b/app/Http/Api/MedicationHistory/Actions/UpdateMedicationHistoryAction.php index 022f842c..c44f4aca 100644 --- a/app/Http/Api/MedicationHistory/Actions/UpdateMedicationHistoryAction.php +++ b/app/Http/Api/MedicationHistory/Actions/UpdateMedicationHistoryAction.php @@ -59,12 +59,14 @@ public function __invoke(int $id, UpdateMedicationHistoryRequest $request): Upda { $existing = $this->medicationHistoryRepository->get(new MedicationHistoryId($id)); + $medicationDate = $request->getMedicationDate() ?? $existing->getMedicationDate(); + $medicationHistory = new MedicationHistory( $existing->getId(), $existing->getUserId(), $existing->getDrugId(), $request->getAmount(), - $existing->getMedicationDate(), + $medicationDate, $request->getNote(), $existing->getCreatedAt(), UpdatedAt::now(), diff --git a/app/Http/Api/MedicationHistory/Requests/UpdateMedicationHistoryRequest.php b/app/Http/Api/MedicationHistory/Requests/UpdateMedicationHistoryRequest.php index ef3cd34e..1ee9a317 100644 --- a/app/Http/Api/MedicationHistory/Requests/UpdateMedicationHistoryRequest.php +++ b/app/Http/Api/MedicationHistory/Requests/UpdateMedicationHistoryRequest.php @@ -6,6 +6,7 @@ use App\Http\Api\Shered\Request\ApiRequest; use Domain\MedicationHistory\Amount; +use Domain\MedicationHistory\MedicationDate; use Domain\MedicationHistory\MedicationNote; use OpenApi\Attributes\Property; use OpenApi\Attributes\Schema; @@ -15,6 +16,7 @@ properties: [ new Property(property: 'amount', type: 'number', format: 'double'), new Property(property: 'note', type: 'string', nullable: true), + new Property(property: 'medication_date', type: 'string', format: 'date-time', nullable: true), ] )] class UpdateMedicationHistoryRequest extends ApiRequest @@ -29,6 +31,7 @@ public function rules(): array return [ 'amount' => 'required|numeric', 'note' => 'nullable|string', + 'medication_date' => 'nullable|date', ]; } @@ -41,4 +44,13 @@ public function getNote(): MedicationNote { return new MedicationNote($this->input('note')); } + + public function getMedicationDate(): ?MedicationDate + { + $value = $this->input('medication_date'); + if (is_null($value)) { + return null; + } + return new MedicationDate($value); + } } From 22060ebe434f1dbfd1101f4e6d97bb8772b9a858 Mon Sep 17 00:00:00 2001 From: fyui001 Date: Wed, 1 Apr 2026 10:37:21 +0900 Subject: [PATCH 3/3] Update OpenAPI spec for delete endpoint and medication date field Co-Authored-By: Claude Opus 4.6 (1M context) --- storage/api-docs/api-docs.json | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/storage/api-docs/api-docs.json b/storage/api-docs/api-docs.json index 6b6bd805..710fded7 100755 --- a/storage/api-docs/api-docs.json +++ b/storage/api-docs/api-docs.json @@ -377,6 +377,45 @@ "description": "Unauthorized" } } + }, + "delete": { + "tags": [ + "MedicationHistory" + ], + "summary": "服薬履歴を削除する", + "operationId": "1ad17a3f19538c0535c42eb5fd6295cd", + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "integer" + } + } + ], + "responses": { + "200": { + "description": "success", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/base_responder" + } + } + } + }, + "404": { + "description": "not found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/api_error_responder" + } + } + } + } + } } } }, @@ -725,6 +764,11 @@ "note": { "type": "string", "nullable": true + }, + "medication_date": { + "type": "string", + "format": "date-time", + "nullable": true } }, "type": "object"