Skip to content

Commit

Permalink
#59 서버 연결 중
Browse files Browse the repository at this point in the history
  • Loading branch information
ZombieBread123 committed May 10, 2024
1 parent 953132c commit a339aca
Show file tree
Hide file tree
Showing 15 changed files with 446 additions and 288 deletions.
3 changes: 2 additions & 1 deletion frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,5 @@ fabric.properties
!/gradle/wrapper/gradle-wrapper.jar

#select file
lib/secret.dart
lib/secret.dart
android\app\google-service.json
1 change: 1 addition & 0 deletions frontend/android/app/google-service.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"installed":{"client_id":"801277628829-qba15ch2hanumq1v4hpe94c7rmt6k8ch.apps.googleusercontent.com","project_id":"bookmeeting-422618","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs"}}
1 change: 1 addition & 0 deletions frontend/devtools_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extensions:
79 changes: 78 additions & 1 deletion frontend/lib/http.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Future<dynamic> login(String email) async {

//유저 정보 가져오기
Future<dynamic> getUserInfo(String id, String token) async {
var address = Uri.parse(BASE_URL + "/member/$id");
var address = Uri.parse("$BASE_URL/member/$id");
http.Response res = await http.get(
address,
headers: {
Expand Down Expand Up @@ -212,3 +212,80 @@ Future<List<dynamic>> contentLoad(dynamic token, int id) async {
}
return contentList;
}

// 모임 가입하기
Future<String> groupJoin(String token, int clubId) async {
var address = Uri.parse(BASE_URL + "/club/join?clubId=$clubId");
http.Response res = await http.get(
address,
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer $token",
},
);
final data = res.body;

return data;
}

//모임 나가기
Future<String> groupOut(String token, int clubId) async {
var address = Uri.parse(BASE_URL + "/club/out?clubId=$clubId");
http.Response res = await http.get(
address,
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer $token",
},
);
final data = res.body;

return data;
}

//서재 불러오기
Future<List<dynamic>> getLibrary(String token) async {
List<dynamic> libraryList = [];
var address = Uri.parse("$BASE_URL/library");
http.Response res = await http.get(
address,
headers: {
"Content-Type": "application/json",
"Authorization": 'Bearer $token',
},
);
final data = json.decode(utf8.decode(res.bodyBytes));
for (int i = 0; i < data.length; i++) {
libraryList.add(data[i]);
}
return libraryList;
}

//서재에 책 추가하기
Future<String> addBookToLibrary(
String token,
String isbn,
String title,
String author,
String publisher,
String publishDate,
String imageUrl) async {
var address = Uri.parse("$BASE_URL/library/add");
http.Response res = await http.post(
address,
headers: {
"Content-Type": "application/json",
"Authorization": 'Bearer $token',
},
body: json.encode({
"isbn": isbn,
"title": title,
"author": author,
"publisher": publisher,
"publishDate": publishDate,
"imageUrl": imageUrl,
}),
);
final data = res.body;
return data;
}
2 changes: 1 addition & 1 deletion frontend/lib/provider/secure_storage_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SecureStorageService extends ChangeNotifier {
class SecureStorageProvider extends StatelessWidget {
final Widget child;

const SecureStorageProvider({required this.child});
const SecureStorageProvider({super.key, required this.child});

@override
Widget build(BuildContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class _BookReportState extends State<BookReportScreen> {
color: Colors.white,
fontFamily: 'Noto Sans KR',
fontWeight: FontWeight.w700,
fontSize: 20,
),
backgroundColor: const Color(0xFF0E9913),
centerTitle: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class BookReportTemplateScreen extends StatelessWidget {
color: Colors.white,
fontFamily: 'Noto Sans KR',
fontWeight: FontWeight.w700,
fontSize: 20,
),
backgroundColor: const Color(0xFF0E9913),
centerTitle: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:frontend/http.dart';
import 'package:frontend/screens/home/search/search_screen.dart';
import 'package:frontend/provider/secure_storage_provider.dart';
import 'package:provider/provider.dart';

class BookReportViewingScreen extends StatefulWidget {
const BookReportViewingScreen({super.key});
Expand All @@ -19,9 +20,11 @@ class _BookReportViewingState extends State<BookReportViewingScreen> {
String _body = '';
final String _author = "작가";
final String _publisher = "출판사";
// ignore: prefer_typing_uninitialized_variables
var token;

void initializeContentData(dynamic token) async {
_contentData = await contentLoad(token[0], 1);
_contentData = await contentLoad(token, 2);
_template = _contentData[0]['type'] as String;
_title = _contentData[0]['title'] as String;
_body = _contentData[0]['body'] as String;
Expand All @@ -30,9 +33,16 @@ class _BookReportViewingState extends State<BookReportViewingScreen> {
@override
void initState() {
super.initState();
_initUserState();
initializeContentData(token);
}

Future<void> _initUserState() async {
final secureStorage =
Provider.of<SecureStorageService>(context, listen: false);
token = await secureStorage.readData("token");
}

@override
void dispose() {
super.dispose();
Expand All @@ -47,6 +57,7 @@ class _BookReportViewingState extends State<BookReportViewingScreen> {
color: Colors.white,
fontFamily: 'Noto Sans KR',
fontWeight: FontWeight.w700,
fontSize: 20,
),
backgroundColor: const Color(0xFF0E9913),
centerTitle: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:frontend/http.dart';
import 'package:frontend/provider/bookinfo_provider.dart';
import 'package:frontend/screens/home/search/search_screen.dart';
import 'package:frontend/provider/secure_storage_provider.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';

class BookReportWritingScreen extends StatefulWidget {
Expand Down Expand Up @@ -36,6 +38,7 @@ class _BookReportWritingState extends State<BookReportWritingScreen> {
final TextEditingController _answerController2 = TextEditingController();
final TextEditingController _answerController3 = TextEditingController();
final TextEditingController _answerController4 = TextEditingController();
var token;

// Predefined values for author and publisher
final String _author = "작가";
Expand All @@ -48,6 +51,7 @@ class _BookReportWritingState extends State<BookReportWritingScreen> {
void initState() {
super.initState();

_initUserState();
// Initialize _keyboardVisibilityObserver and _keyboardVisibilityObserverWrapper
final keyboardVisibilityObserver =
_KeyboardVisibilityObserver((bool visible) {
Expand All @@ -66,6 +70,12 @@ class _BookReportWritingState extends State<BookReportWritingScreen> {
WidgetsBinding.instance.addObserver(_keyboardVisibilityObserverWrapper);
}

Future<void> _initUserState() async {
final secureStorage =
Provider.of<SecureStorageService>(context, listen: false);
token = await secureStorage.readData("token");
}

@override
void dispose() {
// Remove the keyboard visibility listener
Expand Down Expand Up @@ -106,6 +116,7 @@ class _BookReportWritingState extends State<BookReportWritingScreen> {
color: Colors.white,
fontFamily: 'Noto Sans KR',
fontWeight: FontWeight.w700,
fontSize: 20,
),
backgroundColor: const Color(0xFF0E9913),
centerTitle: true,
Expand Down Expand Up @@ -305,8 +316,16 @@ class _BookReportWritingState extends State<BookReportWritingScreen> {
child: ElevatedButton(
onPressed: () {
// 글 저장 기능 추가
contentCreate(token[0], 1, 3, '독후감', '제목', '내용', '2021-10-10',
'2021-10-10');
contentCreate(
token,
1,
3,
_template,
_bookTitleController.text,
_writingController.text,
_startDate.toString(),
_endDate.toString());
context.pop();
},
child: const Text('저장'),
),
Expand Down
52 changes: 51 additions & 1 deletion frontend/lib/screens/home/mypage/makelibrary_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:go_router/go_router.dart';

class MakeLibraryScreen extends StatefulWidget {
const MakeLibraryScreen({super.key});
Expand All @@ -10,13 +11,22 @@ class MakeLibraryScreen extends StatefulWidget {
}

class _MakeLibraryScreenState extends State<MakeLibraryScreen> {
String _appBarTitle = '서재 이름';

@override
Widget build(BuildContext context) {
return ScreenUtilInit(
designSize: const Size(390, 675),
builder: (context, _) => Scaffold(
appBar: AppBar(
title: const Text('서재 이름'),
leading: IconButton(
icon: const Icon(Icons.arrow_back),
color: Colors.white,
onPressed: () {
context.pop();
},
),
title: Text(_appBarTitle),
titleTextStyle: const TextStyle(
color: Colors.white,
fontFamily: 'Noto Sans KR',
Expand All @@ -25,6 +35,46 @@ class _MakeLibraryScreenState extends State<MakeLibraryScreen> {
),
backgroundColor: const Color(0xFF0E9913),
centerTitle: true,
actions: [
IconButton(
icon: const Icon(Icons.more_vert),
color: Colors.white,
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
String newName = '';
return AlertDialog(
title: const Text("서재 이름 입력"),
content: TextField(
onChanged: (value) {
newName = value;
},
decoration: const InputDecoration(hintText: "새로운 서재"),
),
actions: [
TextButton(
onPressed: () {
setState(() {
_appBarTitle = newName;
});
Navigator.of(context).pop();
},
child: const Text("확인"),
),
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text("취소"),
),
],
);
},
);
},
),
],
),
body: Column(
children: [
Expand Down
Loading

0 comments on commit a339aca

Please sign in to comment.