add GET for profile
This commit is contained in:
parent
36cf9f5631
commit
df15b0d19e
15
src/main/java/com/covas/Json/ProfileSingle.java
Normal file
15
src/main/java/com/covas/Json/ProfileSingle.java
Normal file
@ -0,0 +1,15 @@
|
||||
package com.covas.Json;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
public class ProfileSingle {
|
||||
|
||||
public final String description;
|
||||
|
||||
public ProfileSingle(String description){
|
||||
this.description = description;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,17 +1,28 @@
|
||||
package com.covas.Resources;
|
||||
|
||||
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.core.SecurityContext;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.core.SecurityContext;
|
||||
import javax.ws.rs.CookieParam;
|
||||
import javax.ws.rs.core.Context;
|
||||
import org.eclipse.microprofile.jwt.JsonWebToken;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
import org.eclipse.microprofile.jwt.Claims;
|
||||
|
||||
import com.covas.Json.ProfileSingle;
|
||||
|
||||
|
||||
import org.postgresql.shaded.com.ongres.scram.common.bouncycastle.base64.Base64;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import com.covas.Entity.UsersEntity;
|
||||
import com.covas.Entity.ProfilEntity;
|
||||
import javax.ws.rs.Path;
|
||||
|
||||
|
||||
@ -45,5 +56,60 @@ public class ProfileRessources {
|
||||
return Response.Status.OK;
|
||||
}
|
||||
|
||||
// GET
|
||||
|
||||
@GET
|
||||
@RolesAllowed("Admin")
|
||||
@Path("{id}")
|
||||
public Response getSingleProfile(@PathParam("id") String id, @CookieParam("user") String userCookie,
|
||||
@Context SecurityContext ctx) {
|
||||
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
|
||||
UsersEntity user = UsersEntity.findById(kid);
|
||||
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||
Response responseHttp = Response.status(status).build();
|
||||
if (status.equals(Response.Status.OK)) {
|
||||
UUID uid = UUID.fromString(id);
|
||||
UsersEntity users = UsersEntity.findById(uid);
|
||||
ProfilEntity profile = users.profile;
|
||||
responseHttp = Response.status(Response.Status.NOT_FOUND).build();
|
||||
if (profile != null) {
|
||||
responseHttp = Response.ok(users).build();
|
||||
}
|
||||
|
||||
}
|
||||
return responseHttp;
|
||||
}
|
||||
|
||||
@GET
|
||||
@RolesAllowed("User")
|
||||
public Response getInfoProfile(@Context SecurityContext ctx, @CookieParam("user") String userCookie) {
|
||||
UUID kid = UUID.fromString(jwt.getClaim(Claims.kid));
|
||||
UsersEntity user = UsersEntity.findById(kid);
|
||||
String description = "";
|
||||
Response.Status status = getResponseCheck(ctx, userCookie, user);
|
||||
if (status.equals(Response.Status.OK)) {
|
||||
if (user == null) {
|
||||
status = Response.Status.NOT_FOUND;
|
||||
}
|
||||
if (!checkUserCookie(userCookie, user)) {
|
||||
status = Response.Status.FORBIDDEN;
|
||||
}
|
||||
if (user != null){
|
||||
ProfilEntity profile = user.profile;
|
||||
if(profile == null){
|
||||
status = Response.Status.NOT_FOUND;
|
||||
} else {
|
||||
description = profile.description;
|
||||
}
|
||||
}
|
||||
}
|
||||
Response responseHttp = Response.status(status).build();
|
||||
if (status.equals(Response.Status.OK)) {
|
||||
responseHttp = Response.status(status).entity(new ProfileSingle(description))
|
||||
.build();
|
||||
}
|
||||
return responseHttp;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user