Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#12 send letter #59

Merged
merged 4 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
int? receiverId;
String content;
String title;

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

Map<String, dynamic> toJson() => {
'receiverId': receiverId,
'content': content,
'title': title,
};
}
21 changes: 21 additions & 0 deletions unibond/lib/controller/letter_controller.dart
Copy link
Member Author

@codeJiwon codeJiwon Dec 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
μ½˜μ†”μ°½μ— μ΄λ ‡κ²Œ 찍히고 있음
NoSuchMethodError: '[]'에 λŒ€ν•΄ κ²€μƒ‰ν•΄λ΄€λ”λ‹ˆ μ „λ‹¬λ˜λŠ” 값에 null값이 μžˆλŠ” κ²½μš°λ‚˜ κ΄€λ ¨ ν•¨μˆ˜κ°€ μ •μ˜λ˜μ–΄ μžˆμ§€ μ•Šμ„ λ•Œ μƒκΈ°λŠ” 였λ₯˜λΌκ³  함.
<의문1> receiverIdλ₯Ό '2'둜 μž„μ˜λ‘œ μ„€μ •ν–ˆλŠ”λ° κ·Έκ²ƒμœΌλ‘œ 인해 생긴 였λ₯˜μΌκΉŒ? Receiver: null이 error 메세지인 것 같은데 ν˜Ήμ‹œ 이게 λ¬Έμ œμ΄λ €λ‚˜

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

일단 μ΄κ²ƒλ§Œ λ³΄κ³ λŠ” μ–΄λ–€ μ½”λ“œλ‘œμΈν•΄μ„œ λ‚˜μ˜¨ 결괏값인지 μ•Œμˆ˜κ°€μ—†μœΌλ‹ˆκΉŒ μ•žμœΌλ‘œλŠ” μ½”λ“œ μžμ²΄μ— μ½”λ©˜νŠΈ 뢀탁해.....제봘.. μ–΄λ–€κ±Έ printν–ˆμ„λ•Œ null인지에 따라 해결방법이 μ²œμ°¨λ§Œλ³„μΌν…Œλ‹ˆκΉŒ...!

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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(int receiverId, String content, String title) async {
try {
bool isSuccess =
await _letterRepository.sendLetter(receiverId, content, title);
print('sendLetter result: $isSuccess');
return isSuccess;
} catch (error) {
print('sendLetter error: $error');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런 μ‹μœΌλ‘œ..

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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그리고 λ§Œμ•½μ— 이뢀뢄을 λ§ν•˜λŠ”κ±°λΌλ©΄
letterReqDto.toJson()을 λ³΄λƒˆμž–μ•„..근데 μ € κ°’μ˜ μžλ£Œν˜•μ„ Map<String, dynamic> μ΄λ ‡κ²Œ 정해놓고 λ³΄λƒˆλŠ”λ° 이뢀뢄을 μ™œ λ°”κΏ”μ•Ό ν•œλ‹€κ³  μƒκ°ν•œκ±΄μ§€ λͺ¨λ₯΄κ²Ÿμ–΄.
μ•žμœΌλ‘œλŠ” κΌ­. κ·Έ 생각/의문점의 μ΄μœ λ„ ν¬ν•¨ν•΄μ„œ λ‚¨κ²¨μ€˜.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ–΄ μ—¬κΈ° λ°”κΏ”μ•Ό ν•˜λŠ”μ§€λ₯Ό λ¬Όμ–΄λ³Έκ±° λ§žλŠ”λ° λ‹Ήμ‹œ μ—λŸ¬λœ¨λŠ”κ²Œ μ „λ‹¬λ˜λŠ” κ°’ 쀑에 null이 μžˆλ‹€κ³  ν•΄μ„œ Map에 데이터듀이 μ•ˆ λ‹΄κ²¨μ„œ κ·ΈλŸ°κ°€ κ³ λ―Όν–ˆμ—ˆμ–΄.

'$host/api/v1/letters',
headers: {"Authorization": userIdNum ?? ""},
data);
}
32 changes: 32 additions & 0 deletions unibond/lib/domain/letter/letter_repository.dart
Copy link
Member Author

@codeJiwon codeJiwon Dec 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ½˜μ†”μ°½ κ²°κ³Όλ₯Ό 보면 μ—¬κΈ°μ„œλΆ€ν„° catch문에 빠지고 있음. μ—¬κΈ°μ„œλΆ€ν„° 해결해야함.
<의문2> sendLetter μ•ˆμ— Map λŒ€μ‹  int receiverId, String content, String title을 λ„£μ–΄μ•Όν• κΉŒ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

