Skip to content

Commit

Permalink
Merge pull request #59 from UniBond-jijijin/feature/#12---sendLetter
Browse files Browse the repository at this point in the history
Feature/#12   send letter
  • Loading branch information
Jinyshin authored Jan 1, 2024
2 parents d1267ac + d4c77c9 commit 87fe40e
Show file tree
Hide file tree
Showing 15 changed files with 265 additions and 51 deletions.
Binary file added unibond/auth-jwt-0.0.1-SNAPSHOT.jar
Binary file not shown.
17 changes: 17 additions & 0 deletions unibond/lib/controller/dto/letter_req_dto.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class LetterReqDto {
String receiverId;
String content;
String title;

LetterReqDto({
required this.receiverId,
required this.title,
required this.content,
});

Map<String, dynamic> toJson() => {
'receiverId': receiverId,
'title': title,
'content': content,
};
}
24 changes: 24 additions & 0 deletions unibond/lib/controller/letter_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:get/get.dart';
import 'package:unibond/controller/dto/letter_req_dto.dart';
import 'package:unibond/domain/letter/letter.dart';
import 'package:unibond/domain/letter/letter_provider.dart';
import 'package:unibond/domain/letter/letter_repository.dart';

class LetterController extends GetxController {
final LetterRepository _letterRepository = LetterRepository();

Future<bool> sendLetter(
String receiverId,
String title,
String content,
) async {
try {
bool isSuccess =
await _letterRepository.sendLetter(receiverId, title, content);
return isSuccess;
} catch (error) {
print('sendLetter error: $error');
rethrow;
}
}
}
12 changes: 12 additions & 0 deletions unibond/lib/domain/letter/letter_provider.dart
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
import 'package:get/get.dart';
import 'package:unibond/controller/dto/letter_req_dto.dart';
import 'package:unibond/domain/letter/letter_provider.dart';
import 'package:unibond/util/userIdNum.dart';

const host = "http://3.35.110.214";

class LetterProvider extends GetConnect {
Future<Response> sendLetter(Map data) => post(
'$host/api/v1/letters',
headers: {"Authorization": "26"}, // 실제 userIdNum을 넣어야함
data);
}
30 changes: 30 additions & 0 deletions unibond/lib/domain/letter/letter_repository.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:get/get.dart';
import 'package:unibond/controller/dto/letter_req_dto.dart';
import 'package:unibond/domain/letter/letter_provider.dart';

const host = "http://3.35.110.214";

class LetterRepository {
final LetterProvider _letterProvider = LetterProvider();

Future<bool> sendLetter(
String receiverId, String title, String content) async {
try {
final LetterReqDto letterReqDto = LetterReqDto(
receiverId: receiverId,
title: title,
content: content,
);

print(letterReqDto.toJson());
Response response =
await _letterProvider.sendLetter(letterReqDto.toJson());

bool isSuccess = response.body["isSuccess"];
return isSuccess;
} catch (error) {
print("Failed: $error");
rethrow;
}
}
}
10 changes: 8 additions & 2 deletions unibond/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ void main() async {
runApp(const MaterialApp(
home: MyApp(),
));

}

class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return GetMaterialApp(
Expand All @@ -35,3 +34,10 @@ class MyApp extends StatelessWidget {
);
}
}

class InitialBinding extends Bindings {
@override
void dependencies() {
Get.put(LetterController()); // LetterController를 등록합니다.
}
}
Empty file added unibond/lib/util/userIdNum
Empty file.
96 changes: 53 additions & 43 deletions unibond/lib/view/screens/letter/letter_write_screen.dart
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:unibond/controller/dto/letter_req_dto.dart';
import 'package:unibond/controller/letter_controller.dart';
import 'package:unibond/util/validator_util.dart';
import 'package:unibond/view/screens/home_screen.dart';
import 'package:unibond/view/widgets/custon_elevated_button.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.dart';

