-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ajout de Swagger et modification de RatingRequest en record
- Loading branch information
1 parent
da3d152
commit 06e54b4
Showing
6 changed files
with
50 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
rating/rating/src/main/java/com/example/rating/config/OpenApiConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 11 additions & 9 deletions
20
rating/rating/src/main/java/com/example/rating/mapper/RatingMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
66 changes: 11 additions & 55 deletions
66
rating/rating/src/main/java/com/example/rating/request/RatingRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters