Skip to content

Commit

Permalink
Enum for familyname and api base route
Browse files Browse the repository at this point in the history
  • Loading branch information
omar-selo committed May 19, 2023
1 parent 083793c commit ed7c6bc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 51 deletions.
1 change: 1 addition & 0 deletions frontend/lib/models/family_name.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enum FamilyName { snap, deb }
2 changes: 1 addition & 1 deletion frontend/lib/providers/dio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ part 'dio.g.dart';

@riverpod
Dio dio(DioRef ref) {
final dio = Dio();
final dio = Dio(BaseOptions(baseUrl: 'http://localhost:3000'));
return dio;
}
54 changes: 7 additions & 47 deletions frontend/lib/providers/stages.dart
Original file line number Diff line number Diff line change
@@ -1,57 +1,17 @@
import 'package:riverpod_annotation/riverpod_annotation.dart';

import '../models/artefact.dart';
import '../models/family_name.dart';
import '../models/stage.dart';
import 'dio.dart';

part 'stages.g.dart';

@riverpod
Future<List<Stage>> stages(StagesRef ref, String familyName) async {
// final dio = ref.watch(dioProvider);
Future<List<Stage>> stages(StagesRef ref, FamilyName familyName) async {
final dio = ref.watch(dioProvider);

// final response = await dio.get('/family/$familyName/stages');
// final List stagesJson = response.data;
// final stages = stagesJson.map((json) => Stage.fromJson(json)).toList();
// return stages;

if (familyName != 'snap') {
throw Exception('Invalid familyName "$familyName"');
}

return Future.delayed(
const Duration(seconds: 2),
() => const [
Stage(
name: 'Stage 1',
artefacts: [
Artefact(name: 'Artefact 1'),
Artefact(name: 'Artefact 2'),
Artefact(name: 'Artefact 3'),
Artefact(name: 'Artefact 4'),
],
),
Stage(
name: 'Stage 2',
artefacts: [
Artefact(name: 'Artefact 11'),
Artefact(name: 'Artefact 12'),
],
),
Stage(
name: 'Stage 3',
artefacts: [
Artefact(name: 'Artefact 21'),
Artefact(name: 'Artefact 22'),
Artefact(name: 'Artefact 23'),
Artefact(name: 'Artefact 24'),
Artefact(name: 'Artefact 24'),
],
),
Stage(
name: 'Stage 4',
artefacts: [],
),
],
);
final response = await dio.get('/families/${familyName.name}');
final List stagesJson = response.data;
final stages = stagesJson.map((json) => Stage.fromJson(json)).toList();
return stages;
}
7 changes: 4 additions & 3 deletions frontend/lib/ui/dashboard/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:yaru_widgets/widgets.dart';

import '../../models/family_name.dart';
import '../../providers/stages.dart';
import 'dashboard_body.dart';
import 'dashboard_header.dart';
Expand All @@ -12,7 +13,7 @@ class SnapDashboard extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const _Dashboard(
familyName: 'snap',
familyName: FamilyName.snap,
title: 'Snap Update Verification',
);
}
Expand All @@ -24,7 +25,7 @@ class DebDashboard extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const _Dashboard(
familyName: 'deb',
familyName: FamilyName.deb,
title: 'Deb Update Verification',
);
}
Expand All @@ -34,7 +35,7 @@ class _Dashboard extends ConsumerWidget {
const _Dashboard({Key? key, required this.familyName, required this.title})
: super(key: key);

final String familyName;
final FamilyName familyName;
final String title;

@override
Expand Down

0 comments on commit ed7c6bc

Please sign in to comment.