69 lines
1.6 KiB
Dart
69 lines
1.6 KiB
Dart
import 'package:dio/dio.dart';
|
|
import 'package:server/apis/auth.dart';
|
|
import 'package:server/server.dart';
|
|
|
|
class Projects {
|
|
getProjects() async {
|
|
try {
|
|
final id = await auth.setToken();
|
|
if (id != null) {
|
|
final response = await api.get('/collections/project/records');
|
|
if (response.data != null) {
|
|
return response.data;
|
|
}
|
|
}
|
|
} on DioException catch (e) {
|
|
if (e.type == DioExceptionType.connectionError) {
|
|
return "Internet Connection Error";
|
|
}
|
|
return e.response!.data['message'];
|
|
} catch (e) {
|
|
print(e);
|
|
return Error();
|
|
}
|
|
}
|
|
|
|
createProject(
|
|
title,
|
|
typeProject,
|
|
dateStart,
|
|
dateEnd,
|
|
gender,
|
|
descriptionSource,
|
|
category,
|
|
) async {
|
|
try {
|
|
final id = await auth.setToken();
|
|
print(id);
|
|
if (id != null) {
|
|
final response = await api.post(
|
|
'/collections/project/records',
|
|
data: {
|
|
"title": title,
|
|
"typeProject": typeProject,
|
|
"user_id": id,
|
|
"dateStart": dateStart,
|
|
"dateEnd": dateEnd,
|
|
"gender": gender,
|
|
"description_source": descriptionSource,
|
|
"category": category,
|
|
},
|
|
);
|
|
if (response.data != null) {
|
|
return response.data;
|
|
}
|
|
}
|
|
} on DioException catch (e) {
|
|
if (e.type == DioExceptionType.connectionError) {
|
|
return "Internet Connection Error";
|
|
}
|
|
return e.response!.data['message'];
|
|
} catch (e) {
|
|
print(e);
|
|
return Error();
|
|
}
|
|
}
|
|
}
|
|
|
|
final projects = Projects();
|