RyosukeSakakibara718 / project-balancer

A project management tool that allows managers to track member work hours and calculate/forecast gross profit based on the tracked data. This app helps in efficient resource allocation and profitability analysis.
0 stars 0 forks source link

案件管理画面/API作成 検索機能 #125

Closed RyosukeSakakibara718 closed 1 month ago

tsukimi0618 commented 2 months ago

メモ 案件管理画面で実装するのは検索機能と削除機能

検索機能は検索内容が案件名による検索で処理がシンプルなため、 indexアクションとsearchアクションを切り分けずにindexの中で行う。

tsukimi0618 commented 2 months ago

※docker downしたら毎回必要

DBデータ挿入 docker-compose exec apache bash php artisan migrate php artisan db:seed --class=ProjectTableSeeder php artisan db:seed --class=AssignmentMemberTableSeeder php artisan db:seed --class=WorkCostTableSeeder

データ確認 docker-compose exec db bash psql -U username -d project_balancer_local SELECT * FROM projects;

例:

id | freee_project_code | name | contract | phase | start_date | end_date | created_at | updated_at | deleted_at ----+--------------------+-------------------------------+----------+-------+------------+------------+---------------------+---------------------+------------ 1 | PRJ52047 | eligendi nobis deleniti | 2 | 3 | 1975-08-18 | 1980-06-25 | 2024-09-01 08:45:17 | 2024-09-01 08:45:17 | 2 | PRJ16334 | ut sed atque | 2 | 1 | 2024-04-09 | 1998-05-02 | 2024-09-01 08:45:17 | 2024-09-01 08:45:17 | 3 | PRJ57639 | dolorem nostrum voluptatem | 2 | 2 | 2024-07-16 | 1996-09-20 | 2024-09-01 08:45:17 | 2024-09-01 08:45:17 | 4 | PRJ25600 | qui quisquam fugit | 2 | 2 | 1993-12-27 | 2017-06-19 | 2024-09-01 08:45:17 | 2024-09-01 08:45:17 | 5 | PRJ67038 | ipsam ut ipsum | 3 | 3 | 1976-11-20 | 2003-04-04 | 2024-09-01 08:45:17 | 2024-09-01 08:45:17 | 6 | PRJ75056 | exercitationem sit atque | 1 | 3 | 2023-07-21 | 2002-08-12 | 2024-09-01 08:45:17 | 2024-09-01 08:45:17 | 7 | PRJ14088 | quibusdam veritatis quaerat | 3 | 5 | 1989-07-16 | 1990-11-23 | 2024-09-01 08:45:17 | 2024-09-01 08:45:17 | 8 | PRJ91131 | incidunt voluptatem molestias | 2 | 3 | 2022-01-28 | 2024-02-14 | 2024-09-01 08:45:17 | 2024-09-01 08:45:17 | 9 | PRJ00305 | dolores molestiae voluptatem | 1 | 4 | 2001-11-23 | 1997-07-19 | 2024-09-01 08:45:17 | 2024-09-01 08:45:17 | 10 | PRJ25127 | sed sequi aperiam | 1 | 3 | 1977-09-26 | 1990-01-31 | 2024-09-01 08:45:17 | 2024-09-01 08:45:17 |

tsukimi0618 commented 2 months ago
root@d077c151717c:/var/www/html# php artisan route:list

  GET|HEAD        / ..................................................................................................................................................................... 
  GET|HEAD        up .................................................................................................................................................................... 
  GET|HEAD        v1/members ..................................................................................................................... members.index › MemberController@index
  POST            v1/members ..................................................................................................................... members.store › MemberController@store
  GET|HEAD        v1/members/{member} .............................................................................................................. members.show › MemberController@show
  PUT|PATCH       v1/members/{member} .......................................................................................................... members.update › MemberController@update
  DELETE          v1/members/{member} ........................................................................................................ members.destroy › MemberController@destroy
  GET|HEAD        v1/projects .................................................................................................................. projects.index › ProjectController@index
  POST            v1/projects .................................................................................................................. projects.store › ProjectController@store
  GET|HEAD        v1/projects/{project} .......................................................................................................... projects.show › ProjectController@show
  PUT|PATCH       v1/projects/{project} ...................................................................................................... projects.update › ProjectController@update
  DELETE          v1/projects/{project} .................................................................................................... projects.destroy › ProjectController@destroy