class LetterWriteScreen extends StatefulWidget {
const LetterWriteScreen({super.key});

@override
_LetterWriteScreenState createState() => _LetterWriteScreenState();
}
class LetterWriteScreen extends StatelessWidget {
final _formKey = GlobalKey<FormState>();

class _LetterWriteScreenState extends State<LetterWriteScreen> {
final TextEditingController _titleController = TextEditingController();
final TextEditingController _contentController = TextEditingController();
final _titleController = TextEditingController();
final _contentController = TextEditingController();

@override
void dispose() {
_titleController.dispose();
_contentController.dispose();
super.dispose();
}
LetterWriteScreen({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
final l = Get.find<LetterController>();

return Scaffold(
appBar: AppBar(
centerTitle: true,
Expand All @@ -32,41 +30,53 @@ class _LetterWriteScreenState extends State<LetterWriteScreen> {
Get.back();
},
),
actions: [
IconButton(
icon: const Icon(Icons.send),
onPressed: () {
// 편지 전송하는 코드 추가
showToastMessage();
Get.back(); // 이전 화면 이동
},
)
],
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
TextField(
controller: _titleController,
decoration: const InputDecoration(
labelText: "제목",
border: OutlineInputBorder(),
),
),
const SizedBox(height: 16),
Expanded(
child: TextField(
controller: _contentController,
maxLines: null,
expands: true,
child: Form(
key: _formKey,
child: Column(
children: [
TextField(
controller: _titleController,
decoration: const InputDecoration(
hintText: "내용을 입력하세요...",
labelText: "제목",
border: OutlineInputBorder(),
),
),
),
],
const SizedBox(height: 16),
Expanded(
child: TextField(
controller: _contentController,
maxLines: null,
expands: true,
decoration: const InputDecoration(
hintText: "내용을 입력하세요...",
border: OutlineInputBorder(),
),
),
),
CustomElevatedButton(
text: "편지 전송",
screenRoute: () async {
if (isValid(_formKey)) {
var isSuccess = await l.sendLetter(
"30",
_titleController.text.trim(),
_contentController.text.trim(),
);
if (isSuccess == true) {
showToastMessage();
print('편지 전송 성공');
Get.off(() => const HomeScreen());
} else {
print('편지 전송 실패');
}
}
},
),
],
),
),
),
);
Expand Down
43 changes: 43 additions & 0 deletions unibond/lib/view/widgets/custom_letter_area.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'package:flutter/material.dart';

class CustomLetterArea extends StatelessWidget {
final String hint;
final TextEditingController controller;
final funvalidator;
final String? value;

const CustomLetterArea({
super.key,
required this.hint,
required this.controller,
required this.funvalidator,
this.value,
});

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 5.0),
child: TextFormField(
controller: controller,
maxLines: null,
expands: true,
decoration: InputDecoration(
hintText: "$hint을(를) 입력하세요",
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
),
focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
),
),
),
);
}
}
30 changes: 30 additions & 0 deletions unibond/lib/view/widgets/custom_letter_elevated_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:flutter/material.dart';

class CustomLetterElevatedButton extends StatelessWidget {
final String text;
final Future<void> Function() funPageRoute;

const CustomLetterElevatedButton({
Key? key,
required this.text,
required this.funPageRoute,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return ElevatedButton(
style: ElevatedButton.styleFrom(
minimumSize: const Size(double.infinity, 50),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
backgroundColor: Colors.blue,
foregroundColor: Colors.white,
),
onPressed: () async {
await funPageRoute();
},
child: Text("$text"),
);
}
}
44 changes: 44 additions & 0 deletions unibond/lib/view/widgets/custom_letter_form_field.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import 'package:flutter/material.dart';

class CustomLetterFormField extends StatelessWidget {
final String hint;
final TextEditingController controller;
final funvalidator;
final String? value;

const CustomLetterFormField({
super.key,
required this.hint,
required this.controller,
required this.funvalidator,
this.value,
required InputDecoration decoration,
});

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 5.0),
child: TextFormField(
validator: funvalidator,
controller: controller,
decoration: InputDecoration(
// ignore: unnecessary_string_interpolations
hintText: hint == "이메일" ? "$hint을 입력하세요" : "$hint를 입력하세요",
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
),
focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
),
),
),
);
}
}
4 changes: 2 additions & 2 deletions unibond/lib/view/widgets/custom_text_form_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class CustomTextFormField extends StatelessWidget {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 5.0),
child: TextFormField(
controller: controller,
initialValue: value,
// controller: controller,
// initialValue: value,
validator: funvalidator,
obscureText: hint == "비밀번호" ? true : false,
style: const TextStyle(fontSize: 14),
Expand Down
2 changes: 0 additions & 2 deletions unibond/lib/view/widgets/custon_elevated_button.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore_for_file: unnecessary_string_interpolations

import 'package:flutter/material.dart';

class CustomElevatedButton extends StatelessWidget {
Expand Down
2 changes: 1 addition & 1 deletion unibond/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1048,4 +1048,4 @@ sdks:
version: "13.0.0"
sdks:
dart: ">=3.2.0-0 <4.0.0"
flutter: ">=1.10.0"
flutter: ">=1.10.0"
2 changes: 1 addition & 1 deletion unibond/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'package:unibond/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());
await tester.pumpWidget(MyApp());

// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
Expand Down

0 comments on commit 87fe40e

Please sign in to comment.