mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2026-03-10 18:55:03 +00:00
Delete Lambda prototype
Prototype the User DELETE lambda. Amplify does not include this functionality, so putting it in a Lambda with the fine-grained API. This currently does not invalidate outstanding tokens nor does it clean up the database. @claytonwwilson You will want to add the clean up code instead of the deleted stuff in UserDeleter
This commit is contained in:
@@ -8,6 +8,7 @@ import com.amplifyframework.auth.options.AuthSignUpOptions;
|
||||
import com.amplifyframework.auth.result.AuthSignInResult;
|
||||
import com.amplifyframework.auth.result.AuthSignUpResult;
|
||||
import com.amplifyframework.core.Amplify;
|
||||
import com.example.listify.data.User;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@@ -85,6 +86,10 @@ public class AuthManager {
|
||||
waiting = false;
|
||||
}
|
||||
|
||||
public void signOutSuccess() {
|
||||
waiting = false;
|
||||
}
|
||||
|
||||
public void startSignUp(String email, String password) throws AuthException {
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
@@ -124,6 +129,11 @@ public class AuthManager {
|
||||
throwIfAuthError();
|
||||
}
|
||||
|
||||
public void deleteUser(Requestor requestor) {
|
||||
requestor.deleteObject("N/A", User.class);
|
||||
Amplify.Auth.signOut(this::signOutSuccess, error -> setAuthError(error));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Properties loadProperties(Context context, String path) throws IOException, JSONException {
|
||||
|
||||
@@ -14,8 +14,8 @@ import androidx.navigation.ui.AppBarConfiguration;
|
||||
import androidx.navigation.ui.NavigationUI;
|
||||
import com.amplifyframework.auth.AuthException;
|
||||
import com.example.listify.data.Item;
|
||||
import com.example.listify.data.ListEntry;
|
||||
import com.example.listify.data.List;
|
||||
import com.example.listify.data.ListEntry;
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
import org.json.JSONException;
|
||||
|
||||
@@ -60,7 +60,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
//------------------------------------------------------------------------------------------//
|
||||
|
||||
|
||||
boolean testAPI = false;
|
||||
boolean testAPI = true;
|
||||
//----------------------------------API Testing---------------------------------------------//
|
||||
|
||||
if (testAPI) {
|
||||
@@ -78,6 +78,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
Requestor requestor = new Requestor(authManager, configs.getProperty("apiKey"));
|
||||
|
||||
authManager.deleteUser(requestor);
|
||||
|
||||
//The name is the only part of this that is used, the rest is generated by the Lambda.
|
||||
List testList = new List(-1, "New List", "user filled by lambda", Instant.now().toEpochMilli());
|
||||
//Everything except addedDate is used for ItemEntry
|
||||
|
||||
@@ -24,20 +24,30 @@ public class Requestor {
|
||||
client = new OkHttpClient();
|
||||
}
|
||||
|
||||
public <T> void getObject(String id, Class<T> classType, Receiver<T> receiver) {
|
||||
getObject(id, classType, receiver, null);
|
||||
}
|
||||
|
||||
public <T> void getListOfIds(Class<T> ofType, Receiver<Integer[]> successHandler, RequestErrorHandler failureHandler) {
|
||||
String getURL = DEV_BASEURL + "/" + ofType.getSimpleName() + "?id=-1";
|
||||
Request postRequest = buildBaseRequest(getURL, "GET", null);
|
||||
launchCall(postRequest, successHandler, Integer[].class, failureHandler);
|
||||
}
|
||||
|
||||
public <T> void getObject(String id, Class<T> classType, Receiver<T> receiver) {
|
||||
getObject(id, classType, receiver, null);
|
||||
}
|
||||
|
||||
public <T> void getObject(String id, Class<T> classType, Receiver<T> successHandler, RequestErrorHandler failureHandler) {
|
||||
String getURL = DEV_BASEURL + "/" + classType.getSimpleName() + "?id=" + id;
|
||||
Request postRequest = buildBaseRequest(getURL, "GET", null);
|
||||
launchCall(postRequest, successHandler, classType, failureHandler);
|
||||
Request getRequest = buildBaseRequest(getURL, "GET", null);
|
||||
launchCall(getRequest, successHandler, classType, failureHandler);
|
||||
}
|
||||
|
||||
public void deleteObject(String id, Class classType) {
|
||||
deleteObject(id, classType, null);
|
||||
}
|
||||
|
||||
public void deleteObject(String id, Class classType, RequestErrorHandler failureHandler) {
|
||||
String deleteURL = DEV_BASEURL + "/" + classType.getSimpleName() + "?id=" + id;
|
||||
Request deleteRequest = buildBaseRequest(deleteURL, "DELETE", "{}");
|
||||
launchCall(deleteRequest, null, classType, failureHandler);
|
||||
}
|
||||
|
||||
public void postObject(Object toPost) throws JSONException {
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.example.listify.data;
|
||||
|
||||
public class User {
|
||||
}
|
||||
Reference in New Issue
Block a user