Skip to content

Commit

Permalink
Merge pull request #5 from Riviu-Buku/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
syazantri authored Dec 18, 2023
2 parents 54b21a0 + 7b7ceb7 commit bcabf24
Show file tree
Hide file tree
Showing 26 changed files with 1,022 additions and 388 deletions.
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<br />
<div align="center">
<a href="http://samuel-taniel-tutorial.pbp.cs.ui.ac.id">
<a href="https://install.appcenter.ms/orgs/riviu-buku/apps/riviu-buku/distribution_groups/public">
<img src="https://github.com/Riviu-Buku/riviu-buku/blob/main/logo.png" alt="Logo Riviu Buku" width="80" height="80">
</a>

Expand All @@ -11,14 +11,23 @@
<p align="center">
Riviu Buku: Ulas Buku Untukmu
<br />
<a href="https://github.com/Riviu-Buku/riviu-buku"><strong>Explore the code »</strong> </a>
<a href="https://github.com/Riviu-Buku/riviu-buku-mobile"><strong>Explore the code »</strong> </a>
<br />
<br />
<a href="http://samuel-taniel-tutorial.pbp.cs.ui.ac.id">View Site</a>
<a href="https://install.appcenter.ms/orgs/riviu-buku/apps/riviu-buku/distribution_groups/public">View Download App Site</a>
·
<a href="https://pbp-fasilkom-ui.github.io/ganjil-2024/assignments/group/midterm"> View Assignment </a>
<a href="https://pbp-fasilkom-ui.github.io/ganjil-2024/assignments/group/final"> View Assignment </a>
</p>
</div>
<div align="center">
<a href="https://appcenter.ms">
<img src="https://build.appcenter.ms/v0.1/apps/b32cb2cf-819c-443f-8eb0-a6f631f9027f/branches/main/badge" alt="Build status" />
</a>
&nbsp; | &nbsp;
<a href="https://install.appcenter.ms/orgs/riviu-buku/apps/riviu-buku/distribution_groups/public"> Download App</a>
<br />
<br />
</div>

<details>
<summary>Daftar Pustaka</summary>
Expand Down Expand Up @@ -68,7 +77,7 @@ Terima kasih telah membaca cerita Riviu Buku, selamat membaca dan mereview!😇

## 📃 Daftar Modul Yang Akan Diimplementasikan 📃

- 📕 Modul untuk me-review buku yang oleh pengguna yang disertai oleh leaderboard berdasarkan review terbaik menggunakan fitur upvote dan downvote; dikerjakan oleh Samuel Taniel Mulyadi;</p>
- 📕 Modul untuk me-review buku yang oleh pengguna yang disertai oleh like buku, add, dan delete review yang dibuat pengguna; dikerjakan oleh Samuel Taniel Mulyadi;</p>
- 📕 Modul koleksi, kategori, dan favorit yang memungkinkan pengguna untuk menyimpan daftar buku favorit dan fungsi untuk menambahkan buku ke album/wishlist pengguna serta upload buku untuk bisa di review; dikerjakan oleh Ken Balya</p>
- 📕 Modul homepage yang menyajikan rekomendasi berdasarkan jumlah likes pada suatu kategori buku oleh pengguna; dikerjakan oleh Khansa Mahira</p>
- 📕 Modul profile yang bisa melihat koleksi buku favorit dan mengedit detail profile; dikerjakan oleh Syazantri Salsabila</p>
Expand Down
41 changes: 35 additions & 6 deletions album/lib/albumpage.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import 'package:flutter/material.dart';
import 'package:riviu_buku/models/album.dart';
import 'package:riviu_buku/models/book.dart';
import 'package:riviu_buku/models/user.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:review/reviewpage.dart';
import 'package:album/editalbum.dart';

