diff --git a/.gitignore b/.gitignore index 7843e0d..9f0bb74 100644 --- a/.gitignore +++ b/.gitignore @@ -33,25 +33,4 @@ amplify-gradle-config.json amplifytools.xcconfig .secret-* **.sample -#amplify-do-not-edit-end - -#amplify-do-not-edit-begin -amplify/\#current-cloud-backend -amplify/.config/local-* -amplify/logs -amplify/mock-data -amplify/backend/amplify-meta.json -amplify/backend/.temp -build/ -dist/ -node_modules/ -aws-exports.js -awsconfiguration.json -amplifyconfiguration.json -amplifyconfiguration.dart -amplify-build-config.json -amplify-gradle-config.json -amplifytools.xcconfig -.secret-* -**.sample -#amplify-do-not-edit-end +#amplify-do-not-edit-end diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml index 97e58a7..6c76ba3 100644 --- a/.idea/deploymentTargetDropDown.xml +++ b/.idea/deploymentTargetDropDown.xml @@ -1,17 +1,17 @@ - + - + - - + + - - + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index a41a17b..9cfcbea 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -55,6 +55,10 @@ + + + + diff --git a/amplify/backend/api/thrifty2/cli-inputs.json b/amplify/backend/api/thrifty2/cli-inputs.json new file mode 100644 index 0000000..6c408e9 --- /dev/null +++ b/amplify/backend/api/thrifty2/cli-inputs.json @@ -0,0 +1,27 @@ +{ + "version": 1, + "serviceConfiguration": { + "serviceName": "AppSync", + "defaultAuthType": { + "mode": "AMAZON_COGNITO_USER_POOLS", + "cognitoUserPoolId": "auththrifty23c488d7e" + }, + "conflictResolution": { + "defaultResolutionStrategy": { + "type": "AUTOMERGE" + } + }, + "apiName": "thrifty2", + "gqlSchemaPath": "/tmp/amplify-5f5ada2c-a6db-4c8f-a135-c722a7a816d9/amplify/backend/api/thrifty2/schema.graphql", + "additionalAuthTypes": [ + { + "mode": "API_KEY", + "keyDescription": "api key description", + "expirationTime": 30 + }, + { + "mode": "AWS_IAM" + } + ] + } +} \ No newline at end of file diff --git a/amplify/backend/api/thrifty2/parameters.json b/amplify/backend/api/thrifty2/parameters.json index 0f1836b..254946c 100644 --- a/amplify/backend/api/thrifty2/parameters.json +++ b/amplify/backend/api/thrifty2/parameters.json @@ -7,5 +7,6 @@ "auththrifty23c488d7e", "Outputs.UserPoolId" ] - } + }, + "AuthModeLastUpdated": "2021-12-01T23:40:42.562Z" } \ No newline at end of file diff --git a/amplify/backend/api/thrifty2/schema.graphql b/amplify/backend/api/thrifty2/schema.graphql index 14c7584..27ddccd 100644 --- a/amplify/backend/api/thrifty2/schema.graphql +++ b/amplify/backend/api/thrifty2/schema.graphql @@ -30,3 +30,4 @@ type Product @model @auth(rules: [{allow: private}]) @key(name: "byCategory", fi categoryID: ID image: String! } + \ No newline at end of file diff --git a/amplify/backend/backend-config.json b/amplify/backend/backend-config.json index 40e82b3..1c24ae3 100644 --- a/amplify/backend/backend-config.json +++ b/amplify/backend/backend-config.json @@ -11,7 +11,18 @@ "userPoolId": "auththrifty23c488d7e" } }, - "additionalAuthenticationProviders": [] + "additionalAuthenticationProviders": [ + { + "authenticationType": "API_KEY", + "apiKeyConfig": { + "apiKeyExpirationDays": 30, + "description": "api key description" + } + }, + { + "authenticationType": "AWS_IAM" + } + ] } } } diff --git a/amplify/cli.json b/amplify/cli.json index 8e29a8e..1b1a4f5 100644 --- a/amplify/cli.json +++ b/amplify/cli.json @@ -1,48 +1,48 @@ { - "features": { - "graphqltransformer": { - "addmissingownerfields": true, - "improvepluralization": false, - "validatetypenamereservedwords": true, - "useexperimentalpipelinedtransformer": false, - "enableiterativegsiupdates": true, - "secondarykeyasgsi": true, - "skipoverridemutationinputtypes": true - }, - "frontend-ios": { - "enablexcodeintegration": true - }, - "auth": { - "enablecaseinsensitivity": true, - "useinclusiveterminology": true, - "breakcirculardependency": true, - "forcealiasattributes": false - }, - "codegen": { - "useappsyncmodelgenplugin": true, - "usedocsgeneratorplugin": true, - "usetypesgeneratorplugin": true, - "cleangeneratedmodelsdirectory": true, - "retaincasestyle": true, - "addtimestampfields": true, - "handlelistnullabilitytransparently": true, - "emitauthprovider": true, - "generateindexrules": true, - "enabledartnullsafety": true - }, - "appsync": { - "generategraphqlpermissions": true - }, - "latestregionsupport": { - "pinpoint": 1, - "translate": 1, - "transcribe": 1, - "rekognition": 1, - "textract": 1, - "comprehend": 1 - }, - "project": { - "overrides": true + "features": { + "graphqltransformer": { + "addmissingownerfields": true, + "improvepluralization": false, + "validatetypenamereservedwords": true, + "useexperimentalpipelinedtransformer": false, + "enableiterativegsiupdates": true, + "secondarykeyasgsi": true, + "skipoverridemutationinputtypes": true + }, + "frontend-ios": { + "enablexcodeintegration": true + }, + "auth": { + "enablecaseinsensitivity": true, + "useinclusiveterminology": true, + "breakcirculardependency": true, + "forcealiasattributes": false + }, + "codegen": { + "useappsyncmodelgenplugin": true, + "usedocsgeneratorplugin": true, + "usetypesgeneratorplugin": true, + "cleangeneratedmodelsdirectory": true, + "retaincasestyle": true, + "addtimestampfields": true, + "handlelistnullabilitytransparently": true, + "emitauthprovider": true, + "generateindexrules": true, + "enabledartnullsafety": true + }, + "appsync": { + "generategraphqlpermissions": true + }, + "latestregionsupport": { + "pinpoint": 1, + "translate": 1, + "transcribe": 1, + "rekognition": 1, + "textract": 1, + "comprehend": 1 + }, + "project": { + "overrides": true + } } - } } \ No newline at end of file diff --git a/app/src/main/java/com/amplifyframework/datastore/generated/model/AmplifyModelProvider.java b/app/src/main/java/com/amplifyframework/datastore/generated/model/AmplifyModelProvider.java index 350f6e7..c5569f5 100644 --- a/app/src/main/java/com/amplifyframework/datastore/generated/model/AmplifyModelProvider.java +++ b/app/src/main/java/com/amplifyframework/datastore/generated/model/AmplifyModelProvider.java @@ -13,7 +13,7 @@ */ public final class AmplifyModelProvider implements ModelProvider { - private static final String AMPLIFY_MODEL_VERSION = "60f05c329e96e718a1c603e8ce306b24"; + private static final String AMPLIFY_MODEL_VERSION = "52523adac5d643063a009102021f267d"; private static AmplifyModelProvider amplifyGeneratedModelInstance; private AmplifyModelProvider() { @@ -34,7 +34,7 @@ public static AmplifyModelProvider getInstance() { @Override public Set> models() { final Set> modifiableSet = new HashSet<>( - Arrays.>asList(Product.class, UserCart.class, User.class, Favourites.class, Category.class) + Arrays.>asList(Favorite.class, User.class, Category.class, Product.class) ); return Immutable.of(modifiableSet); diff --git a/app/src/main/java/com/amplifyframework/datastore/generated/model/Category.java b/app/src/main/java/com/amplifyframework/datastore/generated/model/Category.java index 41adec4..534b2a4 100644 --- a/app/src/main/java/com/amplifyframework/datastore/generated/model/Category.java +++ b/app/src/main/java/com/amplifyframework/datastore/generated/model/Category.java @@ -1,5 +1,6 @@ package com.amplifyframework.datastore.generated.model; +import com.amplifyframework.core.model.temporal.Temporal; import java.util.List; import java.util.UUID; @@ -21,13 +22,15 @@ /** This is an auto generated class representing the Category type in your schema. */ @SuppressWarnings("all") @ModelConfig(pluralName = "Categories", authRules = { - @AuthRule(allow = AuthStrategy.PUBLIC, operations = { ModelOperation.CREATE, ModelOperation.UPDATE, ModelOperation.DELETE, ModelOperation.READ }) + @AuthRule(allow = AuthStrategy.PRIVATE, operations = { ModelOperation.CREATE, ModelOperation.UPDATE, ModelOperation.DELETE, ModelOperation.READ }) }) public final class Category implements Model { - public static final QueryField ID = field("id"); - public static final QueryField NAME = field("name"); + public static final QueryField ID = field("Category", "id"); + public static final QueryField NAME = field("Category", "name"); private final @ModelField(targetType="ID", isRequired = true) String id; private final @ModelField(targetType="String", isRequired = true) String name; + private @ModelField(targetType="AWSDateTime", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType="AWSDateTime", isReadOnly = true) Temporal.DateTime updatedAt; public String getId() { return id; } @@ -36,6 +39,14 @@ public String getName() { return name; } + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + private Category(String id, String name) { this.id = id; this.name = name; @@ -50,7 +61,9 @@ public boolean equals(Object obj) { } else { Category category = (Category) obj; return ObjectsCompat.equals(getId(), category.getId()) && - ObjectsCompat.equals(getName(), category.getName()); + ObjectsCompat.equals(getName(), category.getName()) && + ObjectsCompat.equals(getCreatedAt(), category.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), category.getUpdatedAt()); } } @@ -59,6 +72,8 @@ public int hashCode() { return new StringBuilder() .append(getId()) .append(getName()) + .append(getCreatedAt()) + .append(getUpdatedAt()) .toString() .hashCode(); } @@ -68,7 +83,9 @@ public String toString() { return new StringBuilder() .append("Category {") .append("id=" + String.valueOf(getId()) + ", ") - .append("name=" + String.valueOf(getName())) + .append("name=" + String.valueOf(getName()) + ", ") + .append("createdAt=" + String.valueOf(getCreatedAt()) + ", ") + .append("updatedAt=" + String.valueOf(getUpdatedAt())) .append("}") .toString(); } @@ -84,18 +101,8 @@ public static NameStep builder() { * in a relationship. * @param id the id of the existing item this instance will represent * @return an instance of this model with only ID populated - * @throws IllegalArgumentException Checks that ID is in the proper format */ public static Category justId(String id) { - try { - UUID.fromString(id); // Check that ID is in the UUID format - if not an exception is thrown - } catch (Exception exception) { - throw new IllegalArgumentException( - "Model IDs must be unique in the format of UUID. This method is for creating instances " + - "of an existing object with only its ID field for sending as a mutation parameter. When " + - "creating a new object, use the standard builder method and leave the ID field blank." - ); - } return new Category( id, null @@ -113,7 +120,7 @@ public interface NameStep { public interface BuildStep { Category build(); - BuildStep id(String id) throws IllegalArgumentException; + BuildStep id(String id); } @@ -137,22 +144,11 @@ public BuildStep name(String name) { } /** - * WARNING: Do not set ID when creating a new object. Leave this blank and one will be auto generated for you. - * This should only be set when referring to an already existing object. * @param id id * @return Current Builder instance, for fluent method chaining - * @throws IllegalArgumentException Checks that ID is in the proper format */ - public BuildStep id(String id) throws IllegalArgumentException { + public BuildStep id(String id) { this.id = id; - - try { - UUID.fromString(id); // Check that ID is in the UUID format - if not an exception is thrown - } catch (Exception exception) { - throw new IllegalArgumentException("Model IDs must be unique in the format of UUID.", - exception); - } - return this; } } diff --git a/app/src/main/java/com/amplifyframework/datastore/generated/model/Favorite.java b/app/src/main/java/com/amplifyframework/datastore/generated/model/Favorite.java index 2eafb21..58c2d7b 100644 --- a/app/src/main/java/com/amplifyframework/datastore/generated/model/Favorite.java +++ b/app/src/main/java/com/amplifyframework/datastore/generated/model/Favorite.java @@ -1,5 +1,6 @@ package com.amplifyframework.datastore.generated.model; +import com.amplifyframework.core.model.temporal.Temporal; import java.util.List; import java.util.UUID; @@ -21,23 +22,69 @@ /** This is an auto generated class representing the Favorite type in your schema. */ @SuppressWarnings("all") @ModelConfig(pluralName = "Favorites", authRules = { - @AuthRule(allow = AuthStrategy.PUBLIC, operations = { ModelOperation.CREATE, ModelOperation.UPDATE, ModelOperation.DELETE, ModelOperation.READ }) + @AuthRule(allow = AuthStrategy.PRIVATE, operations = { ModelOperation.CREATE, ModelOperation.UPDATE, ModelOperation.DELETE, ModelOperation.READ }) }) +@Index(name = "byUser", fields = {"userID"}) public final class Favorite implements Model { - public static final QueryField ID = field("id"); - public static final QueryField USER_ID = field("userID"); + public static final QueryField ID = field("Favorite", "id"); + public static final QueryField TITLE_FAV = field("Favorite", "titleFav"); + public static final QueryField IMAGE_FAV = field("Favorite", "imageFav"); + public static final QueryField PRICE_FAV = field("Favorite", "priceFav"); + public static final QueryField SIZE_FAV = field("Favorite", "sizeFav"); + public static final QueryField CATEGORY_FAV = field("Favorite", "categoryFav"); + public static final QueryField USER_ID = field("Favorite", "userID"); private final @ModelField(targetType="ID", isRequired = true) String id; + private final @ModelField(targetType="String", isRequired = true) String titleFav; + private final @ModelField(targetType="String", isRequired = true) String imageFav; + private final @ModelField(targetType="String", isRequired = true) String priceFav; + private final @ModelField(targetType="String", isRequired = true) String sizeFav; + private final @ModelField(targetType="String", isRequired = true) String categoryFav; private final @ModelField(targetType="ID") String userID; + private @ModelField(targetType="AWSDateTime", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType="AWSDateTime", isReadOnly = true) Temporal.DateTime updatedAt; public String getId() { return id; } + public String getTitleFav() { + return titleFav; + } + + public String getImageFav() { + return imageFav; + } + + public String getPriceFav() { + return priceFav; + } + + public String getSizeFav() { + return sizeFav; + } + + public String getCategoryFav() { + return categoryFav; + } + public String getUserId() { return userID; } - private Favorite(String id, String userID) { + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private Favorite(String id, String titleFav, String imageFav, String priceFav, String sizeFav, String categoryFav, String userID) { this.id = id; + this.titleFav = titleFav; + this.imageFav = imageFav; + this.priceFav = priceFav; + this.sizeFav = sizeFav; + this.categoryFav = categoryFav; this.userID = userID; } @@ -50,7 +97,14 @@ public boolean equals(Object obj) { } else { Favorite favorite = (Favorite) obj; return ObjectsCompat.equals(getId(), favorite.getId()) && - ObjectsCompat.equals(getUserId(), favorite.getUserId()); + ObjectsCompat.equals(getTitleFav(), favorite.getTitleFav()) && + ObjectsCompat.equals(getImageFav(), favorite.getImageFav()) && + ObjectsCompat.equals(getPriceFav(), favorite.getPriceFav()) && + ObjectsCompat.equals(getSizeFav(), favorite.getSizeFav()) && + ObjectsCompat.equals(getCategoryFav(), favorite.getCategoryFav()) && + ObjectsCompat.equals(getUserId(), favorite.getUserId()) && + ObjectsCompat.equals(getCreatedAt(), favorite.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), favorite.getUpdatedAt()); } } @@ -58,7 +112,14 @@ public boolean equals(Object obj) { public int hashCode() { return new StringBuilder() .append(getId()) + .append(getTitleFav()) + .append(getImageFav()) + .append(getPriceFav()) + .append(getSizeFav()) + .append(getCategoryFav()) .append(getUserId()) + .append(getCreatedAt()) + .append(getUpdatedAt()) .toString() .hashCode(); } @@ -68,12 +129,19 @@ public String toString() { return new StringBuilder() .append("Favorite {") .append("id=" + String.valueOf(getId()) + ", ") - .append("userID=" + String.valueOf(getUserId())) + .append("titleFav=" + String.valueOf(getTitleFav()) + ", ") + .append("imageFav=" + String.valueOf(getImageFav()) + ", ") + .append("priceFav=" + String.valueOf(getPriceFav()) + ", ") + .append("sizeFav=" + String.valueOf(getSizeFav()) + ", ") + .append("categoryFav=" + String.valueOf(getCategoryFav()) + ", ") + .append("userID=" + String.valueOf(getUserId()) + ", ") + .append("createdAt=" + String.valueOf(getCreatedAt()) + ", ") + .append("updatedAt=" + String.valueOf(getUpdatedAt())) .append("}") .toString(); } - public static BuildStep builder() { + public static TitleFavStep builder() { return new Builder(); } @@ -84,37 +152,67 @@ public static BuildStep builder() { * in a relationship. * @param id the id of the existing item this instance will represent * @return an instance of this model with only ID populated - * @throws IllegalArgumentException Checks that ID is in the proper format */ public static Favorite justId(String id) { - try { - UUID.fromString(id); // Check that ID is in the UUID format - if not an exception is thrown - } catch (Exception exception) { - throw new IllegalArgumentException( - "Model IDs must be unique in the format of UUID. This method is for creating instances " + - "of an existing object with only its ID field for sending as a mutation parameter. When " + - "creating a new object, use the standard builder method and leave the ID field blank." - ); - } return new Favorite( id, + null, + null, + null, + null, + null, null ); } public CopyOfBuilder copyOfBuilder() { return new CopyOfBuilder(id, + titleFav, + imageFav, + priceFav, + sizeFav, + categoryFav, userID); } + public interface TitleFavStep { + ImageFavStep titleFav(String titleFav); + } + + + public interface ImageFavStep { + PriceFavStep imageFav(String imageFav); + } + + + public interface PriceFavStep { + SizeFavStep priceFav(String priceFav); + } + + + public interface SizeFavStep { + CategoryFavStep sizeFav(String sizeFav); + } + + + public interface CategoryFavStep { + BuildStep categoryFav(String categoryFav); + } + + public interface BuildStep { Favorite build(); - BuildStep id(String id) throws IllegalArgumentException; + BuildStep id(String id); BuildStep userId(String userId); } - public static class Builder implements BuildStep { + public static class Builder implements TitleFavStep, ImageFavStep, PriceFavStep, SizeFavStep, CategoryFavStep, BuildStep { private String id; + private String titleFav; + private String imageFav; + private String priceFav; + private String sizeFav; + private String categoryFav; private String userID; @Override public Favorite build() { @@ -122,9 +220,49 @@ public Favorite build() { return new Favorite( id, + titleFav, + imageFav, + priceFav, + sizeFav, + categoryFav, userID); } + @Override + public ImageFavStep titleFav(String titleFav) { + Objects.requireNonNull(titleFav); + this.titleFav = titleFav; + return this; + } + + @Override + public PriceFavStep imageFav(String imageFav) { + Objects.requireNonNull(imageFav); + this.imageFav = imageFav; + return this; + } + + @Override + public SizeFavStep priceFav(String priceFav) { + Objects.requireNonNull(priceFav); + this.priceFav = priceFav; + return this; + } + + @Override + public CategoryFavStep sizeFav(String sizeFav) { + Objects.requireNonNull(sizeFav); + this.sizeFav = sizeFav; + return this; + } + + @Override + public BuildStep categoryFav(String categoryFav) { + Objects.requireNonNull(categoryFav); + this.categoryFav = categoryFav; + return this; + } + @Override public BuildStep userId(String userId) { this.userID = userId; @@ -132,31 +270,50 @@ public BuildStep userId(String userId) { } /** - * WARNING: Do not set ID when creating a new object. Leave this blank and one will be auto generated for you. - * This should only be set when referring to an already existing object. * @param id id * @return Current Builder instance, for fluent method chaining - * @throws IllegalArgumentException Checks that ID is in the proper format */ - public BuildStep id(String id) throws IllegalArgumentException { + public BuildStep id(String id) { this.id = id; - - try { - UUID.fromString(id); // Check that ID is in the UUID format - if not an exception is thrown - } catch (Exception exception) { - throw new IllegalArgumentException("Model IDs must be unique in the format of UUID.", - exception); - } - return this; } } public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String userId) { + private CopyOfBuilder(String id, String titleFav, String imageFav, String priceFav, String sizeFav, String categoryFav, String userId) { super.id(id); - super.userId(userId); + super.titleFav(titleFav) + .imageFav(imageFav) + .priceFav(priceFav) + .sizeFav(sizeFav) + .categoryFav(categoryFav) + .userId(userId); + } + + @Override + public CopyOfBuilder titleFav(String titleFav) { + return (CopyOfBuilder) super.titleFav(titleFav); + } + + @Override + public CopyOfBuilder imageFav(String imageFav) { + return (CopyOfBuilder) super.imageFav(imageFav); + } + + @Override + public CopyOfBuilder priceFav(String priceFav) { + return (CopyOfBuilder) super.priceFav(priceFav); + } + + @Override + public CopyOfBuilder sizeFav(String sizeFav) { + return (CopyOfBuilder) super.sizeFav(sizeFav); + } + + @Override + public CopyOfBuilder categoryFav(String categoryFav) { + return (CopyOfBuilder) super.categoryFav(categoryFav); } @Override diff --git a/app/src/main/java/com/amplifyframework/datastore/generated/model/Product.java b/app/src/main/java/com/amplifyframework/datastore/generated/model/Product.java index 3eb4d4e..0cc6a03 100644 --- a/app/src/main/java/com/amplifyframework/datastore/generated/model/Product.java +++ b/app/src/main/java/com/amplifyframework/datastore/generated/model/Product.java @@ -1,5 +1,6 @@ package com.amplifyframework.datastore.generated.model; +import com.amplifyframework.core.model.temporal.Temporal; import java.util.List; import java.util.UUID; @@ -21,25 +22,28 @@ /** This is an auto generated class representing the Product type in your schema. */ @SuppressWarnings("all") @ModelConfig(pluralName = "Products", authRules = { - @AuthRule(allow = AuthStrategy.PUBLIC, operations = { ModelOperation.CREATE, ModelOperation.UPDATE, ModelOperation.DELETE, ModelOperation.READ }) + @AuthRule(allow = AuthStrategy.PRIVATE, operations = { ModelOperation.CREATE, ModelOperation.UPDATE, ModelOperation.DELETE, ModelOperation.READ }) }) +@Index(name = "byCategory", fields = {"categoryID"}) public final class Product implements Model { - public static final QueryField ID = field("id"); - public static final QueryField TITLE = field("title"); - public static final QueryField DESCRIPTION = field("description"); - public static final QueryField PRICE = field("price"); - public static final QueryField SIZE = field("size"); - public static final QueryField COLOR = field("color"); - public static final QueryField IMAGE = field("image"); - public static final QueryField CATEGORY_ID = field("categoryID"); + public static final QueryField ID = field("Product", "id"); + public static final QueryField TITLE = field("Product", "title"); + public static final QueryField DESCRIPTION = field("Product", "description"); + public static final QueryField PRICE = field("Product", "price"); + public static final QueryField SIZE = field("Product", "size"); + public static final QueryField COLOR = field("Product", "color"); + public static final QueryField CATEGORY_ID = field("Product", "categoryID"); + public static final QueryField IMAGE = field("Product", "image"); private final @ModelField(targetType="ID", isRequired = true) String id; private final @ModelField(targetType="String", isRequired = true) String title; private final @ModelField(targetType="String", isRequired = true) String description; private final @ModelField(targetType="String", isRequired = true) String price; private final @ModelField(targetType="String", isRequired = true) String size; private final @ModelField(targetType="String", isRequired = true) String color; - private final @ModelField(targetType="String", isRequired = true) String image; private final @ModelField(targetType="ID") String categoryID; + private final @ModelField(targetType="String", isRequired = true) String image; + private @ModelField(targetType="AWSDateTime", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType="AWSDateTime", isReadOnly = true) Temporal.DateTime updatedAt; public String getId() { return id; } @@ -64,23 +68,31 @@ public String getColor() { return color; } + public String getCategoryId() { + return categoryID; + } + public String getImage() { return image; } - public String getCategoryId() { - return categoryID; + public Temporal.DateTime getCreatedAt() { + return createdAt; } - private Product(String id, String title, String description, String price, String size, String color, String image, String categoryID) { + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private Product(String id, String title, String description, String price, String size, String color, String categoryID, String image) { this.id = id; this.title = title; this.description = description; this.price = price; this.size = size; this.color = color; - this.image = image; this.categoryID = categoryID; + this.image = image; } @Override @@ -97,8 +109,10 @@ public boolean equals(Object obj) { ObjectsCompat.equals(getPrice(), product.getPrice()) && ObjectsCompat.equals(getSize(), product.getSize()) && ObjectsCompat.equals(getColor(), product.getColor()) && + ObjectsCompat.equals(getCategoryId(), product.getCategoryId()) && ObjectsCompat.equals(getImage(), product.getImage()) && - ObjectsCompat.equals(getCategoryId(), product.getCategoryId()); + ObjectsCompat.equals(getCreatedAt(), product.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), product.getUpdatedAt()); } } @@ -111,8 +125,10 @@ public int hashCode() { .append(getPrice()) .append(getSize()) .append(getColor()) - .append(getImage()) .append(getCategoryId()) + .append(getImage()) + .append(getCreatedAt()) + .append(getUpdatedAt()) .toString() .hashCode(); } @@ -127,8 +143,10 @@ public String toString() { .append("price=" + String.valueOf(getPrice()) + ", ") .append("size=" + String.valueOf(getSize()) + ", ") .append("color=" + String.valueOf(getColor()) + ", ") + .append("categoryID=" + String.valueOf(getCategoryId()) + ", ") .append("image=" + String.valueOf(getImage()) + ", ") - .append("categoryID=" + String.valueOf(getCategoryId())) + .append("createdAt=" + String.valueOf(getCreatedAt()) + ", ") + .append("updatedAt=" + String.valueOf(getUpdatedAt())) .append("}") .toString(); } @@ -144,18 +162,8 @@ public static TitleStep builder() { * in a relationship. * @param id the id of the existing item this instance will represent * @return an instance of this model with only ID populated - * @throws IllegalArgumentException Checks that ID is in the proper format */ public static Product justId(String id) { - try { - UUID.fromString(id); // Check that ID is in the UUID format - if not an exception is thrown - } catch (Exception exception) { - throw new IllegalArgumentException( - "Model IDs must be unique in the format of UUID. This method is for creating instances " + - "of an existing object with only its ID field for sending as a mutation parameter. When " + - "creating a new object, use the standard builder method and leave the ID field blank." - ); - } return new Product( id, null, @@ -175,8 +183,8 @@ public CopyOfBuilder copyOfBuilder() { price, size, color, - image, - categoryID); + categoryID, + image); } public interface TitleStep { DescriptionStep title(String title); @@ -210,7 +218,7 @@ public interface ImageStep { public interface BuildStep { Product build(); - BuildStep id(String id) throws IllegalArgumentException; + BuildStep id(String id); BuildStep categoryId(String categoryId); } @@ -235,8 +243,8 @@ public Product build() { price, size, color, - image, - categoryID); + categoryID, + image); } @Override @@ -288,29 +296,18 @@ public BuildStep categoryId(String categoryId) { } /** - * WARNING: Do not set ID when creating a new object. Leave this blank and one will be auto generated for you. - * This should only be set when referring to an already existing object. * @param id id * @return Current Builder instance, for fluent method chaining - * @throws IllegalArgumentException Checks that ID is in the proper format */ - public BuildStep id(String id) throws IllegalArgumentException { + public BuildStep id(String id) { this.id = id; - - try { - UUID.fromString(id); // Check that ID is in the UUID format - if not an exception is thrown - } catch (Exception exception) { - throw new IllegalArgumentException("Model IDs must be unique in the format of UUID.", - exception); - } - return this; } } public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String title, String description, String price, String size, String color, String image, String categoryId) { + private CopyOfBuilder(String id, String title, String description, String price, String size, String color, String categoryId, String image) { super.id(id); super.title(title) .description(description) diff --git a/app/src/main/java/com/amplifyframework/datastore/generated/model/User.java b/app/src/main/java/com/amplifyframework/datastore/generated/model/User.java index 521cbfe..1b7bb0b 100644 --- a/app/src/main/java/com/amplifyframework/datastore/generated/model/User.java +++ b/app/src/main/java/com/amplifyframework/datastore/generated/model/User.java @@ -1,5 +1,6 @@ package com.amplifyframework.datastore.generated.model; +import com.amplifyframework.core.model.temporal.Temporal; import java.util.List; import java.util.UUID; @@ -21,13 +22,15 @@ /** This is an auto generated class representing the User type in your schema. */ @SuppressWarnings("all") @ModelConfig(pluralName = "Users", authRules = { - @AuthRule(allow = AuthStrategy.PUBLIC, operations = { ModelOperation.CREATE, ModelOperation.UPDATE, ModelOperation.DELETE, ModelOperation.READ }) + @AuthRule(allow = AuthStrategy.PRIVATE, operations = { ModelOperation.CREATE, ModelOperation.UPDATE, ModelOperation.DELETE, ModelOperation.READ }) }) public final class User implements Model { - public static final QueryField ID = field("id"); - public static final QueryField EMAIL = field("email"); + public static final QueryField ID = field("User", "id"); + public static final QueryField EMAIL = field("User", "email"); private final @ModelField(targetType="ID", isRequired = true) String id; private final @ModelField(targetType="String", isRequired = true) String email; + private @ModelField(targetType="AWSDateTime", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType="AWSDateTime", isReadOnly = true) Temporal.DateTime updatedAt; public String getId() { return id; } @@ -36,6 +39,14 @@ public String getEmail() { return email; } + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + private User(String id, String email) { this.id = id; this.email = email; @@ -50,7 +61,9 @@ public boolean equals(Object obj) { } else { User user = (User) obj; return ObjectsCompat.equals(getId(), user.getId()) && - ObjectsCompat.equals(getEmail(), user.getEmail()); + ObjectsCompat.equals(getEmail(), user.getEmail()) && + ObjectsCompat.equals(getCreatedAt(), user.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), user.getUpdatedAt()); } } @@ -59,6 +72,8 @@ public int hashCode() { return new StringBuilder() .append(getId()) .append(getEmail()) + .append(getCreatedAt()) + .append(getUpdatedAt()) .toString() .hashCode(); } @@ -68,7 +83,9 @@ public String toString() { return new StringBuilder() .append("User {") .append("id=" + String.valueOf(getId()) + ", ") - .append("email=" + String.valueOf(getEmail())) + .append("email=" + String.valueOf(getEmail()) + ", ") + .append("createdAt=" + String.valueOf(getCreatedAt()) + ", ") + .append("updatedAt=" + String.valueOf(getUpdatedAt())) .append("}") .toString(); } @@ -84,18 +101,8 @@ public static EmailStep builder() { * in a relationship. * @param id the id of the existing item this instance will represent * @return an instance of this model with only ID populated - * @throws IllegalArgumentException Checks that ID is in the proper format */ public static User justId(String id) { - try { - UUID.fromString(id); // Check that ID is in the UUID format - if not an exception is thrown - } catch (Exception exception) { - throw new IllegalArgumentException( - "Model IDs must be unique in the format of UUID. This method is for creating instances " + - "of an existing object with only its ID field for sending as a mutation parameter. When " + - "creating a new object, use the standard builder method and leave the ID field blank." - ); - } return new User( id, null @@ -113,7 +120,7 @@ public interface EmailStep { public interface BuildStep { User build(); - BuildStep id(String id) throws IllegalArgumentException; + BuildStep id(String id); } @@ -137,22 +144,11 @@ public BuildStep email(String email) { } /** - * WARNING: Do not set ID when creating a new object. Leave this blank and one will be auto generated for you. - * This should only be set when referring to an already existing object. * @param id id * @return Current Builder instance, for fluent method chaining - * @throws IllegalArgumentException Checks that ID is in the proper format */ - public BuildStep id(String id) throws IllegalArgumentException { + public BuildStep id(String id) { this.id = id; - - try { - UUID.fromString(id); // Check that ID is in the UUID format - if not an exception is thrown - } catch (Exception exception) { - throw new IllegalArgumentException("Model IDs must be unique in the format of UUID.", - exception); - } - return this; } } diff --git a/app/src/main/java/com/example/thrifty/Cart.java b/app/src/main/java/com/example/thrifty/Cart.java index 25b0852..b7101d8 100644 --- a/app/src/main/java/com/example/thrifty/Cart.java +++ b/app/src/main/java/com/example/thrifty/Cart.java @@ -1,21 +1,65 @@ package com.example.thrifty; +import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import android.annotation.SuppressLint; import android.content.Intent; import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.os.Message; +import android.util.Log; import android.view.View; import android.widget.Button; +import android.widget.ImageView; +import android.widget.TextView; -public class Cart extends AppCompatActivity { +import com.amplifyframework.AmplifyException; +import com.amplifyframework.api.aws.AWSApiPlugin; +import com.amplifyframework.api.graphql.model.ModelQuery; +import com.amplifyframework.auth.cognito.AWSCognitoAuthPlugin; +import com.amplifyframework.core.Amplify; +import com.amplifyframework.datastore.AWSDataStorePlugin; +import com.amplifyframework.datastore.generated.model.Favorite; +import com.amplifyframework.datastore.generated.model.Product; +import com.amplifyframework.storage.s3.AWSS3StoragePlugin; +import com.example.thrifty.adapters.CartAdapter; +import com.google.android.material.bottomnavigation.BottomNavigationItemView; +import com.google.android.material.bottomnavigation.BottomNavigationView; +import com.squareup.picasso.Picasso; + +import java.util.ArrayList; +import java.util.List; +public class Cart extends AppCompatActivity { + private List favProduct = new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_cart); + try { +// Amplify.addPlugin(new AWSPinpointAnalyticsPlugin(getApplication())); + Amplify.addPlugin(new AWSS3StoragePlugin()); + Amplify.addPlugin(new AWSCognitoAuthPlugin()); + Amplify.addPlugin(new AWSDataStorePlugin()); + Amplify.addPlugin(new AWSApiPlugin()); + Amplify.configure(getApplicationContext()); + Log.i("MyAmplifyApp", "Initialized Amplify"); + } catch (AmplifyException error) { + Log.e("MyAmplifyApp", "Could not initialize Amplify", error); + } + + RecyclerView recyclerView = findViewById(R.id.cartRecycler); + CartAdapter cartAdapter = new CartAdapter(getApplicationContext()); + + + bottomNav(); Button button1 = findViewById(R.id.button4); button1.setOnClickListener(new View.OnClickListener() { @Override @@ -24,5 +68,94 @@ public void onClick(View view) { startActivity(intent); } }); + recyclerView.setAdapter(cartAdapter); + recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext(), RecyclerView.VERTICAL,false)); + + Handler handler = new Handler(Looper.myLooper(), new Handler.Callback() { + @SuppressLint("NotifyDataSetChanged") + @Override + public boolean handleMessage(@NonNull Message message) { + recyclerView.getAdapter().notifyDataSetChanged(); + return false; + } + }); + + + TextView textView = findViewById(R.id.titlefrag1); + TextView priceTxt = findViewById(R.id.price); + TextView categoryTxt = findViewById(R.id.categoryfrag); +// TextView descriptionTxt = findViewById(R.id.descriptionText); + + Intent intent = getIntent(); + String title = intent.getStringExtra("Title"); + Log.i("Jamal", "onCreate: Tilte "+ title); + String price = intent.getStringExtra("price"); + String category = intent.getStringExtra("category"); +// String description = intent.getStringExtra("description"); + + + + + +// String url = intent.getExtras().getString("image"); +// ImageView image = findViewById(R.id.itemImage); +// Log.i("imagview", url); +// Picasso.get().load(url).into(image); + + Amplify.API.query( + ModelQuery.list(Favorite.class), + response->{ + for (Favorite favorite:response.getData()){ + favProduct.add(favorite); + } + handler.sendEmptyMessage(1); + }, + error-> Log.e("MyAmplifyApp", "Query failure", error) + ); + textView.setText(title); + priceTxt.setText(price); + categoryTxt.setText(category); +// descriptionTxt.setText(description); + + + } + public void bottomNav(){ + BottomNavigationView bottomNavigationView = findViewById(R.id.bottomNavigationView); + bottomNavigationView.setSelectedItemId(R.id.cart); + BottomNavigationItemView homeNav = findViewById(R.id.homeNav); + BottomNavigationItemView search = findViewById(R.id.search); + BottomNavigationItemView cart = findViewById(R.id.cart); + BottomNavigationItemView wishlist = findViewById(R.id.wishlist); + BottomNavigationItemView profile = findViewById(R.id.profile); + + search.setOnClickListener(view -> { + Intent intent = new Intent(getApplicationContext(), Categories.class); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK| Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + }); + + homeNav.setOnClickListener(view -> { + Intent intent = new Intent(getApplicationContext(), MainActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK| Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + }); + + profile.setOnClickListener(view -> { + Intent intent = new Intent(getApplicationContext(), Profile.class); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK| Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + }); + + wishlist.setOnClickListener(view -> { + Intent intent = new Intent(getApplicationContext(), Favourate.class); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK| Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + }); + + cart.setOnClickListener(view -> { + Intent intent = new Intent(getApplicationContext(), Cart.class); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK| Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + }); } } \ No newline at end of file diff --git a/app/src/main/java/com/example/thrifty/ProductView.java b/app/src/main/java/com/example/thrifty/ProductView.java index c5ce49f..d088fad 100644 --- a/app/src/main/java/com/example/thrifty/ProductView.java +++ b/app/src/main/java/com/example/thrifty/ProductView.java @@ -19,9 +19,12 @@ import com.amplifyframework.AmplifyException; import com.amplifyframework.api.aws.AWSApiPlugin; +import com.amplifyframework.api.graphql.model.ModelMutation; import com.amplifyframework.auth.cognito.AWSCognitoAuthPlugin; import com.amplifyframework.core.Amplify; import com.amplifyframework.datastore.AWSDataStorePlugin; +import com.amplifyframework.datastore.generated.model.Favorite; +import com.amplifyframework.datastore.generated.model.UserCart; import com.amplifyframework.storage.s3.AWSS3StoragePlugin; import com.squareup.picasso.Picasso; @@ -78,6 +81,38 @@ protected void onCreate(Bundle savedInstanceState) { Button share = findViewById(R.id.share); ImageView imageView = findViewById(R.id.itemImage); + + findViewById(R.id.addToCart).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { +// UserCart userCart = UserCart.builder() +// .productId() +// .userId() +// .build(); + + String titlePro = textView.getText().toString(); + String pricePro = priceTxt.getText().toString(); + String catPro = categoryTxt.getText().toString(); + String desPro = descriptionTxt.getText().toString(); + + Favorite favorite = new Favorite.Builder() + .titleFav(titlePro) + .imageFav("") + .priceFav(pricePro) + .sizeFav("") + .categoryFav(catPro) + .build(); + + Amplify.API.mutate( + ModelMutation.create(favorite), + response->Log.i("Good Result","There is some progress") + ,error->{} + ); + Intent intent1 = new Intent(ProductView.this, Cart.class); + startActivity(intent1); + } + }); + share.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/app/src/main/java/com/example/thrifty/adapters/CartAdapter.java b/app/src/main/java/com/example/thrifty/adapters/CartAdapter.java new file mode 100644 index 0000000..7c5e4f2 --- /dev/null +++ b/app/src/main/java/com/example/thrifty/adapters/CartAdapter.java @@ -0,0 +1,94 @@ +package com.example.thrifty.adapters; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.content.Intent; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.amplifyframework.datastore.generated.model.Favorite; +import com.amplifyframework.datastore.generated.model.Product; +import com.example.thrifty.Cart; +import com.example.thrifty.ProductView; +import com.example.thrifty.R; +import com.squareup.picasso.Picasso; + +import org.w3c.dom.Text; + +import java.util.ArrayList; +import java.util.List; + +public class CartAdapter extends RecyclerView.Adapter { + + List products = new ArrayList<>(); + Context context; + + public CartAdapter(Context context) { + this.context = context; + } + + public CartAdapter(List products, Cart cart) { + this.products = products; + } + + @NonNull + @Override + public NewItemsHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cart_card, parent , false); + return new NewItemsHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull NewItemsHolder holder, @SuppressLint("RecyclerView") int position) { + holder.product = products.get(position); + ImageView imageView = holder.itemView.findViewById(R.id.idIVCourseImage); + TextView ProductName = holder.itemView.findViewById(R.id.titlefrag1); + TextView ProductCat = holder.itemView.findViewById(R.id.categoryfrag); + TextView ProductPrice = holder.itemView.findViewById(R.id.price); + Button buttonView = holder.itemView.findViewById(R.id.button3); + + ImageView deleteImg = holder.itemView.findViewById(R.id.imageViw4); + + ProductName.setText(holder.product.getTitleFav()); + ProductCat.setText(holder.product.getCategoryFav()); + ProductPrice.setText(holder.product.getPriceFav()); + Picasso.get().load(holder.product.getImageFav() ).into(imageView); + + holder.itemView.findViewById(R.id.cardCart).setOnClickListener(view -> { + Intent goToDetails = new Intent(view.getContext(), Cart.class); + Intent name = goToDetails.putExtra("Title",products.get(position).getTitleFav()); +// goToDetails.putExtra("Title",products.get(position).getTitleFav()); + Log.i("Khair", "onClick: "+name); + goToDetails.putExtra("category",products.get(position).getCategoryFav()); + goToDetails.putExtra("price", products.get(position).getPriceFav()); + goToDetails.putExtra("image",products.get(position).getImageFav()); +// goToDetails.putExtra("description",products.get(position).getDescription()); + view.getContext().startActivity(goToDetails); + }); + + + } + + @Override + public int getItemCount() { + return 0; + } + + + public static class NewItemsHolder extends RecyclerView.ViewHolder{ + public Favorite product; + public View itemView; + public NewItemsHolder(@NonNull View itemView) { + super(itemView); + this.itemView = itemView; + } + } +} diff --git a/app/src/main/java/com/example/thrifty/adapters/NewItemsAdapter.java b/app/src/main/java/com/example/thrifty/adapters/NewItemsAdapter.java index 6a1a3d8..520d877 100644 --- a/app/src/main/java/com/example/thrifty/adapters/NewItemsAdapter.java +++ b/app/src/main/java/com/example/thrifty/adapters/NewItemsAdapter.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.List; +import com.example.thrifty.Cart; import com.example.thrifty.MainActivity; import com.example.thrifty.ProductView; import com.example.thrifty.R; @@ -77,6 +78,19 @@ public void onClick(View view) { } }); +// holder.itemView.findViewById(R.id.addToCart).setOnClickListener(new View.OnClickListener() { +// @Override +// public void onClick(View view) { +// Intent intent = new Intent(view.getContext(), Cart.class); +// intent.putExtra("Title",products.get(position).getTitle()); +// intent.putExtra("category",products.get(position).getCategoryId()); +// intent.putExtra("price",products.get(position).getPrice()); +// intent.putExtra("image",products.get(position).getImage()); +// intent.putExtra("description",products.get(position).getDescription()); +// view.getContext().startActivity(intent); +// } +// }); + // holder.itemView.findViewById(R.id.fav).setOnClickListener(new View.OnClickListener() { diff --git a/app/src/main/res/layout/activity_cart.xml b/app/src/main/res/layout/activity_cart.xml index 5ff4468..aad74cc 100644 --- a/app/src/main/res/layout/activity_cart.xml +++ b/app/src/main/res/layout/activity_cart.xml @@ -60,6 +60,7 @@ app:menu="@menu/bottom_nav_menu" /> + android:text="Add To Cart" + android:textColor="@color/white" />