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

#118 ホスト作成、更新画面の作成 #184

Merged
merged 16 commits into from
Sep 8, 2023
Merged

Conversation

RikitoNoto
Copy link
Collaborator

@RikitoNoto RikitoNoto commented Sep 6, 2023

Issue

close #118

説明

ホスト作成、更新画面を作成しました。

仕様

  • 作成画面での位置情報初期値は東京駅としています。
  • ホスト情報作成時にホストロケーションも作成、更新を行います。
  • ホストロケーションは将来的にホストと1対多の関係になりますが、現状は1つしか更新ができません。(ホストに紐づく最初のホストロケーションを更新対象としています。)

デバッグ用開発ページ

  • ホストとして登録ページ(hosts/create)
  • ホスト情報更新ページ(/hosts/:hostId/update)(hosts/updateでもいいかもと思いました。)

UI

■バリデーション実行
118_validate

■作成
118_create

■更新
118_update

その他

その他に言及したいことがあれば書いてください。

チェックリスト

  • PR の冒頭に関連する Issue 番号を記載しましたか?
  • 本 PR の変更に関して、エディタや IDE で意図しない警告は増えていませんか?(lint 警告やタイポなど)
  • Issue の完了の定義は満たせていますか?
  • 当該 Issue のスレッドで、レビュワーにレビュー依頼をしましたか?

@RikitoNoto RikitoNoto added the 1. 機能開発 機能開発 label Sep 6, 2023
Comment on lines 50 to 66
// Hostの作成
final imageUrl = await _uploadImage(imageFile);
await _hostService.create(
workerId: workerId,
displayName: displayName,
introduction: introduction,
hostTypes: hostTypes,
urls: urls,
imageUrl: imageUrl,
);

// Locationの作成
await _locationService.create(
hostId: workerId,
address: address,
geo: geo,
);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

後で対応メモ:画面全体の OverlayLoading を有効にして使うと良さそう

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちらは何か修正しますか?
ついでに直せる内容でしたら修正します!

Comment on lines 52 to 66
await _hostService.create(
workerId: workerId,
displayName: displayName,
introduction: introduction,
hostTypes: hostTypes,
urls: urls,
imageUrl: imageUrl,
);

// Locationの作成
await _locationService.create(
hostId: workerId,
address: address,
geo: geo,
);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この 2 つは実際にはセットでコールするものなので、Controller が順に呼ぶというよりは、host と hostLocation を一緒に更新するサービスクラスのメソッドを定義するべきかも?と思いました!(そのサービスクラスの名前は HostService で良いと思います。今回する必要はないですが、本来はバッチ書き込みしても良いような内容なので)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正しました!

Comment on lines 85 to 103
await _hostService.update(
hostId: hostId,
displayName: displayName,
introduction: introduction,
hostTypes: hostTypes,
urls: urls,
imageUrl: imageUrl,
);

// Locationの更新
final locations =
await _locationService.fetchHostLocationsFromHost(hostId: hostId);
if (locations != null && locations.isNotEmpty) {
await _locationService.update(
hostLocationId: locations.first.hostLocationId,
address: address,
geo: geo,
);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここもまるっとひとつのモデル(サービス)クラスのメソッドで書くべきかもなと思いました!


また前にちょっと話しましたが、host vs. hostLocation は常に 1 対 1 の前提で良いと思っていました!(ホストに「あなたが登録している hostLocation 一覧」みたいな画面を作るつもりもないです)分かりづらくてすみません🙏

https://flutteruniv.slack.com/archives/C05HHFHGJSC/p1690290571400399?thread_ts=1690284627.798819&cid=C05HHFHGJSC

それならそもそも hostLocation の id は hostId と一致でも良さそうですね...!

※ 上記は対応したかったら & できそうだったらでいいです!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正しました!

final formKey = GlobalKey<FormState>();

/// 選択中のホストタイプ
final List<HostType> _selectedHosyTypes = [];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

タイポ:_selectedHostTypes

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ご指摘ありがとうございます。
修正しました!

Comment on lines 91 to 102
static LatLng convertGeoToLatLng(Geo? geo) {
var latitude = 0.0;

var longitude = 0.0;

if (geo != null) {
latitude = geo.geopoint.latitude;
longitude = geo.geopoint.longitude;
}

return LatLng(latitude, longitude);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static メソッドにしている必要はなさそう?単に private メソッドで OK?

[確認]

null が入ってくると LatLng(0, 0) が返されるのは意図通りですか?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

すみません、開発過程で別のクラスに置いていたので、修正が漏れていました。
nullが入ってくることがないので、修正しました!


/// 入力が必須か任意かを表すバッジ
/// [isRequired] の値によって、必須か任意の文字を選択して返す。
class _OptionalBadge extends StatelessWidget {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

host_form と job_form とで Duplicated なので共通のものとして lib/widgets/ にでも置いてほしいです!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新しくOpstionalBadgeクラスを定義しました!

/// [TextField]をGridで表示するウィジェット
/// GridViewの場合は、aspect比を指定する必要があり、
/// [TextField]のような可変長aspect比が必要なウィジェットでは使用できないため作成
class _VariableHeightGrid extends StatelessWidget {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほど... 意外と難しいんですね

@@ -51,4 +51,40 @@ class HostService {
/// 指定した [Host] を取得する。
Future<ReadHost?> fetchHost({required String hostId}) =>
_hostRepository.fetchHost(hostId: hostId);

/// [Host] の情報を作成する。
Future<void> create({
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

上で書いたとおりですが、Controller で色々書いているのをモデルに移動してほしいです。現状モデルは単に Repository のメソッドを呼ぶだけの感じになっています。Controller が肥大化するのではなく、モデルにロジックを書きます。Controller は ユーザー操作をモデルに伝えるもの、UI を操作するものであることを意識してみてください!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正しました!

- urlMaxCountの定義場所変更
- HostLocation作成、更新処理の定義場所移動
- タイポ修正: _selectedHostTypes
- 座標変換関数のprivate化
- OptionalBadge の作成
@RikitoNoto RikitoNoto merged commit 7885639 into main Sep 8, 2023
5 checks passed
@RikitoNoto RikitoNoto deleted the 118_create_update_host branch September 8, 2023 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1. 機能開発 機能開発
Projects
Development

Successfully merging this pull request may close these issues.

ホスト情報入力画面(ホストデータ作成・更新画面)の実装
2 participants