Skip to content

Commit

Permalink
Ajout de Swagger et modification de RatingRequest en record
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeifatma committed Dec 24, 2024
1 parent da3d152 commit 06e54b4
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 68 deletions.
5 changes: 5 additions & 0 deletions rating/rating/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.2.0</version>
</dependency>



Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.rating.config;

import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.OpenAPI;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OpenApiConfig {

@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI()
.info(new Info()
.title("API E-commerce")
.version("1.0")
.description("Documentation pour le projet SOA E-commerce"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ public List<Rating> getRatingsForProduct(@PathVariable Long idProduit) {
public List<Rating> getRatingsForUser(@PathVariable Long idUser) {
return ratingService.getRatingsForUser(idUser);
}

}
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package com.example.rating.mapper;

import com.example.rating.model.Rating;
import com.example.rating.request.RatingRequest;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Service
public class RatingMapper {


/**
* Méthode pour mapper un RatingRequest (record) à une entité Rating.
*
* @param ratingRequest l'objet RatingRequest contenant les données de la requête.
* @return l'entité Rating.
*/
public Rating mapRequestToEntity(RatingRequest ratingRequest) {
Rating rating = new Rating();
rating.setIdUser(ratingRequest.getIdUser());
rating.setIdProduit(ratingRequest.getIdProduit());
rating.setNote(ratingRequest.getNote());
// Si la classe Rating inclut un champ pour les commentaires
if (ratingRequest.getCommentaire() != null) {
// Ajouter le commentaire si nécessaire
}
rating.setIdUser(ratingRequest.idUser());
rating.setIdProduit(ratingRequest.idProduit());
rating.setNote(ratingRequest.note());

return rating;
}
}
Original file line number Diff line number Diff line change
@@ -1,65 +1,21 @@
package com.example.rating.request;

import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;

public class RatingRequest {

@NotNull(message = "L'ID de l'utilisateur ne peut pas être null.")
private Long idUser;

@NotNull(message = "L'ID du produit ne peut pas être null.")
private Long idProduit;

@NotNull(message = "La note est obligatoire.")
@Min(value = 1, message = "La note doit être au moins 1.")
@Max(value = 5, message = "La note ne peut pas dépasser 5.")
private Integer note;

@Size(max = 255, message = "Le commentaire ne peut pas dépasser 255 caractères.")
private String commentaire;

// Getters et setters
public Long getIdUser() {
return idUser;
}

public void setIdUser(Long idUser) {
this.idUser = idUser;
}

public Long getIdProduit() {
return idProduit;
}

public void setIdProduit(Long idProduit) {
this.idProduit = idProduit;
}

public Integer getNote() {
return note;
}

public void setNote(Integer note) {
this.note = note;
}

public String getCommentaire() {
return commentaire;
}
public record RatingRequest(
@NotNull(message = "L'ID de l'utilisateur ne peut pas être null.")
Long idUser,

public void setCommentaire(String commentaire) {
this.commentaire = commentaire;
}
@NotNull(message = "L'ID du produit ne peut pas être null.")
Long idProduit,

@Override
public String toString() {
return "RatingRequest{" +
"idUser=" + idUser +
", idProduit=" + idProduit +
", note=" + note +
", commentaire='" + commentaire + '\'' +
'}';
}
@NotNull(message = "La note est obligatoire.")
@Min(value = 1, message = "La note doit être au moins 1.")
@Max(value = 5, message = "La note ne peut pas dépasser 5.")
Integer note
) {
}
7 changes: 3 additions & 4 deletions rating/rating/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@
server.port=8088
spring.application.name=rating-service

# Configuration de la base de données PostgreSQL

spring.datasource.url=jdbc:postgresql://localhost:5440/db_rating
spring.datasource.username=postgres
spring.datasource.password=azerty
spring.datasource.driver-class-name=org.postgresql.Driver

# Configuration JPA/Hibernate

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

# Swagger/OpenAPI (via Springdoc)

springdoc.api-docs.path=/openapi
springdoc.swagger-ui.path=/swagger-ui

# Journalisation (développement uniquement)
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE

0 comments on commit 06e54b4

Please sign in to comment.