fix partey tags
This commit is contained in:
@@ -40,9 +40,9 @@ public class ParteyUserTagManager implements UserDataProvider {
|
||||
/**
|
||||
* Gets the all.
|
||||
*
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param sortBy the sort by
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param sortBy the sort by
|
||||
* @param descending the descending
|
||||
* @return the all
|
||||
*/
|
||||
@@ -60,11 +60,8 @@ public class ParteyUserTagManager implements UserDataProvider {
|
||||
* @return the all by user id
|
||||
*/
|
||||
public List<ParteyUserTag> getAllByUserId(Long userId) {
|
||||
User user = userManager.get(userId);
|
||||
Assert.notNull(user, "invalid userId: '"
|
||||
+ userId
|
||||
+ "'!");
|
||||
return getAllForUsername(user.getUsername());
|
||||
return Lists
|
||||
.newArrayList(parteyUserTagRepository.findAll(qParteyUserTag.target.eq(userId)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,16 +77,22 @@ public class ParteyUserTagManager implements UserDataProvider {
|
||||
/**
|
||||
* Gets the non expired by user id.
|
||||
*
|
||||
* @param userId the user id
|
||||
* @param userId the user id
|
||||
* @param upcoming the upcoming
|
||||
* @return the non expired by user id
|
||||
*/
|
||||
public List<ParteyUserTag> getNonExpiredByUserId(Long userId, boolean upcoming) {
|
||||
User user = userManager.get(userId);
|
||||
Assert.notNull(user, "invalid userId: '"
|
||||
+ userId
|
||||
+ "'!");
|
||||
return getNonExpiredForUsername(user.getUsername(), upcoming);
|
||||
BooleanBuilder query = new BooleanBuilder();
|
||||
|
||||
query.and(qParteyUserTag.target.eq(userId));
|
||||
query.and(qParteyUserTag.expires.isNull().or(qParteyUserTag.expires.after(Instant.now())));
|
||||
|
||||
if (!upcoming) {
|
||||
query.and(
|
||||
qParteyUserTag.starts.isNull().or(qParteyUserTag.starts.before(Instant.now())));
|
||||
}
|
||||
|
||||
return Lists.newArrayList(parteyUserTagRepository.findAll(query.getValue()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,8 +102,11 @@ public class ParteyUserTagManager implements UserDataProvider {
|
||||
* @return the all for username
|
||||
*/
|
||||
public List<ParteyUserTag> getAllForUsername(String username) {
|
||||
return Lists.newArrayList(parteyUserTagRepository
|
||||
.findAll(qParteyUserTag.username.equalsIgnoreCase(username)));
|
||||
User user = userManager.getByUsername(username);
|
||||
Assert.notNull(user, "invalid username: '"
|
||||
+ username
|
||||
+ "'!");
|
||||
return getAllByUserId(user.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,6 +116,7 @@ public class ParteyUserTagManager implements UserDataProvider {
|
||||
* @return the non expired for username
|
||||
*/
|
||||
public List<ParteyUserTag> getNonExpiredForUsername(String username) {
|
||||
|
||||
return getNonExpiredForUsername(username, false);
|
||||
}
|
||||
|
||||
@@ -121,18 +128,11 @@ public class ParteyUserTagManager implements UserDataProvider {
|
||||
* @return the non expired for username
|
||||
*/
|
||||
public List<ParteyUserTag> getNonExpiredForUsername(String username, boolean upcoming) {
|
||||
|
||||
BooleanBuilder query = new BooleanBuilder();
|
||||
|
||||
query.and(qParteyUserTag.username.equalsIgnoreCase(username));
|
||||
query.and(qParteyUserTag.expires.isNull().or(qParteyUserTag.expires.after(Instant.now())));
|
||||
|
||||
if (!upcoming) {
|
||||
query.and(
|
||||
qParteyUserTag.starts.isNull().or(qParteyUserTag.starts.before(Instant.now())));
|
||||
}
|
||||
|
||||
return Lists.newArrayList(parteyUserTagRepository.findAll(query.getValue()));
|
||||
User user = userManager.getByUsername(username);
|
||||
Assert.notNull(user, "invalid username: '"
|
||||
+ username
|
||||
+ "'!");
|
||||
return getNonExpiredByUserId(user.getId(), upcoming);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,18 +151,18 @@ public class ParteyUserTagManager implements UserDataProvider {
|
||||
* @param parteyUserTag the partey user tag
|
||||
*/
|
||||
public void delete(ParteyUserTag parteyUserTag) {
|
||||
parteyUserTagRepository.deleteById(
|
||||
new ParteyUserTagId(parteyUserTag.getUsername(), parteyUserTag.getTag()));
|
||||
parteyUserTagRepository
|
||||
.deleteById(new ParteyUserTagId(parteyUserTag.getTarget(), parteyUserTag.getTag()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all for target.
|
||||
*
|
||||
* @param username the username
|
||||
* @param target the target
|
||||
*/
|
||||
public void deleteAllForTarget(String username) {
|
||||
parteyUserTagRepository.deleteAll(parteyUserTagRepository
|
||||
.findAll(qParteyUserTag.username.equalsIgnoreCase(username)));
|
||||
public void deleteAllForTarget(Long target) {
|
||||
parteyUserTagRepository
|
||||
.deleteAll(parteyUserTagRepository.findAll(qParteyUserTag.target.eq(target)));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -187,11 +187,7 @@ public class ParteyUserTagManager implements UserDataProvider {
|
||||
*/
|
||||
@Override
|
||||
public void purgeUserData(Long userId) {
|
||||
User user = userManager.get(userId);
|
||||
Assert.notNull(user, "invalid userId: '"
|
||||
+ userId
|
||||
+ "'!");
|
||||
deleteAllForTarget(user.getUsername());
|
||||
deleteAllForTarget(userId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+13
-2
@@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@@ -56,7 +57,7 @@ public class UserTagManagementController extends BaseController {
|
||||
@RequestParam("desc") Optional<Boolean> descParameter) {
|
||||
|
||||
Page<ParteyUserTag> page = parteyUserTagManager.getAll(pageParameter.orElse(0),
|
||||
sizeParameter.orElse(10), sortParameter.orElse("username"),
|
||||
sizeParameter.orElse(10), sortParameter.orElse("target"),
|
||||
descParameter.orElse(false));
|
||||
|
||||
return page;
|
||||
@@ -128,11 +129,21 @@ public class UserTagManagementController extends BaseController {
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@PostMapping
|
||||
public ParteyUserTag createOrUpdateParteyUserTag(@RequestBody ParteyUserTag parteyUserTag) {
|
||||
User user = userManager.getByUsername(parteyUserTag.getUsername());
|
||||
User user = null;
|
||||
|
||||
if (parteyUserTag.getTarget() != null && !parteyUserTag.getTarget().equals(0L)) {
|
||||
user = userManager.get(parteyUserTag.getTarget());
|
||||
} else if (StringUtils.hasText(parteyUserTag.getUsername())) {
|
||||
user = userManager.getByUsername(parteyUserTag.getUsername());
|
||||
}
|
||||
|
||||
if (user == null) {
|
||||
throw new EntityResponseStatusException(HttpStatus.CONFLICT);
|
||||
}
|
||||
|
||||
parteyUserTag.setTarget(user.getId());
|
||||
parteyUserTag.setUsername(user.getUsername());
|
||||
|
||||
return parteyUserTagManager.save(parteyUserTag);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,30 +24,32 @@ import de.bstly.we.partey.model.ParteyUserTag.ParteyUserTagId;
|
||||
public class ParteyUserTag implements UserData {
|
||||
|
||||
@Id
|
||||
private String username;
|
||||
private Long target;
|
||||
@Id
|
||||
private String tag;
|
||||
@Column(name = "starts", nullable = true)
|
||||
private Instant starts;
|
||||
@Column(name = "expires", nullable = true)
|
||||
private Instant expires;
|
||||
@Column(name = "username", nullable = false)
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* Gets the username.
|
||||
* Gets the target.
|
||||
*
|
||||
* @return the username
|
||||
* @return the target
|
||||
*/
|
||||
public String getUsername() {
|
||||
return username;
|
||||
public Long getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the username.
|
||||
* Sets the target.
|
||||
*
|
||||
* @param username the new username
|
||||
* @param target the new target
|
||||
*/
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
public void setTarget(Long target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,43 +106,69 @@ public class ParteyUserTag implements UserData {
|
||||
this.expires = expires;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the username.
|
||||
*
|
||||
* @return the username
|
||||
*/
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the username.
|
||||
*
|
||||
* @param username the new username
|
||||
*/
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Class ParteyUserTagId.
|
||||
*/
|
||||
public static class ParteyUserTagId implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String username;
|
||||
private Long target;
|
||||
private String tag;
|
||||
|
||||
/**
|
||||
* Instantiates a new partey user tag id.
|
||||
*/
|
||||
public ParteyUserTagId() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param username
|
||||
* @param tag
|
||||
* Instantiates a new partey user tag id.
|
||||
*
|
||||
* @param target the target
|
||||
* @param tag the tag
|
||||
*/
|
||||
public ParteyUserTagId(String username, String tag) {
|
||||
public ParteyUserTagId(Long target, String tag) {
|
||||
super();
|
||||
this.username = username;
|
||||
this.target = target;
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the username.
|
||||
* Gets the target.
|
||||
*
|
||||
* @return the username
|
||||
* @return the target
|
||||
*/
|
||||
public String getUsername() {
|
||||
return username;
|
||||
public Long getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the username.
|
||||
* Sets the target.
|
||||
*
|
||||
* @param username the new username
|
||||
* @param target the new target
|
||||
*/
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
public void setTarget(Long target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -64,16 +64,16 @@ public class TimeslotManager implements UserDataProvider {
|
||||
/**
|
||||
* Gets the.
|
||||
*
|
||||
* @param owner the owner
|
||||
* @param owner the owner
|
||||
* @param invertOwner the invert owner
|
||||
* @param after the after
|
||||
* @param type the type
|
||||
* @param visibility the visibility
|
||||
* @param search the search
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param sortBy the sort by
|
||||
* @param descending the descending
|
||||
* @param after the after
|
||||
* @param type the type
|
||||
* @param visibility the visibility
|
||||
* @param search the search
|
||||
* @param page the page
|
||||
* @param size the size
|
||||
* @param sortBy the sort by
|
||||
* @param descending the descending
|
||||
* @return the page
|
||||
*/
|
||||
public Page<Timeslot> get(Long owner, boolean invertOwner, Instant after, TimeslotType type,
|
||||
|
||||
Reference in New Issue
Block a user