complete group resources
This commit is contained in:
parent
4b3b307d6d
commit
b597bdb255
@ -26,7 +26,7 @@ import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import com.covas.Entity.EventEntity;
|
||||
import com.covas.Entity.GroupEntity;
|
||||
import com.covas.Entity.UsersEntity;
|
||||
|
||||
import io.quarkus.panache.common.Page;
|
||||
@ -88,18 +88,18 @@ public class GroupRessources {
|
||||
Response.Status statusHttp = getResponseCheck(ctx, userCookie, user);
|
||||
Response responseHttp = Response.status(statusHttp).build();
|
||||
if (statusHttp.equals(Response.Status.OK)) {
|
||||
List<EventEntity> listEvents = EventEntity.findAll().page(Page.of(page, nbPages)).list();
|
||||
List<GroupEntity> listGroups = GroupEntity.findAll().page(Page.of(page, nbPages)).list();
|
||||
|
||||
|
||||
responseHttp = Response.ok(listEvents).build();
|
||||
responseHttp = Response.ok(listGroups).build();
|
||||
if(uuid != null){
|
||||
EventEntity eventSingle= EventEntity.findById(new ObjectId(uuid));
|
||||
responseHttp = Response.ok(eventSingle).build();
|
||||
GroupEntity groupSingle= GroupEntity.findById(new ObjectId(uuid));
|
||||
responseHttp = Response.ok(groupSingle).build();
|
||||
}
|
||||
|
||||
if(search != null){
|
||||
List<EventEntity> eventsList = EventEntity.find("name", search).page(Page.of(page, nbPages)).list();
|
||||
responseHttp = Response.ok(eventsList).build();
|
||||
List<GroupEntity> groupsList = GroupEntity.find("name", search).page(Page.of(page, nbPages)).list();
|
||||
responseHttp = Response.ok(groupsList).build();
|
||||
}
|
||||
}
|
||||
return responseHttp;
|
||||
@ -114,7 +114,7 @@ public class GroupRessources {
|
||||
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||
Response responseHttp = Response.status(status).build();
|
||||
if (status.equals(Response.Status.OK)){
|
||||
responseHttp = Response.ok(EventEntity.count()).build();
|
||||
responseHttp = Response.ok(GroupEntity.count()).build();
|
||||
}
|
||||
return responseHttp;
|
||||
}
|
||||
@ -129,10 +129,10 @@ public class GroupRessources {
|
||||
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||
Response responseHttp = Response.status(status).build();
|
||||
if (status.equals(Response.Status.OK)) {
|
||||
EventEntity event = EventEntity.findById(new ObjectId(id));
|
||||
GroupEntity group = GroupEntity.findById(new ObjectId(id));
|
||||
responseHttp = Response.status(Response.Status.NOT_FOUND).build();
|
||||
if (event != null) {
|
||||
responseHttp = Response.ok(event).build();
|
||||
if (group != null) {
|
||||
responseHttp = Response.ok(group).build();
|
||||
}
|
||||
|
||||
}
|
||||
@ -146,23 +146,22 @@ public class GroupRessources {
|
||||
@RolesAllowed({"Admin", "User"})
|
||||
@Path("{id}")
|
||||
@Transactional
|
||||
public Response createEvent(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id, EventEntity event) {
|
||||
public Response createEvent(@Context SecurityContext ctx, @CookieParam("user") String userCookie, @PathParam("id") String id, GroupEntity group) {
|
||||
|
||||
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
|
||||
UsersEntity user = UsersEntity.findById(kid);
|
||||
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||
EventEntity newEvent = new EventEntity();
|
||||
GroupEntity newGroup = new GroupEntity();
|
||||
if (status.equals(Response.Status.OK)) {
|
||||
newEvent.name = event.name;
|
||||
newEvent.address = event.address;
|
||||
newEvent.organisateurs = event.organisateurs;
|
||||
newEvent.created_at = LocalDateTime.now();
|
||||
newEvent.updated_at = LocalDateTime.now();
|
||||
newEvent.persist();
|
||||
newGroup.name = group.name;
|
||||
newGroup.admins = group.admins;
|
||||
newGroup.created_at = LocalDateTime.now();
|
||||
newGroup.updated_at = LocalDateTime.now();
|
||||
newGroup.persist();
|
||||
status = Response.Status.CREATED;
|
||||
|
||||
}
|
||||
return Response.status(status).entity(newEvent).build();
|
||||
return Response.status(status).entity(newGroup).build();
|
||||
}
|
||||
|
||||
|
||||
@ -177,14 +176,14 @@ public class GroupRessources {
|
||||
UsersEntity user = UsersEntity.findById(kid);
|
||||
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||
if (status.equals(Response.Status.OK)) {
|
||||
EventEntity singleEvent = EventEntity.find("id", new ObjectId(id)).firstResult();
|
||||
if (singleEvent == null) {
|
||||
GroupEntity singleGroup = GroupEntity.find("id", new ObjectId(id)).firstResult();
|
||||
if (singleGroup == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
singleEvent.status = -1;
|
||||
singleEvent.updated_at = LocalDateTime.now();
|
||||
singleEvent.deleted_at = LocalDateTime.now();
|
||||
singleEvent.persist();
|
||||
singleGroup.status = -1;
|
||||
singleGroup.updated_at = LocalDateTime.now();
|
||||
singleGroup.deleted_at = LocalDateTime.now();
|
||||
singleGroup.persist();
|
||||
}
|
||||
}
|
||||
return Response.status(status).build();
|
||||
@ -200,14 +199,14 @@ public class GroupRessources {
|
||||
UsersEntity user = UsersEntity.findById(kid);
|
||||
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||
if (status.equals(Response.Status.OK)) {
|
||||
EventEntity singleEvent = EventEntity.find("id", new ObjectId(id)).firstResult();
|
||||
if (singleEvent == null) {
|
||||
GroupEntity singleGroup = GroupEntity.find("id", new ObjectId(id)).firstResult();
|
||||
if (singleGroup == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
singleEvent.status = 0;
|
||||
singleEvent.updated_at = LocalDateTime.now();
|
||||
singleEvent.deleted_at = LocalDateTime.now();
|
||||
singleEvent.persist();
|
||||
singleGroup.status = 0;
|
||||
singleGroup.updated_at = LocalDateTime.now();
|
||||
singleGroup.deleted_at = LocalDateTime.now();
|
||||
singleGroup.persist();
|
||||
}
|
||||
}
|
||||
return Response.status(status).build();
|
||||
@ -220,27 +219,27 @@ public class GroupRessources {
|
||||
@Transactional
|
||||
@Path("{id}")
|
||||
public Response updateEvent(@Context SecurityContext ctx, @CookieParam("user") String userCookie,
|
||||
EventEntity event, @PathParam("id") String id) {
|
||||
GroupEntity group, @PathParam("id") String id) {
|
||||
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
|
||||
UsersEntity user = UsersEntity.findById(kid);
|
||||
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||
|
||||
if (status.equals(Response.Status.OK)) {
|
||||
|
||||
EventEntity eventOrig = EventEntity.findById(new ObjectId(id));
|
||||
if (eventOrig == null) {
|
||||
GroupEntity groupOrig = GroupEntity.findById(new ObjectId(id));
|
||||
if (groupOrig == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
eventOrig.name = event.name;
|
||||
groupOrig.name = group.name;
|
||||
|
||||
|
||||
eventOrig.updated_at = LocalDateTime.now();
|
||||
groupOrig.updated_at = LocalDateTime.now();
|
||||
|
||||
if(event.status == 1){
|
||||
eventOrig.deleted_at = null;
|
||||
eventOrig.status = 1;
|
||||
if(group.status == 1){
|
||||
groupOrig.deleted_at = null;
|
||||
groupOrig.status = 1;
|
||||
}
|
||||
eventOrig.persist();
|
||||
groupOrig.persist();
|
||||
|
||||
}
|
||||
}
|
||||
@ -260,12 +259,12 @@ public class GroupRessources {
|
||||
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||
if (status.equals(Response.Status.OK)) {
|
||||
|
||||
EventEntity eventOrig = EventEntity.findById(new ObjectId(id));
|
||||
if (eventOrig == null) {
|
||||
GroupEntity groupOrig = GroupEntity.findById(new ObjectId(id));
|
||||
if (groupOrig == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
eventOrig.status = 1;
|
||||
eventOrig.persist();
|
||||
groupOrig.status = 1;
|
||||
groupOrig.persist();
|
||||
}
|
||||
}
|
||||
return Response.status(status).build();
|
||||
|
Loading…
x
Reference in New Issue
Block a user