Skip to content

Commit d95a585

Browse files
authored
feat; 마음 그래프 api 연결 (#95)
* feat: 온도그래프 화면으로 전환 * feat: 온도그래프 화면으로 전환 * feat: 온도그래프 화면으로 전환 * feat: 온도그래프 화면으로 전환 * feat: 온도그래프 화면으로 전환 * feat: 온도그래프 화면 구현 * feat: 온도그래프 화면 구현 * feat: 온도그래프 화면 구현 * feat: 온도그래프 화면 구현 * feat: 온도그래프 화면 구현 * feat: 마이페이지 및 온도지수 api연결 * feat: 마이페이지 api 연결 * feat: 마이페이지 api 연결 * feat: 가족기여도 api 연결 * feat: dkdkkkkkk * feat: 서비스 업로드
1 parent 958591c commit d95a585

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
class FamilyTemperatureContributionResponse {
2+
final List<Contribution> contributions;
3+
4+
FamilyTemperatureContributionResponse({required this.contributions});
5+
6+
factory FamilyTemperatureContributionResponse.fromJson(Map<String, dynamic> json) {
7+
var list = json['contributions'] as List<dynamic>? ?? [];
8+
return FamilyTemperatureContributionResponse(
9+
contributions: list.map((e) => Contribution.fromJson(e)).toList(),
10+
);
11+
}
12+
}
13+
14+
class Contribution {
15+
final DateTime dateTime;
16+
final String userName;
17+
final String reason;
18+
final double contributed;
19+
20+
Contribution({
21+
required this.dateTime,
22+
required this.userName,
23+
required this.reason,
24+
required this.contributed,
25+
});
26+
27+
factory Contribution.fromJson(Map<String, dynamic> json) {
28+
return Contribution(
29+
dateTime: DateTime.parse(json['dateTime']),
30+
userName: json['userName'] ?? '',
31+
reason: json['reason'] ?? '',
32+
contributed: (json['contributed'] as num?)?.toDouble() ?? 0.0,
33+
);
34+
}
35+
36+
String get formattedDate => '${dateTime.year % 100}.${dateTime.month.toString().padLeft(2, '0')}.${dateTime.day.toString().padLeft(2, '0')} '
37+
'${dateTime.hour.toString().padLeft(2, '0')}:${dateTime.minute.toString().padLeft(2, '0')}';
38+
39+
String get formattedChange => (contributed > 0 ? '+' : '') + contributed.toStringAsFixed(1) + '°C';
40+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import 'dart:convert';
2+
import 'package:http/http.dart' as http;
3+
4+
class TemperatureService {
5+
final String baseUrl;
6+
TemperatureService({required this.baseUrl});
7+
8+
Future<List<Map<String, dynamic>>> fetchFamilyTemperatureDaily(String familyCode, {String? token}) async {
9+
final url = Uri.parse('$baseUrl/temperature/daily?familyId=$familyCode');
10+
Map<String, String> headers = {
11+
'Content-Type': 'application/json',
12+
};
13+
if (token != null) {
14+
headers['Authorization'] = 'Bearer $token';
15+
}
16+
final response = await http.get(url, headers: headers);
17+
if (response.statusCode == 200) {
18+
final data = json.decode(response.body);
19+
return List<Map<String, dynamic>>.from(data['dailyTemperatures'] ?? data ?? []);
20+
} else {
21+
throw Exception('가족 온도 일별 데이터 불러오기 실패');
22+
}
23+
}
24+
25+
Future<List<dynamic>> fetchFamilyTemperatureContributions(String familyCode, {String? token}) async {
26+
final url = Uri.parse('$baseUrl/temperature/contributions?familyId=$familyCode');
27+
Map<String, String> headers = {
28+
'Content-Type': 'application/json',
29+
};
30+
if (token != null) {
31+
headers['Authorization'] = 'Bearer $token';
32+
}
33+
final response = await http.get(url, headers: headers);
34+
if (response.statusCode == 200) {
35+
final data = json.decode(response.body);
36+
return data['contributions'] ?? data ?? [];
37+
} else {
38+
throw Exception('가족 온도 기여도 데이터 불러오기 실패');
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)