mirror of
https://github.com/Mercantec-GHC/h4-projekt-gruppe-0-sm.git
synced 2025-04-27 16:24:07 +02:00
fix app issues
This commit is contained in:
parent
5625526010
commit
8726468c55
@ -55,7 +55,10 @@ class ProductPage extends StatelessWidget {
|
|||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
image,
|
SizedBox(
|
||||||
|
height: 300,
|
||||||
|
child: image,
|
||||||
|
),
|
||||||
Text(
|
Text(
|
||||||
product.name,
|
product.name,
|
||||||
style: Theme.of(context).textTheme.bodyLarge,
|
style: Theme.of(context).textTheme.bodyLarge,
|
||||||
|
@ -13,14 +13,14 @@ class BackendServer implements Server {
|
|||||||
final _apiUrl = "https://h4-sm.mercantec.tech/api";
|
final _apiUrl = "https://h4-sm.mercantec.tech/api";
|
||||||
|
|
||||||
Future<Result<dynamic, String>> _postJson<Body>({
|
Future<Result<dynamic, String>> _postJson<Body>({
|
||||||
required String endpoint,
|
required String path,
|
||||||
required Body body,
|
required Body body,
|
||||||
Map<String, String>? headers,
|
Map<String, String>? headers,
|
||||||
}) async {
|
}) async {
|
||||||
final encoded = json.encode(body);
|
final encoded = json.encode(body);
|
||||||
return Future<Result<dynamic, String>>.sync(() {
|
return Future<Result<dynamic, String>>.sync(() {
|
||||||
return http.post(
|
return http.post(
|
||||||
Uri.parse("$_apiUrl/$endpoint"),
|
Uri.parse("$_apiUrl$path"),
|
||||||
body: encoded,
|
body: encoded,
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@ -40,12 +40,12 @@ class BackendServer implements Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Result<dynamic, String>> _getJson<Body>({
|
Future<Result<dynamic, String>> _getJson<Body>({
|
||||||
required String endpoint,
|
required String path,
|
||||||
Map<String, String>? headers,
|
Map<String, String>? headers,
|
||||||
}) async {
|
}) async {
|
||||||
return Future<Result<dynamic, String>>.sync(() {
|
return Future<Result<dynamic, String>>.sync(() {
|
||||||
return http.get(
|
return http.get(
|
||||||
Uri.parse("$_apiUrl/$endpoint"),
|
Uri.parse("$_apiUrl$path"),
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
...?headers,
|
...?headers,
|
||||||
@ -66,7 +66,7 @@ class BackendServer implements Server {
|
|||||||
@override
|
@override
|
||||||
Future<Result<List<Product>, String>> allProducts() async {
|
Future<Result<List<Product>, String>> allProducts() async {
|
||||||
final res = await _getJson(
|
final res = await _getJson(
|
||||||
endpoint: "$_apiUrl/products/all",
|
path: "/products/all",
|
||||||
);
|
);
|
||||||
|
|
||||||
return res.flatMap((body) {
|
return res.flatMap((body) {
|
||||||
@ -87,7 +87,7 @@ class BackendServer implements Server {
|
|||||||
String password,
|
String password,
|
||||||
) async {
|
) async {
|
||||||
final res = await _postJson(
|
final res = await _postJson(
|
||||||
endpoint: "users/register",
|
path: "/users/register",
|
||||||
body: {"name": name, "email": email, "password": password},
|
body: {"name": name, "email": email, "password": password},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ class BackendServer implements Server {
|
|||||||
String password,
|
String password,
|
||||||
) async {
|
) async {
|
||||||
final res = (await _postJson(
|
final res = (await _postJson(
|
||||||
endpoint: "sessions/login",
|
path: "/sessions/login",
|
||||||
body: {"email": email, "password": password},
|
body: {"email": email, "password": password},
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ class BackendServer implements Server {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Result<Null, String>> logout(String token) async {
|
Future<Result<Null, String>> logout(String token) async {
|
||||||
final res = await _postJson(endpoint: "sessions/logout", body: {});
|
final res = await _postJson(path: "sessions/logout", body: {});
|
||||||
|
|
||||||
return res.flatMap((body) {
|
return res.flatMap((body) {
|
||||||
if (body["ok"]) {
|
if (body["ok"]) {
|
||||||
@ -135,7 +135,7 @@ class BackendServer implements Server {
|
|||||||
@override
|
@override
|
||||||
Future<Result<User, String>> sessionUser(String token) async {
|
Future<Result<User, String>> sessionUser(String token) async {
|
||||||
final res = await _getJson(
|
final res = await _getJson(
|
||||||
endpoint: "$_apiUrl/sessions/user",
|
path: "/sessions/user",
|
||||||
headers: {"Session-Token": token},
|
headers: {"Session-Token": token},
|
||||||
);
|
);
|
||||||
return res.flatMap((body) {
|
return res.flatMap((body) {
|
||||||
@ -150,17 +150,15 @@ class BackendServer implements Server {
|
|||||||
@override
|
@override
|
||||||
Future<Result<Null, String>> purchaseCart(
|
Future<Result<Null, String>> purchaseCart(
|
||||||
String token, List<CartItem> cartItems) async {
|
String token, List<CartItem> cartItems) async {
|
||||||
final res = await _postJson(
|
final res = await _postJson(path: "/carts/purchase", headers: {
|
||||||
endpoint: "$_apiUrl/carts/purchase",
|
"Content-Type": "application/json",
|
||||||
headers: {"Content-Type": "application/json", "Session-Token": token},
|
"Session-Token": token
|
||||||
body: json.encode({
|
}, body: {
|
||||||
"items": cartItems
|
"items": cartItems
|
||||||
.map((cartItem) => {
|
.map((cartItem) =>
|
||||||
"product_id": cartItem.product.id,
|
{"product_id": cartItem.product.id, "amount": cartItem.amount})
|
||||||
"amount": cartItem.amount
|
.toList()
|
||||||
})
|
});
|
||||||
.toList()
|
|
||||||
}));
|
|
||||||
|
|
||||||
return res.flatMap((body) {
|
return res.flatMap((body) {
|
||||||
if (body["ok"]) {
|
if (body["ok"]) {
|
||||||
@ -173,8 +171,7 @@ class BackendServer implements Server {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Result<Null, String>> addBalance(String token) async {
|
Future<Result<Null, String>> addBalance(String token) async {
|
||||||
final res =
|
final res = await _postJson(path: "/users/balance/add", headers: {
|
||||||
await _postJson(endpoint: "$_apiUrl/users/balance/add", headers: {
|
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Accept": "application/json",
|
"Accept": "application/json",
|
||||||
"Session-Token": token
|
"Session-Token": token
|
||||||
@ -192,7 +189,7 @@ class BackendServer implements Server {
|
|||||||
@override
|
@override
|
||||||
Future<Result<List<ReceiptHeader>, String>> allReceipts(String token) async {
|
Future<Result<List<ReceiptHeader>, String>> allReceipts(String token) async {
|
||||||
final res = await _getJson(
|
final res = await _getJson(
|
||||||
endpoint: "$_apiUrl/receipts/all",
|
path: "/receipts/all",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Accept": "application/json",
|
"Accept": "application/json",
|
||||||
@ -215,7 +212,7 @@ class BackendServer implements Server {
|
|||||||
@override
|
@override
|
||||||
Future<Result<Receipt, String>> oneReceipt(String token, int id) async {
|
Future<Result<Receipt, String>> oneReceipt(String token, int id) async {
|
||||||
final res = await _getJson(
|
final res = await _getJson(
|
||||||
endpoint: "$_apiUrl/receipts/one?receipt_id=$id",
|
path: "/receipts/one?receipt_id=$id",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Accept": "application/json",
|
"Accept": "application/json",
|
||||||
|
@ -70,6 +70,8 @@ class ErrorMessages {
|
|||||||
switch (message) {
|
switch (message) {
|
||||||
case "insufficient funds":
|
case "insufficient funds":
|
||||||
return "Du har desværre ikke nok penge på kontoen.";
|
return "Du har desværre ikke nok penge på kontoen.";
|
||||||
|
case "bad request":
|
||||||
|
return "Fejl i kommunikation mellem app og server.";
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (kDebugMode) {
|
if (kDebugMode) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user