-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #144 from kosukesaigusa/119_create_update_job_page
#119 仕事編集、作成ページの作成
- Loading branch information
Showing
12 changed files
with
972 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
packages/mottai_flutter_app/lib/job/ui/job_controller.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:firebase_common/firebase_common.dart'; | ||
import 'package:hooks_riverpod/hooks_riverpod.dart'; | ||
|
||
import '../../image/firebase_storage.dart'; | ||
import '../job.dart'; | ||
|
||
final jobControllerProvider = | ||
Provider.family.autoDispose<JobController, String>( | ||
(ref, userId) => JobController( | ||
jobService: ref.watch(jobServiceProvider), | ||
firebaseStorageService: ref.watch(firebaseStorageServiceProvider), | ||
userId: userId, | ||
), | ||
); | ||
|
||
class JobController { | ||
const JobController({ | ||
required JobService jobService, | ||
required FirebaseStorageService firebaseStorageService, | ||
required String userId, | ||
}) : _jobService = jobService, | ||
_firebaseStorageService = firebaseStorageService, | ||
_userId = userId; | ||
|
||
/// storageの画像を保存するフォルダのパス | ||
static const _storagePath = 'jobs'; | ||
|
||
final JobService _jobService; | ||
final FirebaseStorageService _firebaseStorageService; | ||
final String _userId; | ||
|
||
/// [Job] の情報を作成する。 | ||
Future<void> create({ | ||
required String hostId, | ||
required String title, | ||
required String content, | ||
required String place, | ||
required Set<AccessType> accessTypes, | ||
required String accessDescription, | ||
required String belongings, | ||
required String reward, | ||
required String comment, | ||
File? imageFile, | ||
}) async { | ||
var imageUrl = ''; | ||
if (imageFile != null) { | ||
imageUrl = await _uploadImage(imageFile); | ||
} | ||
await _jobService.create( | ||
hostId: hostId, | ||
title: title, | ||
content: content, | ||
place: place, | ||
accessTypes: accessTypes, | ||
accessDescription: accessDescription, | ||
belongings: belongings, | ||
reward: reward, | ||
comment: comment, | ||
imageUrl: imageUrl, | ||
); | ||
} | ||
|
||
/// [Job] を更新する。 | ||
Future<void> updateJob({ | ||
required String jobId, | ||
String? title, | ||
String? content, | ||
String? place, | ||
Set<AccessType>? accessTypes, | ||
String? accessDescription, | ||
String? belongings, | ||
String? reward, | ||
String? comment, | ||
File? imageFile, | ||
}) async { | ||
String? imageUrl; | ||
if (imageFile != null) { | ||
imageUrl = await _uploadImage(imageFile); | ||
} | ||
await _jobService.update( | ||
jobId: jobId, | ||
title: title, | ||
content: content, | ||
place: place, | ||
accessTypes: accessTypes, | ||
accessDescription: accessDescription, | ||
belongings: belongings, | ||
reward: reward, | ||
comment: comment, | ||
imageUrl: imageUrl, | ||
); | ||
} | ||
|
||
Future<String> _uploadImage(File imageFile) { | ||
final imagePath = '$_storagePath/$_userId-${DateTime.now()}.jpg'; | ||
return _firebaseStorageService.upload( | ||
path: imagePath, | ||
resource: FirebaseStorageFile(imageFile), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'package:auto_route/auto_route.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:hooks_riverpod/hooks_riverpod.dart'; | ||
|
||
import '../../auth/ui/auth_dependent_builder.dart'; | ||
import 'job_form.dart'; | ||
|
||
/// 仕事情報更新ページ。 | ||
@RoutePage() | ||
class JobCreatePage extends ConsumerWidget { | ||
const JobCreatePage({ | ||
super.key, | ||
}); | ||
|
||
static const path = '/jobs/create'; | ||
|
||
/// [JobCreatePage] に遷移する際に `context.router.pushNamed` で指定する文字列。 | ||
static const location = path; | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
return Scaffold( | ||
appBar: AppBar(title: const Text('お手伝い募集内容を入力')), | ||
// TODO:なるんさんが実装中の「本人かどうかビルダー」に後で書き換える。 | ||
body: AuthDependentBuilder( | ||
onAuthenticated: (hostId) { | ||
return JobForm.create(hostId: hostId); | ||
}, | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.