Skip to content

Commit

Permalink
Add user ID parameter to address management endpoints and update data…
Browse files Browse the repository at this point in the history
…base configuration
  • Loading branch information
amine20akka committed Dec 29, 2024
1 parent 8aab01a commit 335aa0c
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 43 deletions.
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ services:
POSTGRES_PASSWORD: azerty
ports:
- 5441:5432
db_shipping:
image: pgvector/pgvector:pg15
environment:
POSTGRES_DB: db_shipping
POSTGRES_USER: postgres
POSTGRES_PASSWORD: azerty
ports:
- 5442:5432
# mongo_example:
# image: mongo:4.4
# environment:
Expand Down
Binary file removed shipping-ci-cd.yml
Binary file not shown.
10 changes: 6 additions & 4 deletions shipping/src/main/java/org/shipping/api/AddressResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ public class AddressResource {

// Ajouter une adresse pour un utilisateur
@POST
@Path("/add")
@Path("/add/{userId}")
@Transactional
public Response addAddress(@Valid AddressDTO addressDTO) {
public Response addAddress(@Valid AddressDTO addressDTO, @PathParam("userId") UUID userId) {
try {
Address createdAddress = addressService.addAddress(
userId,
addressDTO.getStreet(),
addressDTO.getPostalCode(),
addressDTO.getCity(),
Expand All @@ -60,9 +61,10 @@ public Response addAddress(@Valid AddressDTO addressDTO) {

// Trouver les adresses de l'utilisateur courant
@GET
public Response getUserAddresses() {
@Path("/{userId}")
public Response getUserAddresses(UUID userId) {
try {
List<Address> addresses = addressService.getAddressesByUserId();
List<Address> addresses = addressService.getAddressesByUserId(userId);
return Response.ok(addresses).build();

} catch (IllegalArgumentException e) {
Expand Down
12 changes: 2 additions & 10 deletions shipping/src/main/java/org/shipping/service/AddressService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ public class AddressService {
@Inject
AddressRepository addressRepository;

// @Inject
// SecurityService securityService;

@Inject
AddressEventPublisher eventPublisher;

Expand Down Expand Up @@ -57,17 +54,14 @@ public Address getAddressById(UUID addressId) {

// Ajouter une adresse pour un utilisateur
@Transactional
public Address addAddress(String street, String postalCode, String city, String country) {
public Address addAddress(UUID userId, String street, String postalCode, String city, String country) {
try {
// Validation des champs
if (street == null || postalCode == null || city == null || country == null) {
throw new IllegalArgumentException(
"All address fields (street, postal code, city, country) must be provided.");
}

// UUID utilisateur simulé pour le moment
UUID userId = UUID.fromString("faa1b47d-27e3-4106-b42b-2d1e7d1f6e93");

// Vérifier si l'adresse existe déjà pour l'utilisateur
boolean addressExists = addressRepository
.find("userId = ?1 AND street = ?2 AND postalCode = ?3 AND city = ?4 AND country = ?5",
Expand Down Expand Up @@ -98,10 +92,8 @@ public Address addAddress(String street, String postalCode, String city, String
}

// Trouver les adresses d'un utilisateur
public List<Address> getAddressesByUserId() {
public List<Address> getAddressesByUserId(UUID userId) {
try {
// UUID userId = securityService.getCurrentUserId();
UUID userId = UUID.fromString("faa1b47d-27e3-4106-b42b-2d1e7d1f6e93"); // Simulé pour le moment
if (userId == null) {
throw new IllegalArgumentException("User ID could not be extracted from the token.");
}
Expand Down
18 changes: 0 additions & 18 deletions shipping/src/main/java/org/shipping/service/SecurityService.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ public class ShippingService {
@Inject
AddressService addressService;

@Inject
SecurityService securityService;

@Inject
DeliveryStatusPublisher statusPublisher;

Expand Down
9 changes: 1 addition & 8 deletions shipping/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,12 @@ quarkus.datasource.password=azerty
quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5442/db_shipping

# drop and create the database at startup (use `update` to only update the schema)
quarkus.hibernate-orm.database.generation=create
quarkus.hibernate-orm.database.generation=update
%dev.quarkus.hibernate-orm.log.sql=true
%dev.quarkus.hibernate-orm.log.format-sql=true
%dev.quarkus.hibernate-orm.statistics=true
quarkus.http.limits.max-form-attribute-size=4M

# Enable security
# quarkus.security.enabled=true
# Configure JWT
# mp.jwt.verify.publickey.location=https://example.com/iam/publicKey
# mp.jwt.verify.issuer=https://example.com/iam
# mp.jwt.token.header=Authorization

quarkus.kafka.devservices.enabled=false
# S'abonner à un Broker Kafka pour l'event "order-paid"
mp.messaging.incoming.order-paid.connector=smallrye-kafka
Expand Down

0 comments on commit 335aa0c

Please sign in to comment.