mirror of
https://github.com/Mercantec-GHC/h4-projekt-gruppe-0-sm.git
synced 2025-04-27 08:24:05 +02:00
add coords
This commit is contained in:
parent
15d0892efd
commit
d5541c46fa
@ -3,4 +3,8 @@ class Coordinate {
|
|||||||
final double y;
|
final double y;
|
||||||
|
|
||||||
Coordinate({required this.x, required this.y});
|
Coordinate({required this.x, required this.y});
|
||||||
|
|
||||||
|
Coordinate.fromJson(Map<String, dynamic> json)
|
||||||
|
: x = json["x"],
|
||||||
|
y = json["y"];
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ import 'dart:convert';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:mobile/models/cart_item.dart';
|
import 'package:mobile/models/cart_item.dart';
|
||||||
|
import 'package:mobile/models/coordinate.dart';
|
||||||
import 'package:mobile/models/product.dart';
|
import 'package:mobile/models/product.dart';
|
||||||
import 'package:mobile/models/receipt.dart';
|
import 'package:mobile/models/receipt.dart';
|
||||||
import 'package:mobile/models/user.dart';
|
import 'package:mobile/models/user.dart';
|
||||||
@ -232,4 +233,26 @@ class BackendServer implements Server {
|
|||||||
Image productImage(int productId) {
|
Image productImage(int productId) {
|
||||||
return Image.network("$_apiUrl/products/image.png?product_id=$productId");
|
return Image.network("$_apiUrl/products/image.png?product_id=$productId");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Result<Coordinate, String>> productCoords(int id) async {
|
||||||
|
final res = await _getJson(
|
||||||
|
path: "/products/coords?product_id=$id",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Accept": "application/json",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return res.flatMap((body) {
|
||||||
|
if (body["ok"]) {
|
||||||
|
if (body["found"]) {
|
||||||
|
return Ok(
|
||||||
|
(Coordinate.fromJson(body["coords"] as Map<String, dynamic>)));
|
||||||
|
}
|
||||||
|
return const Err("Product has no coordinate");
|
||||||
|
} else {
|
||||||
|
return Err(body["msg"]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,4 +152,9 @@ class MockServer implements Server {
|
|||||||
Image productImage(int productId) {
|
Image productImage(int productId) {
|
||||||
return Image.asset("assets/placeholder.png");
|
return Image.asset("assets/placeholder.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Result<Coordinate, String>> productCoords(int id) async {
|
||||||
|
return Ok(Coordinate(x: 200, y: 100));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:mobile/models/cart_item.dart';
|
import 'package:mobile/models/cart_item.dart';
|
||||||
|
import 'package:mobile/models/coordinate.dart';
|
||||||
import 'package:mobile/models/product.dart';
|
import 'package:mobile/models/product.dart';
|
||||||
import 'package:mobile/models/receipt.dart';
|
import 'package:mobile/models/receipt.dart';
|
||||||
import 'package:mobile/models/user.dart';
|
import 'package:mobile/models/user.dart';
|
||||||
@ -31,6 +32,8 @@ abstract class Server {
|
|||||||
Future<Result<List<ReceiptHeader>, String>> allReceipts(String token);
|
Future<Result<List<ReceiptHeader>, String>> allReceipts(String token);
|
||||||
Future<Result<Receipt, String>> oneReceipt(String token, int id);
|
Future<Result<Receipt, String>> oneReceipt(String token, int id);
|
||||||
|
|
||||||
|
Future<Result<Coordinate, String>> productCoords(int id);
|
||||||
|
|
||||||
Image productImage(int productId);
|
Image productImage(int productId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user