preparation for song entity
This commit is contained in:
parent
710acac821
commit
49b3395424
15 changed files with 194 additions and 42 deletions
|
@ -49,7 +49,7 @@ linter:
|
|||
- always_put_control_body_on_new_line
|
||||
# - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
|
||||
- always_require_non_null_named_parameters
|
||||
- always_specify_types
|
||||
##### - always_specify_types
|
||||
- annotate_overrides
|
||||
# - avoid_annotating_with_dynamic # conflicts with always_specify_types
|
||||
# - avoid_as # required for implicit-casts: true
|
||||
|
|
|
@ -1,6 +1,16 @@
|
|||
import 'package:equatable/equatable.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class Song extends Equatable {
|
||||
Song({
|
||||
@required this.title,
|
||||
@required this.album,
|
||||
@required this.artist,
|
||||
@required this.path,
|
||||
this.trackNumber,
|
||||
this.albumArtPath,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final String album;
|
||||
final String artist;
|
||||
|
@ -8,9 +18,6 @@ class Song extends Equatable {
|
|||
final String path;
|
||||
final String albumArtPath;
|
||||
|
||||
Song(this.title, this.album, this.artist, this.trackNumber, this.path,
|
||||
this.albumArtPath);
|
||||
|
||||
@override
|
||||
List<Object> get props => [title, album, artist];
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import 'package:dartz/dartz.dart';
|
||||
import 'package:mosh/core/error/failures.dart';
|
||||
|
||||
import '../../core/error/failures.dart';
|
||||
import '../entities/album.dart';
|
||||
// import '../entities/artist.dart';
|
||||
import '../entities/song.dart';
|
||||
|
||||
abstract class MusicDataRepository {
|
||||
Future<Either<Failure, List<Song>>> getSongs();
|
||||
Future<Either<Failure, List<Album>>> getAlbums();
|
||||
// Future<List<Album>> getAlbumsByArtist(Artist artist);
|
||||
Future<void> updateDatabase();
|
||||
}
|
|
@ -5,11 +5,11 @@ import '../../core/usecase.dart';
|
|||
import '../entities/album.dart';
|
||||
import '../repositories/music_data_repository.dart';
|
||||
|
||||
class GetAlbums implements UseCase<List<Album>, Null> {
|
||||
final MusicDataRepository musicDataRepository;
|
||||
|
||||
class GetAlbums implements UseCase<List<Album>, void> {
|
||||
GetAlbums(this.musicDataRepository);
|
||||
|
||||
final MusicDataRepository musicDataRepository;
|
||||
|
||||
@override
|
||||
Future<Either<Failure, List<Album>>> call([_]) async {
|
||||
return await musicDataRepository.getAlbums();
|
||||
|
|
17
lib/domain/usecases/get_songs.dart
Normal file
17
lib/domain/usecases/get_songs.dart
Normal file
|
@ -0,0 +1,17 @@
|
|||
import 'package:dartz/dartz.dart';
|
||||
|
||||
import '../../core/error/failures.dart';
|
||||
import '../../core/usecase.dart';
|
||||
import '../entities/song.dart';
|
||||
import '../repositories/music_data_repository.dart';
|
||||
|
||||
class GetSongs implements UseCase<List<Song>, void> {
|
||||
GetSongs(this.musicDataRepository);
|
||||
|
||||
final MusicDataRepository musicDataRepository;
|
||||
|
||||
@override
|
||||
Future<Either<Failure, List<Song>>> call([_]) async {
|
||||
return await musicDataRepository.getSongs();
|
||||
}
|
||||
}
|
23
lib/system/models/song_model.dart
Normal file
23
lib/system/models/song_model.dart
Normal file
|
@ -0,0 +1,23 @@
|
|||
import 'package:mosh/domain/entities/song.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
class SongModel extends Song {
|
||||
SongModel({
|
||||
this.id,
|
||||
@required String title,
|
||||
@required String album,
|
||||
@required String artist,
|
||||
@required String path,
|
||||
int trackNumber,
|
||||
String albumArtPath,
|
||||
}) : super(
|
||||
title: title,
|
||||
album: album,
|
||||
artist: artist,
|
||||
path: path,
|
||||
trackNumber: trackNumber,
|
||||
albumArtPath: albumArtPath,
|
||||
);
|
||||
|
||||
final int id;
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:dartz/dartz.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:mosh/domain/entities/song.dart';
|
||||
|
||||
import '../../core/error/failures.dart';
|
||||
import '../../domain/entities/album.dart';
|
||||
|
@ -35,4 +36,10 @@ class MusicDataRepositoryImpl implements MusicDataRepository {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, List<Song>>> getSongs() {
|
||||
// TODO: implement getSongs
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ void main() {
|
|||
});
|
||||
|
||||
final tAlbums = <Album>[
|
||||
Album(title: "Back in Black", artist: "AC/DC"),
|
||||
Album(title: "Twilight Of The Thunder God", artist: "Amon Amarth"),
|
||||
Album(title: 'Back in Black', artist: 'AC/DC'),
|
||||
Album(title: 'Twilight Of The Thunder God', artist: 'Amon Amarth'),
|
||||
];
|
||||
|
||||
test(
|
||||
|
|
54
test/domain/usecases/get_songs_test.dart
Normal file
54
test/domain/usecases/get_songs_test.dart
Normal file
|
@ -0,0 +1,54 @@
|
|||
import 'package:dartz/dartz.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:mosh/domain/entities/song.dart';
|
||||
import 'package:mosh/domain/repositories/music_data_repository.dart';
|
||||
import 'package:mosh/domain/usecases/get_songs.dart';
|
||||
|
||||
import '../../test_constants.dart';
|
||||
|
||||
class MockMusicDataRepository extends Mock implements MusicDataRepository {}
|
||||
|
||||
void main() {
|
||||
GetSongs usecase;
|
||||
MockMusicDataRepository mockMusicDataRepository;
|
||||
|
||||
setUp(() {
|
||||
mockMusicDataRepository = MockMusicDataRepository();
|
||||
usecase = GetSongs(mockMusicDataRepository);
|
||||
});
|
||||
|
||||
final tSongs = <Song>[
|
||||
Song(
|
||||
album: ALBUM_TITLE_3,
|
||||
artist: ARTIST_3,
|
||||
title: SONG_TITLE_3,
|
||||
path: PATH_3,
|
||||
albumArtPath: ALBUM_ART_PATH_3,
|
||||
trackNumber: TRACKNUMBER_3,
|
||||
),
|
||||
Song(
|
||||
album: ALBUM_TITLE_4,
|
||||
artist: ARTIST_4,
|
||||
title: SONG_TITLE_4,
|
||||
path: PATH_4,
|
||||
albumArtPath: ALBUM_ART_PATH_4,
|
||||
trackNumber: TRACKNUMBER_4,
|
||||
),
|
||||
];
|
||||
|
||||
test(
|
||||
'should get all songs from the repository',
|
||||
() async {
|
||||
// arrange
|
||||
when(mockMusicDataRepository.getSongs())
|
||||
.thenAnswer((_) async => Right(tSongs));
|
||||
// act
|
||||
final result = await usecase();
|
||||
// assert
|
||||
expect(result, Right(tSongs));
|
||||
verify(mockMusicDataRepository.getSongs());
|
||||
verifyNoMoreInteractions(mockMusicDataRepository);
|
||||
},
|
||||
);
|
||||
}
|
|
@ -23,7 +23,7 @@ void main() {
|
|||
|
||||
setUp(() {
|
||||
mockAlbumInfo = MockAlbumInfo();
|
||||
when(mockAlbumInfo.title).thenReturn(TITLE_1);
|
||||
when(mockAlbumInfo.title).thenReturn(ALBUM_TITLE_1);
|
||||
when(mockAlbumInfo.albumArt).thenReturn(ALBUM_ART_PATH_1);
|
||||
when(mockAlbumInfo.artist).thenReturn(ARTIST_1);
|
||||
when(mockAlbumInfo.firstYear).thenReturn(FIRST_YEAR_1.toString());
|
||||
|
|
|
@ -14,7 +14,7 @@ void main() {
|
|||
MoorMusicDataSource.withQueryExecutor(VmDatabase.memory());
|
||||
|
||||
albumModel = AlbumModel(
|
||||
title: TITLE_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
artist: ARTIST_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
year: YEAR_1,
|
||||
|
|
|
@ -11,7 +11,7 @@ class MockAlbumInfo extends Mock implements AlbumInfo {}
|
|||
|
||||
void main() {
|
||||
final tAlbumModel = AlbumModel(
|
||||
title: TITLE_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
artist: ARTIST_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
year: YEAR_1,
|
||||
|
@ -32,14 +32,14 @@ void main() {
|
|||
// arrange
|
||||
final expected = MoorAlbum(
|
||||
artist: ARTIST_1,
|
||||
title: TITLE_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
year: YEAR_1,
|
||||
);
|
||||
|
||||
final albumModel = AlbumModel(
|
||||
artist: ARTIST_1,
|
||||
title: TITLE_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
year: YEAR_1,
|
||||
);
|
||||
|
@ -58,14 +58,14 @@ void main() {
|
|||
// arrange
|
||||
final moorAlbum = MoorAlbum(
|
||||
artist: ARTIST_1,
|
||||
title: TITLE_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
year: YEAR_1,
|
||||
);
|
||||
|
||||
final expected = AlbumModel(
|
||||
artist: ARTIST_1,
|
||||
title: TITLE_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
year: YEAR_1,
|
||||
);
|
||||
|
@ -82,13 +82,13 @@ void main() {
|
|||
// arrange
|
||||
final moorAlbum = MoorAlbum(
|
||||
artist: ARTIST_1,
|
||||
title: TITLE_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
year: YEAR_1,
|
||||
);
|
||||
|
||||
final expected = AlbumModel(
|
||||
artist: ARTIST_1,
|
||||
title: TITLE_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
year: YEAR_1,
|
||||
);
|
||||
// act
|
||||
|
@ -104,13 +104,13 @@ void main() {
|
|||
// arrange
|
||||
final moorAlbum = MoorAlbum(
|
||||
artist: ARTIST_1,
|
||||
title: TITLE_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
);
|
||||
|
||||
final expected = AlbumModel(
|
||||
artist: ARTIST_1,
|
||||
title: TITLE_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
);
|
||||
// act
|
||||
|
@ -126,7 +126,7 @@ void main() {
|
|||
|
||||
setUp(() {
|
||||
mockAlbumInfo = MockAlbumInfo();
|
||||
when(mockAlbumInfo.title).thenReturn(TITLE_1);
|
||||
when(mockAlbumInfo.title).thenReturn(ALBUM_TITLE_1);
|
||||
when(mockAlbumInfo.albumArt).thenReturn(ALBUM_ART_PATH_1);
|
||||
when(mockAlbumInfo.artist).thenReturn(ARTIST_1);
|
||||
when(mockAlbumInfo.firstYear).thenReturn(FIRST_YEAR_1.toString());
|
||||
|
@ -139,7 +139,7 @@ void main() {
|
|||
() async {
|
||||
// arrange
|
||||
final expected = AlbumModel(
|
||||
title: TITLE_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
artist: ARTIST_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
year: FIRST_YEAR_1,
|
||||
|
|
24
test/system/models/song_model_test.dart
Normal file
24
test/system/models/song_model_test.dart
Normal file
|
@ -0,0 +1,24 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mosh/domain/entities/song.dart';
|
||||
import 'package:mosh/system/models/song_model.dart';
|
||||
|
||||
import '../../test_constants.dart';
|
||||
|
||||
void main() {
|
||||
final tSongModel = SongModel(
|
||||
title: SONG_TITLE_3,
|
||||
album: ALBUM_TITLE_3,
|
||||
artist: ARTIST_3,
|
||||
path: PATH_3,
|
||||
trackNumber: TRACKNUMBER_3,
|
||||
albumArtPath: ALBUM_ART_PATH_3,
|
||||
);
|
||||
|
||||
test(
|
||||
'should be subclass of Album entity',
|
||||
() async {
|
||||
// assert
|
||||
expect(tSongModel, isA<Song>());
|
||||
},
|
||||
);
|
||||
}
|
|
@ -29,20 +29,7 @@ void main() {
|
|||
musicDataSource: mockMusicDataSource,
|
||||
);
|
||||
|
||||
tAlbumList = [
|
||||
AlbumModel(
|
||||
artist: ARTIST_1,
|
||||
title: TITLE_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
year: YEAR_1,
|
||||
),
|
||||
AlbumModel(
|
||||
artist: ARTIST_2,
|
||||
title: TITLE_2,
|
||||
albumArtPath: ALBUM_ART_PATH_2,
|
||||
year: YEAR_2,
|
||||
),
|
||||
];
|
||||
tAlbumList = setupAlbumList(tAlbumList);
|
||||
|
||||
tEmptyList = [];
|
||||
});
|
||||
|
@ -130,3 +117,18 @@ void main() {
|
|||
);
|
||||
});
|
||||
}
|
||||
|
||||
List<AlbumModel> setupAlbumList(List<AlbumModel> tAlbumList) => [
|
||||
AlbumModel(
|
||||
artist: ARTIST_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
year: YEAR_1,
|
||||
),
|
||||
AlbumModel(
|
||||
artist: ARTIST_2,
|
||||
title: ALBUM_TITLE_2,
|
||||
albumArtPath: ALBUM_ART_PATH_2,
|
||||
year: YEAR_2,
|
||||
),
|
||||
];
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
const String TITLE_1 = 'Back in Black';
|
||||
|
||||
// Albums
|
||||
const String ALBUM_TITLE_1 = 'Back in Black';
|
||||
const String ARTIST_1 = 'AC/DC';
|
||||
const String ALBUM_ART_PATH_1 = '/music/acdc/backinblack.jpg';
|
||||
const int YEAR_1 = 1980;
|
||||
|
@ -6,7 +8,23 @@ const int FIRST_YEAR_1 = 1979;
|
|||
const int LAST_YEAR_1 = 1980;
|
||||
const int NUM_SONGS_1 = 10;
|
||||
|
||||
const String TITLE_2 = 'Twilight Of The Thunder God';
|
||||
const String ALBUM_TITLE_2 = 'Twilight Of The Thunder God';
|
||||
const String ARTIST_2 = 'Amon Amarth';
|
||||
const String ALBUM_ART_PATH_2 = '/music/amon-amarth/twilight.jpg';
|
||||
const int YEAR_2 = 2008;
|
||||
const int YEAR_2 = 2008;
|
||||
|
||||
|
||||
// Songs
|
||||
const String SONG_TITLE_3 = 'Bottom Feeder';
|
||||
const String ALBUM_TITLE_3 = 'Ire';
|
||||
const String ARTIST_3 = 'Parkway Drive';
|
||||
const String PATH_3 = '/music/parkwaydrive/bottom_feeder.mp3';
|
||||
const String ALBUM_ART_PATH_3 = '/music/parkwaydrive/ire.jpg';
|
||||
const int TRACKNUMBER_3 = 7;
|
||||
|
||||
const String SONG_TITLE_4 = 'Black Flame';
|
||||
const String ALBUM_TITLE_4 = 'Black Flame';
|
||||
const String ARTIST_4 = 'Bury Tomorrow';
|
||||
const String PATH_4 = '/music/burytomorrow/blackflame.mp3';
|
||||
const String ALBUM_ART_PATH_4 = '/music/parkwaydrive/blackflame.jpg';
|
||||
const int TRACKNUMBER_4 = 3;
|
Loading…
Add table
Reference in a new issue