Skip to content
This repository has been archived by the owner on Feb 6, 2022. It is now read-only.

Commit

Permalink
"매일 한 번만 자동 제출" 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
nnnlog committed Oct 24, 2020
1 parent e7d4cfd commit 52ce0ef
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 12 deletions.
11 changes: 7 additions & 4 deletions lib/type/JagaJindanData.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class JagaJindanData {
String name, birthday, school, edu, password;
bool force, agree = false, startup = false, useNotification = false;
bool force, agree = false, startup = false, useNotification = false, submitLimitation = false;

static JagaJindanData readFromJSON(dynamic json) {
return new JagaJindanData(
Expand All @@ -12,11 +12,13 @@ class JagaJindanData {
json["force"] ?? false,
json["agree"] ?? false,
json["startup"] ?? false,
json["noti"] ?? false);
json["noti"] ?? false,
json["submitLimitation"] ?? false
);
}

JagaJindanData(this.name, this.birthday, this.school, this.edu, this.password,
this.force, this.agree, this.startup, this.useNotification);
this.force, this.agree, this.startup, this.useNotification, this.submitLimitation);

dynamic toJSON() {
return {
Expand All @@ -28,7 +30,8 @@ class JagaJindanData {
"force": this.force,
"agree": this.agree,
"startup": this.startup,
"noti": this.useNotification
"noti": this.useNotification,
"submitLimitation": this.submitLimitation
};
}
}
5 changes: 3 additions & 2 deletions lib/ui/MainPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import 'component/agree.dart';

class MainPage extends StatefulWidget {
JagaJindanData data =
JagaJindanData("", "", "", "", "", false, false, false, false);
JagaJindanData("", "", "", "", "", false, false, false, false, false);

TextEditingController nameController = TextEditingController(),
birthdayController = TextEditingController(),
schoolController = TextEditingController(),
Expand All @@ -28,7 +29,7 @@ class MainPage extends StatefulWidget {
this.eduController.text = this.data.edu;
this.passwordController.text = this.data.password;

if (this.data.startup) sendSurvey(this.data);
if (this.data.startup) sendSurvey(this.data, true);

agree(pageState);
await pageState.setState(() {});
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/MainPageState.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:jaga_jindan/ui/component/JagaJindanForm.dart';
import 'package:jaga_jindan/ui/component/credit.dart';
import 'package:jaga_jindan/ui/component/setting.dart';
import 'package:jaga_jindan/util/school.dart';

import 'package:jaga_jindan/util/sendSurvey.dart';
Expand Down
3 changes: 2 additions & 1 deletion lib/ui/component/JagaJindanForm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ JagaJindanForm(MainPageState state) {
child: ListBody(
children: <Widget>[
Text('앱 시작 시 자가진단 설문을 제출합니다.'),
Text('특정 시각마다 제출하는 기능은 계획 중에 있습니다.'),
Text('특정 시각마다 제출하는 기능은 계획 중 입니다.'),
Text('설정에서 "매일 한 번만 자동 제출" 옵션을 활성화하면 매일 한 번만 제출할 수 있습니다.'),
],
),
),
Expand Down
10 changes: 10 additions & 0 deletions lib/ui/component/credit.dart → lib/ui/component/setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ showCredit(MainPageState state) async {
state.widget.writeJSON();
});
}),
CheckboxListTile(
contentPadding: EdgeInsets.zero,
title: const Text('매일 한 번만 자동 제출'),
value: state.widget.data.submitLimitation,
onChanged: (bool value) {
_setState(() {
state.widget.data.submitLimitation = value;
state.widget.writeJSON();
});
}),
Divider(
color: Colors.black38,
height: 50,
Expand Down
18 changes: 14 additions & 4 deletions lib/util/sendSurvey.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:convert';

import 'package:flutter/widgets.dart';
import 'package:http/http.dart' as http;
import 'package:jaga_jindan/type/JagaJindanData.dart';
import 'package:jaga_jindan/util/RSAEncrypt.dart';
Expand All @@ -13,7 +14,7 @@ void showSurveyResult(
toast(message);
}

void sendSurvey(JagaJindanData credentials) async {
void sendSurvey(JagaJindanData credentials, [bool byAutomatic = false]) async {
try {
String jwt = jsonDecode((await http.post(
'https://${credentials.edu}hcs.eduro.go.kr/v2/findUser',
Expand Down Expand Up @@ -71,14 +72,23 @@ void sendSurvey(JagaJindanData credentials) async {
var userNo = int.parse(users[0]['userPNo']);
String org = users[0]['orgCode'];

jwt = jsonDecode((await http.post(
var userInfo = jsonDecode((await http.post(
'https://${credentials.edu}hcs.eduro.go.kr/v2/getUserInfo',
body: jsonEncode({'userPNo': userNo, 'orgCode': org}),
headers: {
'Authorization': jwt,
'Content-Type': 'application/json'
}))
.body)['token'];
.body);

var submittedDate = DateTime.parse(userInfo["registerDtm"]);

if (submittedDate.day == DateTime.now().day && byAutomatic && credentials.submitLimitation) {
showSurveyResult(false, "이미 제출한 기록이 있어 자동 제출을 취소했습니다.", credentials);
return;
}

jwt = userInfo['token'];

var res = await http.post(
'https://${credentials.edu}hcs.eduro.go.kr/registerServey',
Expand Down Expand Up @@ -109,7 +119,7 @@ void sendSurvey(JagaJindanData credentials) async {
true,
"자가진단 설문이 ${DateTime.now().toString().substring(0, 19)}에 제출되었습니다.",
credentials);
} catch (e) {
} catch (e, s) {
showSurveyResult(
false, "인증 정보를 한번 더 확인해주세요.\n오류가 계속 발생하는 경우 개발자에게 알려주세요.", credentials);
//toast(e.toString());
Expand Down

0 comments on commit 52ce0ef

Please sign in to comment.