ソースを参照

feat: use records instead of classes for dtos

Mariano Z. 1 年間 前
コミット
72575b1377

+ 1 - 1
Products.Business/Service/ProductService.cs

@@ -68,7 +68,7 @@ public class ProductService : IProductService
     {
         return new ProductDto(
             product.Name,
-            product.Color,
+            product.Color.ToString(),
             product.Brand,
             product.Id
         );

+ 6 - 20
Products.Common/Dtos/ProductDto.cs

@@ -2,23 +2,9 @@ using Products.Common.Types;
 
 namespace Products.Common.Dtos;
 
-public class ProductDto
-{
-    public ProductDto(string name, Color color, string brand, int id)
-    {
-        Name = name;
-        Color = color;
-        Brand = brand;
-        Id = id;
-    }
-    
-    public ProductDto()
-    {
-    }
-    
-
-    public string Name { get; set; }
-    public Color Color { get; set; }
-    public string Brand { get; set; }
-    public int Id { get; set; }
-}
+public record ProductDto(
+        string Name,
+        string Color,
+        string Brand,
+        int Id
+);

+ 7 - 7
Products.Common/Dtos/UpdateProductDto.cs

@@ -1,15 +1,15 @@
 using System.ComponentModel.DataAnnotations;
 using Products.Common.Types;
-
 namespace Products.Common.Dtos;
 
-public class UpdateProductDto
-{
+public record UpdateProductDto(
     [Required]
     [MinLength(1)]
-    public string Name { get; set; }
+        string Name,
     [Required]
-    public Color Color { get; set; }
+        Color Color,
     [Required]
-    public string Brand { get; set; }
-}
+        string Brand
+);
+
+