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