Search in sources :

Example 1 with User

use of io.ionic.demo.ecommerce.data.model.User in project portals-ecommerce-demo by ionic-team.

the class DataServiceTest method getUserShouldReturnUser.

@Test
public void getUserShouldReturnUser() {
    User user = dataService.getUser();
    assertNotNull(user);
    assertEquals("Joe", user.firstName);
}
Also used : User(io.ionic.demo.ecommerce.data.model.User) Test(org.junit.Test)

Example 2 with User

use of io.ionic.demo.ecommerce.data.model.User in project portals-ecommerce-demo by ionic-team.

the class DataServiceTest method setUserShouldStoreNewUser.

@Test
public void setUserShouldStoreNewUser() {
    User user = dataService.getUser();
    user.firstName = "Jane";
    dataService.setUser(user);
    user = null;
    User user2 = dataService.getUser();
    assertEquals("Jane", user2.firstName);
}
Also used : User(io.ionic.demo.ecommerce.data.model.User) Test(org.junit.Test)

Example 3 with User

use of io.ionic.demo.ecommerce.data.model.User in project portals-ecommerce-demo by ionic-team.

the class ShopAPIPlugin method getUserDetails.

@PluginMethod
public void getUserDetails(PluginCall call) {
    try {
        User user = dataService.getUser();
        String userJson = new Gson().toJson(user);
        JSObject userJSObject = JSObject.fromJSONObject(new JSONObject(userJson));
        call.resolve(userJSObject);
    } catch (JSONException e) {
        call.reject("error decoding user object");
    }
}
Also used : User(io.ionic.demo.ecommerce.data.model.User) JSONObject(org.json.JSONObject) Gson(com.google.gson.Gson) JSObject(com.getcapacitor.JSObject) JSONException(org.json.JSONException) PluginMethod(com.getcapacitor.PluginMethod)

Example 4 with User

use of io.ionic.demo.ecommerce.data.model.User in project portals-ecommerce-demo by ionic-team.

the class ShopAPIPlugin method setUserPicture.

@PluginMethod
public void setUserPicture(PluginCall call) {
    String picture = call.getString("picture");
    if (picture != null && !picture.isEmpty()) {
        User user = dataService.getUser();
        dataService.storeUserImage(getContext(), user, picture);
        dataService.setUser(user);
    }
    call.resolve();
}
Also used : User(io.ionic.demo.ecommerce.data.model.User) PluginMethod(com.getcapacitor.PluginMethod)

Example 5 with User

use of io.ionic.demo.ecommerce.data.model.User in project portals-ecommerce-demo by ionic-team.

the class ShopAPIPlugin method getUserPicture.

@PluginMethod
public void getUserPicture(PluginCall call) {
    User user = dataService.getUser();
    if (user.image != null && !user.image.isEmpty()) {
        String picture = user.getImageBase64(getContext());
        if (picture != null) {
            JSObject returnPicture = new JSObject();
            returnPicture.put("picture", picture);
            call.resolve(returnPicture);
            return;
        }
    }
    call.reject("No picture available");
}
Also used : User(io.ionic.demo.ecommerce.data.model.User) JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Aggregations

User (io.ionic.demo.ecommerce.data.model.User)10 Test (org.junit.Test)5 PluginMethod (com.getcapacitor.PluginMethod)4 JSObject (com.getcapacitor.JSObject)3 Gson (com.google.gson.Gson)2 Address (io.ionic.demo.ecommerce.data.model.Address)2 JSONException (org.json.JSONException)2 DataService (io.ionic.demo.ecommerce.data.DataService)1 AppData (io.ionic.demo.ecommerce.data.model.AppData)1 CreditCard (io.ionic.demo.ecommerce.data.model.CreditCard)1 Product (io.ionic.demo.ecommerce.data.model.Product)1 JSONObject (org.json.JSONObject)1 Before (org.junit.Before)1