Skip to content

Commit fdea0aa

Browse files
fix: Locations fixed. (#136)
1 parent 1585b13 commit fdea0aa

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

src/main/java/it/pagopa/swclient/mil/auth/admin/resource/ClientResource.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
*/
66
package it.pagopa.swclient.mil.auth.admin.resource;
77

8+
import java.net.URI;
89
import java.util.List;
910
import java.util.UUID;
1011

12+
import org.eclipse.microprofile.config.inject.ConfigProperty;
13+
1114
import com.mongodb.MongoWriteException;
1215

1316
import io.quarkus.logging.Log;
@@ -43,11 +46,9 @@
4346
import jakarta.ws.rs.PathParam;
4447
import jakarta.ws.rs.Produces;
4548
import jakarta.ws.rs.WebApplicationException;
46-
import jakarta.ws.rs.core.Context;
4749
import jakarta.ws.rs.core.MediaType;
4850
import jakarta.ws.rs.core.Response;
4951
import jakarta.ws.rs.core.Response.Status;
50-
import jakarta.ws.rs.core.UriInfo;
5152

5253
/**
5354
*
@@ -59,6 +60,12 @@
5960
"mil-auth-admin"
6061
})
6162
public class ClientResource {
63+
/*
64+
* mil-auth base URL.
65+
*/
66+
@ConfigProperty(name = "base-url", defaultValue = "")
67+
String baseUrl;
68+
6269
/*
6370
*
6471
*/
@@ -121,12 +128,11 @@ private WebApplicationException onPersistError(Throwable t) {
121128
/**
122129
*
123130
* @param req
124-
* @param uriInfo
125131
* @return
126132
*/
127133
@POST
128134
@Consumes(MediaType.APPLICATION_JSON)
129-
public Uni<Response> create(@Valid CreateOrUpdateClientRequest req, @Context UriInfo uriInfo) {
135+
public Uni<Response> create(@Valid CreateOrUpdateClientRequest req) {
130136
Log.tracef("Create a new client: %s", req.toString());
131137

132138
/*
@@ -158,11 +164,7 @@ public Uni<Response> create(@Valid CreateOrUpdateClientRequest req, @Context Uri
158164
.map(e -> {
159165
CreateClientResponse res = new CreateClientResponse(clientId, triplet.getSecret());
160166
Log.debugf("Client created successfully: %s", res.toString());
161-
return Response.created(
162-
uriInfo
163-
.getAbsolutePathBuilder()
164-
.path(clientId)
165-
.build())
167+
return Response.created(URI.create(baseUrl + "/admin/clients/" + clientId))
166168
.entity(res)
167169
.build();
168170
})

src/main/java/it/pagopa/swclient/mil/auth/admin/resource/RolesResource.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
*/
66
package it.pagopa.swclient.mil.auth.admin.resource;
77

8+
import java.net.URI;
89
import java.util.List;
910
import java.util.UUID;
1011

12+
import org.eclipse.microprofile.config.inject.ConfigProperty;
13+
1114
import com.mongodb.MongoWriteException;
1215

1316
import io.quarkus.logging.Log;
@@ -41,11 +44,9 @@
4144
import jakarta.ws.rs.PathParam;
4245
import jakarta.ws.rs.Produces;
4346
import jakarta.ws.rs.WebApplicationException;
44-
import jakarta.ws.rs.core.Context;
4547
import jakarta.ws.rs.core.MediaType;
4648
import jakarta.ws.rs.core.Response;
4749
import jakarta.ws.rs.core.Response.Status;
48-
import jakarta.ws.rs.core.UriInfo;
4950

5051
/**
5152
* <p>
@@ -60,6 +61,12 @@
6061
"mil-auth-admin"
6162
})
6263
public class RolesResource {
64+
/*
65+
* mil-auth base URL.
66+
*/
67+
@ConfigProperty(name = "base-url", defaultValue = "")
68+
String baseUrl;
69+
6370
/**
6471
* <p>
6572
* Repository of roles entities.
@@ -121,12 +128,11 @@ private WebApplicationException onPersistError(Throwable t) {
121128
/**
122129
*
123130
* @param req
124-
* @param uriInfo
125131
* @return
126132
*/
127133
@POST
128134
@Consumes(MediaType.APPLICATION_JSON)
129-
public Uni<Response> create(@Valid CreateOrUpdateSetOfRolesRequest req, @Context UriInfo uriInfo) {
135+
public Uni<Response> create(@Valid CreateOrUpdateSetOfRolesRequest req) {
130136
Log.tracef("Create a new list of roles: %s", req.toString());
131137

132138
String id = UUID.randomUUID().toString();
@@ -146,11 +152,7 @@ public Uni<Response> create(@Valid CreateOrUpdateSetOfRolesRequest req, @Context
146152
req.getRoles());
147153

148154
return repository.persist(entity)
149-
.map(e -> Response.created(
150-
uriInfo.getAbsolutePathBuilder()
151-
.path(id)
152-
.build())
153-
.build())
155+
.map(e -> Response.created(URI.create(baseUrl + "/admin/roles/" + id)).build())
154156
.invoke(() -> Log.debug("List of roles created successfully"))
155157
.onFailure().transform(this::onPersistError);
156158
}

0 commit comments

Comments
 (0)