Skip to content

Commit

Permalink
Add get followed aritst by user #113
Browse files Browse the repository at this point in the history
  • Loading branch information
up2code committed Mar 5, 2021
1 parent d8542f5 commit 6389db1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
6 changes: 6 additions & 0 deletions lib/src/controllers/artist_detail_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ArtistDetailController extends GetxController {
@override
void onInit() {
initArgs();
checkFollowArtistStatus();
fetchApis();
super.onInit();
}
Expand All @@ -49,6 +50,11 @@ class ArtistDetailController extends GetxController {
return;
}
//TODO: Wait for API backend implementation

userRepository.getCurrentUserFollowedArtist(artist().id).then((artist) {
return (artist == null || artist.id == null) ? liked(false) : liked(true);
}).then((artist) => debounce(liked, (_) => updateFollowArtist(),
time: Duration(seconds: 1)));
}

updateFollowArtist() {
Expand Down
15 changes: 9 additions & 6 deletions lib/src/pages/artist_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,15 @@ class ArtistDetailPageView extends StatelessWidget {

List<Widget> buttons = [];

buttons.add(ActiveFlatButton(
icon: Icon(Icons.favorite),
label: 'like'.tr,
active: controller.liked.value,
onPressed:
(authService.currentUser().id == null) ? null : this._onTapLikeButton,
buttons.add(Obx(
() => ActiveFlatButton(
icon: Icon(Icons.favorite),
label: 'like'.tr,
active: controller.liked.value,
onPressed: (authService.currentUser().id == null)
? null
: this._onTapLikeButton,
),
));

buttons.add(FlatButton(
Expand Down
9 changes: 9 additions & 0 deletions lib/src/repositories/user_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,13 @@ class UserRepository extends RestApiRepository {
.get('/api/users/current/ratedSongs/$songId', null)
.then((v) => v as String);
}

/// Gets currently logged in user's rating for a artist
Future<ArtistModel> getCurrentUserFollowedArtist(int artistId) {
return httpService
.get('/api/users/current/followedArtists/$artistId', null)
.then((v) => (v == null || v['artist'] == null)
? null
: ArtistModel.fromJson(v['artist']));
}
}

0 comments on commit 6389db1

Please sign in to comment.