rename to one trip

This commit is contained in:
Alexander Laevens
2022-11-26 00:25:22 -07:00
parent 839147e0b0
commit 25e1a42392
207 changed files with 8015 additions and 245 deletions

View File

@@ -35,7 +35,7 @@ class Homegroup {
);
}
static Future<Homegroup?> fetchHomegroup(int id) async {
static Future<Homegroup?> get(int id) async {
String requestURL = "$baseURL/api/homegroups/$id/";
String token = TokenSingleton().getToken();
@@ -52,7 +52,7 @@ class Homegroup {
}
}
static Future<Homegroup?> createHomegroup(String title) async {
static Future<Homegroup?> create(String title) async {
String requestURL = "$baseURL/api/homegroups/";
String token = TokenSingleton().getToken();

View File

@@ -37,8 +37,7 @@ class HomegroupInvite {
return null;
}
static Future<HomegroupInvite?> createInvite(
int homegroupID, int userID) async {
static Future<HomegroupInvite?> create(int homegroupID, int userID) async {
String requestURL = "$baseURL/api/groupinvites/";
String token = TokenSingleton().getToken();
final http.Response response = await http.post(
@@ -54,7 +53,7 @@ class HomegroupInvite {
return null;
}
Future<bool> deleteInvite() async {
Future<bool> delete() async {
String requestURL = "$baseURL/api/groupinvites/$id/";
String token = TokenSingleton().getToken();
final http.Response response = await http.delete(

View File

@@ -8,10 +8,15 @@ import 'package:http/http.dart' as http;
class Recipe {
int id;
int homegroup;
String name;
List<Ingredient> ingredients;
Recipe({required this.id, required this.name, required this.ingredients});
Recipe(
{required this.id,
required this.name,
required this.ingredients,
required this.homegroup});
factory Recipe.fromJson(Map<String, dynamic> json) {
List<Ingredient> ingredients = [];
@@ -20,11 +25,12 @@ class Recipe {
}
return Recipe(
id: json["id"] as int,
homegroup: json["homegroup"] as int,
name: json["name"] as String,
ingredients: ingredients);
}
static Future<Recipe?> fetch(int id) async {
static Future<Recipe?> get(int id) async {
String requestURL = "$baseURL/api/recipes/$id/";
String token = TokenSingleton().getToken();
@@ -40,15 +46,15 @@ class Recipe {
return null;
}
static Future<List<Recipe>> fetchList(int groupID) async {
Homegroup? group = await Homegroup.fetchHomegroup(groupID);
static Future<List<Recipe>> getList(int groupID) async {
Homegroup? group = await Homegroup.get(groupID);
if (group == null) {
return [];
}
List<Recipe> recipes = [];
for (int recipeID in group.recipes) {
Recipe? recipe = await Recipe.fetch(recipeID);
Recipe? recipe = await Recipe.get(recipeID);
if (recipe != null) {
recipes.add(recipe);
}
@@ -56,4 +62,20 @@ class Recipe {
return recipes;
}
static Future<Recipe?> create(String name, int group) async {
String requestURL = "$baseURL/api/recipes/";
String token = TokenSingleton().getToken();
final http.Response response = await http.post(
Uri.parse(requestURL),
headers: {"Authorization": "Token $token"},
body: {"homegroup": "$group", "name": name},
);
if (response.statusCode == 201) {
return Recipe.fromJson(jsonDecode(response.body));
}
return null;
}
}

View File

@@ -37,7 +37,7 @@ class SimpleUser {
);
}
static Future<SimpleUser?> fetchUser({int? id}) async {
static Future<SimpleUser?> get({int? id}) async {
String requestURL = "$baseURL/auth/users/${id ?? 'me'}";
String token = TokenSingleton().getToken();

View File

@@ -39,7 +39,7 @@ class User {
);
}
static Future<User?> fetchUser() async {
static Future<User?> getMe() async {
String requestURL = "$baseURL/auth/users/me";
String token = TokenSingleton().getToken();
@@ -56,7 +56,7 @@ class User {
}
}
Future<User?> patch({
Future<User?> patchMe({
String? firstName,
String? lastName,
int? homegroup,