Skip to content

Commit

Permalink
#59 백엔드 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
ZombieBread123 committed May 21, 2024
1 parent 206c165 commit ce75ad6
Show file tree
Hide file tree
Showing 15 changed files with 1,346 additions and 948 deletions.
5 changes: 5 additions & 0 deletions frontend/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cSpell.words": [
"searchutil"
]
}
7 changes: 4 additions & 3 deletions frontend/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Sun May 19 20:56:07 KST 2024
networkTimeout=10000
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
40 changes: 37 additions & 3 deletions frontend/lib/http.dart
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ Future<dynamic> quizCreate(
"endDate": endDate,
}),
);
final data = res.body;
//final data = res.body;
final data = json.decode(utf8.decode(res.bodyBytes));
print(data);
return data;
}
Expand Down Expand Up @@ -594,6 +595,7 @@ Future<List<dynamic>> getLibrary(String token) async {
);
final data = json.decode(utf8.decode(res.bodyBytes));
for (int i = 0; i < data.length; i++) {
print(data[i]);
libraryList.add(data[i]);
}
return libraryList;
Expand All @@ -608,8 +610,9 @@ Future<String> addBookToLibrary(
String author,
String publisher,
String publishDate,
String imageUrl) async {
var address = Uri.parse("$BASE_URL/member/my-book/add");
String imageUrl,
String groupName) async {
var address = Uri.parse("$BASE_URL/member/my-book/add?groupName=$groupName");
http.Response res = await http.post(
address,
headers: {
Expand Down Expand Up @@ -646,3 +649,34 @@ Future<String> addBooksToLibrary(
print(data);
return data;
}

//서재 삭제하기
Future<String> deleteLibrary(String token, String groupName) async {
var address =
Uri.parse("$BASE_URL/member/my-book/rm/group?groupName=$groupName");
http.Response res = await http.delete(
address,
headers: {
"Content-Type": "application/json",
"Authorization": 'Bearer $token',
},
);
final data = res.body;
return data;
}

//서재에서 책 삭제하기
Future<String> deleteBookFromLibrary(
String token, String groupName, String isbn) async {
var address = Uri.parse(
"$BASE_URL/member/my-book/rm/book?groupName=$groupName&isbn=$isbn");
http.Response res = await http.delete(
address,
headers: {
"Content-Type": "application/json",
"Authorization": 'Bearer $token',
},
);
final data = res.body;
return data;
}
72 changes: 37 additions & 35 deletions frontend/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:frontend/provider/bookinfo_provider.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:frontend/provider/secure_storage_provider.dart';
import 'package:frontend/screens/book/book_content_screen.dart';
import 'package:frontend/screens/book/book_info_screen.dart';
Expand Down Expand Up @@ -260,42 +260,44 @@ class App extends StatelessWidget {

@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => BookInfoProvider()),
ChangeNotifierProvider(create: (_) => SecureStorageService()),
// 다른 프로바이더도 여기에 추가
],
child: MaterialApp.router(
routerConfig: router,
theme: ThemeData(
fontFamily: 'pretendard',
colorScheme: ColorScheme.fromSwatch(
backgroundColor: Colors.white,
primarySwatch: Colors.green,
accentColor: const Color(0xFF09BB10),
),
textTheme: const TextTheme(
headlineLarge: TextStyle(
fontFamily: 'pretendard',
fontSize: 20,
fontWeight: FontWeight.w200,
return ScreenUtilInit(
designSize: const Size(390, 675),
builder: (context, _) => MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => SecureStorageService()),
// 다른 프로바이더도 여기에 추가
],
child: MaterialApp.router(
routerConfig: router,
theme: ThemeData(
fontFamily: 'pretendard',
colorScheme: ColorScheme.fromSwatch(
backgroundColor: Colors.white,
primarySwatch: Colors.green,
accentColor: const Color(0xFF09BB10),
),
titleLarge: TextStyle(
fontFamily: 'pretendard',
fontSize: 20,
fontWeight: FontWeight.w700),
titleMedium: TextStyle(
textTheme: TextTheme(
headlineLarge: TextStyle(
fontFamily: 'pretendard',
fontSize: 20,
fontWeight: FontWeight.w500),
bodyLarge: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w700,
),
bodyMedium: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
fontSize: 20.sp,
fontWeight: FontWeight.w200,
),
titleLarge: TextStyle(
fontFamily: 'pretendard',
fontSize: 20.sp,
fontWeight: FontWeight.w700),
titleMedium: TextStyle(
fontFamily: 'pretendard',
fontSize: 20.sp,
fontWeight: FontWeight.w500),
bodyLarge: TextStyle(
fontSize: 20.sp,
fontWeight: FontWeight.w700,
),
bodyMedium: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w500,
),
),
),
),
Expand Down
78 changes: 0 additions & 78 deletions frontend/lib/provider/bookinfo_provider.dart

This file was deleted.

89 changes: 89 additions & 0 deletions frontend/lib/provider/secure_storage_provider.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:provider/provider.dart';

class SecureStorageService extends ChangeNotifier {
final FlutterSecureStorage _secureStorage = FlutterSecureStorage();
static const _storage = FlutterSecureStorage();

Future<void> saveData(String key, String value) async {
await _secureStorage.write(key: key, value: value);
Expand Down Expand Up @@ -42,3 +45,89 @@ class SecureStorageProvider extends StatelessWidget {
return context.read<SecureStorageService>();
}
}

class SecureStorageUtil {
static const _storage = FlutterSecureStorage();

static Future<void> addBook(TmpBook newBook) async {
List<TmpBook> currentBooks = await loadBooks();
currentBooks.add(newBook);
await saveBooks(currentBooks);
}

static Future<void> saveBooks(List<TmpBook> books) async {
String jsonString = jsonEncode(books.map((book) => book.toJson()).toList());
await _storage.write(key: 'books', value: jsonString);
}

static Future<List<TmpBook>> loadBooks() async {
String? jsonString = await _storage.read(key: 'books');
if (jsonString == null) {
return [];
}
List<dynamic> jsonList = jsonDecode(jsonString);
return jsonList.map((json) => TmpBook.fromJson(json)).toList();
}

static Future<void> deleteBook(int index) async {
List<TmpBook> currentBooks = await loadBooks();
currentBooks.removeAt(index);
await saveBooks(currentBooks);
}

static Future<void> deleteAllBooks() async {
await _storage.delete(key: 'books');
}
}

class TmpBook {
String title;
String imageUrl;
DateTime startDate;
DateTime endDate;
String template;
String booktitle;
String author;
String publisher;
String writing;

TmpBook({
required this.title,
required this.imageUrl,
required this.startDate,
required this.endDate,
required this.template,
required this.booktitle,
required this.author,
required this.publisher,
required this.writing,
});

factory TmpBook.fromJson(Map<String, dynamic> json) {
return TmpBook(
title: json['title'],
imageUrl: json['imageUrl'],
startDate: DateTime.parse(json['startDate']),
endDate: DateTime.parse(json['endDate']),
template: json['template'],
booktitle: json['booktitle'],
author: json['author'],
publisher: json['publisher'],
writing: json['writing'],
);
}

Map<String, dynamic> toJson() {
return {
'title': title,
'imageUrl': imageUrl,
'startDate': startDate.toIso8601String(),
'endDate': endDate.toIso8601String(),
'template': template,
'booktitle': booktitle,
'author': author,
'publisher': publisher,
'writing': writing,
};
}
}
Loading

0 comments on commit ce75ad6

Please sign in to comment.