Skip to content

Commit dd612de

Browse files
authored
feat: 급식 조회 기능 추가
feat: 급식 조회 기능 추가
2 parents df06f9f + 95c3e64 commit dd612de

File tree

4 files changed

+47
-17
lines changed

4 files changed

+47
-17
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
## [1.0.1] - 2025-04-16
2-
- school 로직 수정
1+
# Changelog
2+
3+
## [1.0.0+1] - 2025-04-15
4+
- 최초 공개
5+
- 학교 정보 및 급식 API 지원
36

47
## [1.0.0+2] - 2025-04-16
58
- README.md 문서 개선

lib/flutter_neis.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ library flutter_neis;
22

33
export 'src/neis_client.dart';
44

5+
export 'src/neis.dart';
6+
57
export 'src/models/school_info.dart';
68

7-
export 'src/neis.dart';
9+
export 'src/services/school_service.dart';
810

911
export 'src/models/meal_info.dart';
1012

lib/src/models/meal_info.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
class MealInfo {
22
final String date;
3-
final String dish;
3+
final String type; // 조식/중식/석식
4+
final List<String> dishes;
45

5-
MealInfo({required this.date, required this.dish});
6+
MealInfo({required this.date, required this.type, required this.dishes});
67

78
factory MealInfo.fromJson(Map<String, dynamic> json) {
8-
return MealInfo(date: json['MLSV_YMD'], dish: json['DDISH_NM']);
9+
return MealInfo(
10+
date: json['MLSV_YMD'],
11+
type: json['MMEAL_SC_NM'],
12+
dishes:
13+
(json['DDISH_NM'] as String)
14+
.split('<br/>')
15+
.map((e) => e.trim())
16+
.toList(),
17+
);
918
}
1019
}

lib/src/neis.dart

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,49 @@
1-
// lib/src/neis.dart
2-
31
import 'neis_client.dart';
42
import 'models/school_info.dart';
53
import 'models/meal_info.dart';
64

75
class Neis {
86
final NeisClient _client;
97
SchoolInfo? _school;
8+
List<MealInfo> _meals = [];
109

1110
Neis({required String apiKey}) : _client = NeisClient(apiKey: apiKey);
1211

1312
Future<void> loadSchoolInfo(String name) async {
1413
final result = await _client.fetchSchools(schoolName: name);
1514
if (result.isEmpty) throw Exception('학교를 찾을 수 없습니다.');
1615
_school = result.first;
17-
}
1816

19-
String get officeCode => _school?.officeCode ?? '';
20-
String get schoolCode => _school?.schoolCode ?? '';
21-
String get schoolName => _school?.schoolName ?? '';
17+
// 오늘 날짜 형식: YYYYMMDD
18+
final today = DateTime.now();
19+
final date = '${today.year}${_two(today.month)}${_two(today.day)}';
2220

23-
Future<List<MealInfo>> meal({required String date}) async {
24-
if (_school == null) {
25-
throw Exception('학교 정보를 먼저 불러와야 합니다.');
26-
}
27-
return _client.fetchMeals(
21+
_meals = await _client.fetchMeals(
2822
officeCode: _school!.officeCode,
2923
schoolCode: _school!.schoolCode,
3024
date: date,
3125
);
3226
}
27+
28+
// getter: 학교 정보
29+
String get officeCode => _school?.officeCode ?? '';
30+
String get schoolCode => _school?.schoolCode ?? '';
31+
String get schoolName => _school?.schoolName ?? '';
32+
List<MealInfo> get meals => _meals;
33+
34+
// 끼니별 getter
35+
MealInfo? get breakfast => _meals.firstWhere(
36+
(e) => e.type == '조식',
37+
orElse: () => MealInfo(date: '', type: '조식', dishes: []),
38+
);
39+
MealInfo? get lunch => _meals.firstWhere(
40+
(e) => e.type == '중식',
41+
orElse: () => MealInfo(date: '', type: '중식', dishes: []),
42+
);
43+
MealInfo? get dinner => _meals.firstWhere(
44+
(e) => e.type == '석식',
45+
orElse: () => MealInfo(date: '', type: '석식', dishes: []),
46+
);
47+
48+
String _two(int n) => n.toString().padLeft(2, '0');
3349
}

0 commit comments

Comments
 (0)