mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
delete users
This commit is contained in:
@@ -16,7 +16,7 @@ import com.uaihebert.model.EasyCriteria;
|
||||
|
||||
@Stateless
|
||||
@SuppressWarnings("serial")
|
||||
public class FeedCategoryService extends GenericDAO<FeedCategory, Long> {
|
||||
public class FeedCategoryService extends GenericDAO<FeedCategory> {
|
||||
|
||||
public List<FeedCategory> findAll(User user) {
|
||||
return findByField(MF.i(MF.p(FeedCategory.class).getUser()), user);
|
||||
|
||||
@@ -23,7 +23,7 @@ import com.google.common.collect.Lists;
|
||||
|
||||
@Stateless
|
||||
@SuppressWarnings("serial")
|
||||
public class FeedEntryService extends GenericDAO<FeedEntry, Long> {
|
||||
public class FeedEntryService extends GenericDAO<FeedEntry> {
|
||||
|
||||
@Inject
|
||||
FeedService feedService;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.commafeed.backend.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Stateless;
|
||||
import javax.persistence.NoResultException;
|
||||
|
||||
@@ -12,7 +14,11 @@ import com.uaihebert.model.EasyCriteria;
|
||||
|
||||
@Stateless
|
||||
@SuppressWarnings("serial")
|
||||
public class FeedEntryStatusService extends GenericDAO<FeedEntryStatus, Long> {
|
||||
public class FeedEntryStatusService extends GenericDAO<FeedEntryStatus> {
|
||||
|
||||
public List<FeedEntryStatus> findAll(User user) {
|
||||
return findByField(MF.i(proxy().getUser()), user);
|
||||
}
|
||||
|
||||
public FeedEntryStatus getStatus(User user, FeedEntry entry) {
|
||||
EasyCriteria<FeedEntryStatus> criteria = EasyCriteriaFactory
|
||||
|
||||
@@ -10,7 +10,7 @@ import com.google.common.collect.Iterables;
|
||||
|
||||
@Stateless
|
||||
@SuppressWarnings("serial")
|
||||
public class FeedService extends GenericDAO<Feed, Long> {
|
||||
public class FeedService extends GenericDAO<Feed> {
|
||||
|
||||
public Feed findByUrl(String url) {
|
||||
List<Feed> feeds = findByField(MF.i(proxy().getUrl()), url);
|
||||
|
||||
@@ -15,7 +15,7 @@ import com.uaihebert.model.EasyCriteria;
|
||||
|
||||
@Stateless
|
||||
@SuppressWarnings("serial")
|
||||
public class FeedSubscriptionService extends GenericDAO<FeedSubscription, Long> {
|
||||
public class FeedSubscriptionService extends GenericDAO<FeedSubscription> {
|
||||
|
||||
@Inject
|
||||
FeedCategoryService feedCategoryService;
|
||||
|
||||
@@ -17,7 +17,8 @@ import com.uaihebert.factory.EasyCriteriaFactory;
|
||||
import com.uaihebert.model.EasyCriteria;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public abstract class GenericDAO<T, K> implements Serializable {
|
||||
public abstract class GenericDAO<T extends AbstractModel> implements
|
||||
Serializable {
|
||||
|
||||
private TypeToken<T> type = new TypeToken<T>(getClass()) {
|
||||
};
|
||||
@@ -55,12 +56,18 @@ public abstract class GenericDAO<T, K> implements Serializable {
|
||||
em.remove(object);
|
||||
}
|
||||
|
||||
public void deleteById(K id) {
|
||||
public void delete(List<T> objects) {
|
||||
for (T object : objects) {
|
||||
delete(object);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteById(Long id) {
|
||||
Object ref = em.getReference(getType(), id);
|
||||
em.remove(ref);
|
||||
}
|
||||
|
||||
public T findById(K id) {
|
||||
public T findById(Long id) {
|
||||
T t = em.find(getType(), id);
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import com.google.common.collect.Sets;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@Stateless
|
||||
public class UserRoleService extends GenericDAO<UserRole, Long> {
|
||||
public class UserRoleService extends GenericDAO<UserRole> {
|
||||
|
||||
public List<UserRole> findAll(User user) {
|
||||
return findByField(MF.i(MF.p(UserRole.class).getUser()), user);
|
||||
|
||||
@@ -15,7 +15,7 @@ import com.google.common.collect.Iterables;
|
||||
|
||||
@Stateless
|
||||
@SuppressWarnings("serial")
|
||||
public class UserService extends GenericDAO<User, Long> {
|
||||
public class UserService extends GenericDAO<User> {
|
||||
|
||||
@Inject
|
||||
PasswordEncryptionService encryptionService;
|
||||
|
||||
@@ -11,7 +11,7 @@ import com.uaihebert.model.EasyCriteria;
|
||||
|
||||
@Stateless
|
||||
@SuppressWarnings("serial")
|
||||
public class UserSettingsService extends GenericDAO<UserSettings, Long> {
|
||||
public class UserSettingsService extends GenericDAO<UserSettings> {
|
||||
|
||||
public UserSettings findByUser(User user) {
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
@@ -110,4 +111,21 @@ public class AdminUsersREST extends AbstractREST {
|
||||
}
|
||||
return users.values();
|
||||
}
|
||||
|
||||
@Path("delete")
|
||||
@DELETE
|
||||
public Response delete(@QueryParam("id") Long id) {
|
||||
User user = userService.findById(id);
|
||||
if (user == null) {
|
||||
return Response.status(Status.NOT_FOUND).build();
|
||||
}
|
||||
feedEntryStatusService.delete(feedEntryStatusService.findAll(user));
|
||||
feedSubscriptionService.delete(feedSubscriptionService.findAll(user));
|
||||
feedCategoryService.delete(feedCategoryService.findAll(user));
|
||||
userSettingsService.delete(userSettingsService.findByUser(user));
|
||||
userRoleService.delete(userRoleService.findAll(user));
|
||||
userService.delete(user);
|
||||
|
||||
return Response.ok().build();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user