indexのルート問題なし GET|HEAD v1/projects .......... projects.index › ProjectController@index

URI http://localhost:80/v1/projects?name=eligendi 500エラー

エラー原因特定するために project-balancer % docker-compose logs apache apache | 172.21.0.1 - - [01/Sep/2024:09:12:15 +0000] "GET /v1/projects?name=eligendi HTTP/1.1" 500 302632 "-" "PostmanRuntime/7.36.0"

docker-compose exec apache tail -n 1000 storage/logs/laravel.log

tsukimi0618 commented 2 months ago

主なエラー: エラーログの中で最も重要な部分は以下の行です。

vbnet コードをコピーする [2024-09-01 13:14:39] local.ERROR: Attempt to read property "member" on null {"exception":"[object] (ErrorException(code: 0): Attempt to read property \"member\" on null at /var/www/html/app/Http/Resources/ProjectResource.php:25) これは、ProjectResource クラスの toArray メソッド内で、$this->assignmentMembers->firstWhere('position', 'PM')->member を使用して member プロパティにアクセスしようとした際に発生したエラーです。このエラーは、$this->assignmentMembers->firstWhere('position', 'PM') の結果が null である場合に発生します。つまり、position が 'PM' である assignmentMembers が見つからなかったため、member プロパティにアクセスしようとした時点で null 参照エラーが発生しています。

tsukimi0618 commented 2 months ago

'project_manager' => optional(optional($this->assignmentMembers->firstWhere('position', 'PM'))->member)->name, で検索ヒットしないときにnullかえす+seederでデータ突っ込むときにPMが入るようにデータを指定する必要あり

tsukimi0618 commented 2 months ago

手順1: データベースのリセット php artisan migrate:refresh 手順2:すべてのデータベースをシーディング (DatabaseSeederに記載必須) php artisan db:seed

tsukimi0618 commented 2 months ago

id | freee_project_code | name | contract | phase | start_date | end_date | created_at | updated_at | deleted_at ----+--------------------+--------------------------+----------+-------+------------+------------+---------------------+---------------------+------------ 1 | PRJ20794 | doloremque unde et | 2 | 5 | 1973-09-01 | 2003-05-04 | 2024-09-01 14:23:27 | 2024-09-01 14:23:27 | 2 | PRJ98525 | autem et nesciunt | 2 | 5 | 2008-11-28 | 2025-01-15 | 2024-09-01 14:23:27 | 2024-09-01 14:23:27 | 3 | PRJ54665 | et pariatur minima | 3 | 2 | 2020-04-22 | 1990-07-04 | 2024-09-01 14:23:27 | 2024-09-01 14:23:27 | 4 | PRJ38886 | eligendi tempore facere | 2 | 3 | 1991-11-14 | 1995-11-30 | 2024-09-01 14:23:27 | 2024-09-01 14:23:27 | 5 | PRJ70160 | cupiditate quia eligendi | 1 | 5 | 1985-07-28 | 1986-07-20 | 2024-09-01 14:23:27 | 2024-09-01 14:23:27 | 6 | PRJ01698 | doloribus enim facere | 2 | 2 | 1994-06-27 | 2011-09-15 | 2024-09-01 14:23:27 | 2024-09-01 14:23:27 | 7 | PRJ21646 | officiis qui qui | 3 | 1 | 2020-06-11 | 1982-03-03 | 2024-09-01 14:23:27 | 2024-09-01 14:23:27 | 8 | PRJ63545 | id consequatur est | 1 | 1 | 1988-07-09 | 1981-07-23 | 2024-09-01 14:23:27 | 2024-09-01 14:23:27 | 9 | PRJ60321 | maxime qui quibusdam | 3 | 4 | 1993-08-21 | 1990-04-19 | 2024-09-01 14:23:27 | 2024-09-01 14:23:27 | 10 | PRJ19930 | quisquam vitae debitis | 1 | 4 | 1999-03-13 | 1999-08-06 | 2024-09-01 14:23:27 | 2024-09-01 14:23:27 |

tsukimi0618 commented 2 months ago

project_balancer_local=# SELECT * FROM assignment_members; id | project_id | member_id | position | estimate_total_person_month | created_at | updated_at | deleted_at ----+------------+-----------+----------+-----------------------------+---------------------+---------------------+------------ 1 | 1 | 1 | 1 | 5.00 | 2024-09-01 14:23:27 | 2024-09-01 14:23:27 |