class AlbumDetailsPage extends StatefulWidget {
final Album album;

AlbumDetailsPage({Key? key, required this.album}) : super(key: key);
final User user;
AlbumDetailsPage({Key? key, required this.user, required this.album}) : super(key: key);

@override
_AlbumDetailsPageState createState() => _AlbumDetailsPageState();
Expand All @@ -32,13 +35,32 @@ class _AlbumDetailsPageState extends State<AlbumDetailsPage> {
return list_book;
}


bool canEditAlbum() {
// Check if the current user is the one who made the album
print(widget.album.fields.user + widget.user.id);
return widget.album.fields.user == widget.user.id;
}

@override
Widget build(BuildContext context) {
User user = widget.user;
return Scaffold(
appBar: AppBar(
title: Text(widget.album.fields.name),
actions: [
if (canEditAlbum())
IconButton(
icon: Icon(Icons.edit),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => EditAlbumPage(user: widget.user, album: widget.album),
),
);
},
),
],
),
body: FutureBuilder(
future: fetchBooksForAlbum(widget.album),
Expand Down Expand Up @@ -66,9 +88,16 @@ class _AlbumDetailsPageState extends State<AlbumDetailsPage> {
),
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
onTap: () {
// TODO: Implement your functionality here
print('Book clicked');
onTap: () {Navigator.push(
context,
MaterialPageRoute(
builder: (context){
return ReviewPage(
book: snapshot.data![index], user: user,
);
}
),
);
},
child: Card(
child: Column(
Expand Down
6 changes: 3 additions & 3 deletions album/lib/albumspage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class _AlbumsPageState extends State<AlbumsPage> {
}


void viewAlbum(Album album) {
void viewAlbum(Album album, User user) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => AlbumDetailsPage(album: album)),
MaterialPageRoute(builder: (context) => AlbumDetailsPage(album: album, user: user)),
);
}

Expand Down Expand Up @@ -106,7 +106,7 @@ class _AlbumsPageState extends State<AlbumsPage> {
TextStyle(color: Colors.white)),
ElevatedButton(
onPressed: () =>
viewAlbum(snapshot.data![index]),
viewAlbum(snapshot.data![index], user),
child: Text('View Album'),
),
],
Expand Down
35 changes: 22 additions & 13 deletions album/lib/createalbum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'package:riviu_buku/models/user.dart';
import 'package:album/albumspage.dart';
import 'package:review/reviewpage.dart';

import 'albumpage.dart';

class CreateAlbumPage extends StatefulWidget {
final User user;
CreateAlbumPage({Key? key, required this.user}) : super(key: key);
Expand Down Expand Up @@ -41,7 +43,6 @@ class _CreateAlbumPageState extends State<CreateAlbumPage> {
}
}


Widget buildSelectedBooks() {
return GridView.builder(
itemCount: _selectedBooks.length,
Expand Down Expand Up @@ -91,8 +92,8 @@ class _CreateAlbumPageState extends State<CreateAlbumPage> {
);
}

Future<void> createAlbum() async {
var url = Uri.parse('http://127.0.0.1:8000/album/create-album-flutter/'); // replace with your Django server URL
Future<album.Album> createAlbum() async {
var url = Uri.parse('http://127.0.0.1:8000/album/create-album-flutter/');

var response = await http.post(
url,
Expand All @@ -101,19 +102,26 @@ class _CreateAlbumPageState extends State<CreateAlbumPage> {
'name': _nameController.text,
'description': _descriptionController.text,
'books': _selectedBooks,
'user': widget.user.username
'user': widget.user.username,
}),
);

if (response.statusCode == 200) {
// If the server returns a 200 OK response, then the album was created successfully.
if (response.statusCode == 201) {
// If the server returns a 201 Created response, the album was created successfully.
print('Album created successfully');

// Parse the JSON response and return the Album object
Map<String, dynamic> jsonResponse = json.decode(response.body);
return album.Album.fromJson(jsonResponse['album']);
} else {
// If the server returns an error response, then the album was not created.
print('Failed to create album');
// If the server returns an error response, print the error message and return null.
print('Failed to create album: ${response.statusCode}');
return album.Album(model: '', pk: 0, fields: album.Fields(name: '', slug: '', user: 0, description: '', coverImage: '', books: []));
}
}



@override
Widget build(BuildContext context) {
User user = widget.user;
Expand Down Expand Up @@ -151,7 +159,8 @@ class _CreateAlbumPageState extends State<CreateAlbumPage> {
hintText: 'Search for books',
),
onChanged: (value) {
// TODO: Implement search functionality
// Call fetchBooks when the search query changes
setState(() {});
},
),
SizedBox(height: 16.0),
Expand Down Expand Up @@ -229,12 +238,12 @@ class _CreateAlbumPageState extends State<CreateAlbumPage> {
child: buildSelectedBooks(),
),
ElevatedButton(
onPressed: () {
onPressed: () async {
// TODO: Implement create album functionality
createAlbum();
album.Album createdAlbum = await createAlbum();
Navigator.push(
context,
MaterialPageRoute(builder: (context) => AlbumsPage(user: user)),
MaterialPageRoute(builder: (context) => AlbumDetailsPage(album: createdAlbum, user: user)),
);
},
child: Text('Create'),
Expand All @@ -245,4 +254,4 @@ class _CreateAlbumPageState extends State<CreateAlbumPage> {
),
);
}
}
}
Loading

0 comments on commit bcabf24

Please sign in to comment.