/account/admin DELETE
This commit is contained in:
@@ -14,7 +14,9 @@ public class ControllerPathConfig {
|
|||||||
|
|
||||||
//AccountController
|
//AccountController
|
||||||
public static final String ACCOUNT_BASE = "/account";
|
public static final String ACCOUNT_BASE = "/account";
|
||||||
|
|
||||||
public static final String ACCOUNT_BASE_ALL = "/account/all";
|
public static final String ACCOUNT_BASE_ALL = "/account/all";
|
||||||
|
public static final String ACCOUNT_ADMIN = "/account/admin";
|
||||||
|
|
||||||
public static final String EMAIL_BASE = "/email";
|
public static final String EMAIL_BASE = "/email";
|
||||||
|
|
||||||
|
|||||||
@@ -93,6 +93,22 @@ public class AccountController {
|
|||||||
return ResponseEntity.ok().build();
|
return ResponseEntity.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(path = ACCOUNT_ADMIN, method = RequestMethod.DELETE, produces = "application/json")
|
||||||
|
public ResponseEntity<Boolean> deleteAccount(HttpServletRequest request,
|
||||||
|
@RequestParam(PARAM_EMAIL) String email,
|
||||||
|
@RequestParam(PARAM_PASSWORD) UUID token,
|
||||||
|
@RequestParam(PARAM_ID) Long accountId) {
|
||||||
|
logRequest(request);
|
||||||
|
if (!sessionService.isAdmin(token, email)) {
|
||||||
|
log.warn("Invalid session requesting Admin {}", token);
|
||||||
|
return ResponseEntity.status(403).build();
|
||||||
|
}
|
||||||
|
if(!accountService.deleteIfExists(accountId)) {
|
||||||
|
return ResponseEntity.badRequest().build();
|
||||||
|
}
|
||||||
|
return ResponseEntity.ok();
|
||||||
|
}
|
||||||
|
|
||||||
@RequestMapping(path = ACCOUNT_BASE, method = RequestMethod.GET, produces = "application/json")
|
@RequestMapping(path = ACCOUNT_BASE, method = RequestMethod.GET, produces = "application/json")
|
||||||
public ResponseEntity<Account> getAccount(HttpServletRequest request,
|
public ResponseEntity<Account> getAccount(HttpServletRequest request,
|
||||||
@RequestParam(PARAM_EMAIL) String email,
|
@RequestParam(PARAM_EMAIL) String email,
|
||||||
|
|||||||
@@ -9,4 +9,6 @@ public interface AccountRepository extends JpaRepository<Account, Long> {
|
|||||||
Account getAccountByEmail(String email);
|
Account getAccountByEmail(String email);
|
||||||
|
|
||||||
boolean existsAccountByEmail(String email);
|
boolean existsAccountByEmail(String email);
|
||||||
|
|
||||||
|
Account getAccountById(Long id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ public interface AccountService {
|
|||||||
|
|
||||||
boolean deleteIfExists(Account account);
|
boolean deleteIfExists(Account account);
|
||||||
|
|
||||||
|
boolean deleteIfExists(Long id);
|
||||||
|
|
||||||
Account isValidLogin(String email, String password);
|
Account isValidLogin(String email, String password);
|
||||||
|
|
||||||
boolean existsWithEmail(String email);
|
boolean existsWithEmail(String email);
|
||||||
|
|||||||
@@ -53,6 +53,16 @@ public class AccountServiceImpl implements AccountService {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteIfExists(Long id) {
|
||||||
|
Account tbd = accountRepository.getAccountById(id);
|
||||||
|
if (tbd == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
accountRepository.delete(tbd);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Account isValidLogin(String email, String password) {
|
public Account isValidLogin(String email, String password) {
|
||||||
Account acc = accountRepository.getAccountByEmail(email);
|
Account acc = accountRepository.getAccountByEmail(email);
|
||||||
|
|||||||
Reference in New Issue
Block a user