의문 2 처럼 μ˜λ¬Έμ μ„ μ“°λ €λ©΄ κ·Έλ ‡κ²Œ μƒκ°ν•˜λŠ” μ΄μœ λ„ 제발 ν¬ν•¨ν•΄μ„œ 써쀘....
그리고 μ΄λ˜ν•œ μ–΄λ””μ˜ Map을 λ§ν•˜λŠ”κ±΄μ§€, μ–΄λ–€ νŒŒμΌμ— μžˆλŠ” sendLetterν•¨μˆ˜λ₯Όλ§ν•˜λŠ”건지(repository, provider 파일 등등에 λ‹€ μ € ν•¨μˆ˜κ°€ μ •μ˜λΌμžˆμž–μ•„) λ‚΄κ°€ 직접 μœ μΆ”λ₯Ό ν•΄μ•Όν•˜λŠ”λ°..... μ •ν™•ν•œ μ½”λ“œμ— μ½”λ©˜νŠΈ λ‹¬μ•„μ€˜.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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(int receiverId, String content, String title) async {
try {
final LetterReqDto letterReqDto = LetterReqDto(
receiverId: receiverId,
content: content,
title: title,
);
Response response =
await _letterProvider.sendLetter(letterReqDto.toJson());

print(response.body);
print(response.body["isSuccess"]);

bool isSuccess = response.body["isSuccess"];
print("전솑 성곡 μ—¬λΆ€: $isSuccess");
return isSuccess;
} catch (error) {
print("Failed");
print(error);
throw error;
}
}
}
28 changes: 13 additions & 15 deletions unibond/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:unibond/view/screens/community/post_detail_screen.dart';
import 'package:unibond/view/screens/user/login_screen.dart';
import 'package:unibond/controller/letter_controller.dart'; // LetterControllerλ₯Ό κ°€μ Έμ˜΅λ‹ˆλ‹€.
import 'package:unibond/view/screens/letter/letter_write_screen.dart';

void main() {
runApp(const MaterialApp(
home: MyApp(),
));
runApp(MyApp());
}

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

@override
Widget build(BuildContext context) {
return GetMaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blueAccent),
useMaterial3: true,
),
home: DetailScreen(
id: 0,
), // μž„μ‹œ μŠ€ν”Œλž˜μ‹œν™”λ©΄
title: 'Your App Title',
home: LetterWriteScreen(), // μ•±μ˜ 초기 화면을 μ„€μ •ν•©λ‹ˆλ‹€.
initialBinding: InitialBinding(), // μ—¬κΈ°μ—μ„œ LetterControllerλ₯Ό μ΄ˆκΈ°ν™”ν•©λ‹ˆλ‹€.
);
}
}

class InitialBinding extends Bindings {
@override
void dependencies() {
Get.put(LetterController()); // LetterControllerλ₯Ό λ“±λ‘ν•©λ‹ˆλ‹€.
}
}
Empty file added unibond/lib/util/userIdNum
Empty file.
1 change: 1 addition & 0 deletions unibond/lib/util/userIdNum.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
String? userIdNum;
2 changes: 1 addition & 1 deletion unibond/lib/view/screens/community/post_write_screen.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:unibond/view/screens/home_screen.dart';
import 'package:unibond/util/validator_util.dart';
import 'package:unibond/view/screens/home_screen.dart';
import 'package:unibond/view/widgets/custom_text_form_field.dart';
import 'package:unibond/view/widgets/custom_textarea.dart';
import 'package:unibond/view/widgets/custon_elevated_button.dart';
Expand Down
96 changes: 52 additions & 44 deletions unibond/lib/view/screens/letter/letter_write_screen.dart
Original file line number Diff line number Diff line change
@@ -1,67 +1,75 @@
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';

class LetterWriteScreen extends StatefulWidget {
const LetterWriteScreen({super.key});
class LetterWriteScreen extends StatelessWidget {
final _formKey = GlobalKey<FormState>();
final _titleController = TextEditingController();
final _contentController = TextEditingController();

@override
_LetterWriteScreenState createState() => _LetterWriteScreenState();
}

class _LetterWriteScreenState extends State<LetterWriteScreen> {
final TextEditingController _titleController = TextEditingController();
final TextEditingController _contentController = TextEditingController();
LetterWriteScreen({Key? key}) : super(key: key);

@override
void dispose() {
_titleController.dispose();
_contentController.dispose();
super.dispose();
}

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

return Scaffold(
appBar: AppBar(
title: const Text("νŽΈμ§€ μž‘μ„±"),
leading: IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: () {
Navigator.pop(context);
Get.back();
},
),
actions: [
IconButton(
icon: const Icon(Icons.send),
onPressed: () {
// νŽΈμ§€ μ „μ†‘ν•˜λŠ” μ½”λ“œ μΆ”κ°€
},
)
],
),
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(
2,
_titleController.text.trim(),
_contentController.text.trim());
if (isSuccess == true) {
print('νŽΈμ§€ 전솑 성곡');
Get.off(() => 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),
),
),
),
);
}
}
Loading