Skip to content

Commit

Permalink
Fetch artefact versions from api
Browse files Browse the repository at this point in the history
  • Loading branch information
omar-selo committed Sep 11, 2024
1 parent 7e4013f commit 6f03f8f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
15 changes: 15 additions & 0 deletions frontend/lib/models/artefact_version.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:freezed_annotation/freezed_annotation.dart';

part 'artefact_version.freezed.dart';
part 'artefact_version.g.dart';

@freezed
class ArtefactVersion with _$ArtefactVersion {
const factory ArtefactVersion({
@JsonKey(name: 'artefact_id') required int artefactId,
required String version,
}) = _ArtefactVersion;

factory ArtefactVersion.fromJson(Map<String, Object?> json) =>
_$ArtefactVersionFromJson(json);
}
3 changes: 2 additions & 1 deletion frontend/lib/providers/artefact_versions.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import 'package:riverpod_annotation/riverpod_annotation.dart';

import '../models/artefact_version.dart';
import 'api.dart';

part 'artefact_versions.g.dart';

@riverpod
Future<List<({int artefactId, String version})>> artefactVersions(
Future<List<ArtefactVersion>> artefactVersions(
ArtefactVersionsRef ref,
int artefactId,
) async {
Expand Down
11 changes: 5 additions & 6 deletions frontend/lib/repositories/api_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:dio/dio.dart';
import '../models/artefact.dart';

import '../models/artefact_build.dart';
import '../models/artefact_version.dart';
import '../models/family_name.dart';
import '../models/rerun_request.dart';
import '../models/test_execution.dart';
Expand Down Expand Up @@ -131,13 +132,11 @@ class ApiRepository {
return Artefact.fromJson(response.data);
}

Future<List<({int artefactId, String version})>> getArtefactVersions(
Future<List<ArtefactVersion>> getArtefactVersions(
int artefactId,
) async {
return [
(artefactId: 1, version: '1'),
(artefactId: 2, version: '2'),
(artefactId: 3, version: '3'),
];
final response = await dio.get('/v1/artefacts/$artefactId/versions');
final List data = response.data;
return data.map((json) => ArtefactVersion.fromJson(json)).toList();
}
}

0 comments on commit 6f03f8f

Please sign in to comment.