-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a RatingsService and use it from the frontend
- Loading branch information
Showing
9 changed files
with
137 additions
and
3 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
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
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
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
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
14 changes: 14 additions & 0 deletions
14
samples/eShopLite/MyFrontend/Services/RatingServiceClient.cs
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,14 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Globalization; | ||
|
||
namespace MyFrontend.Services; | ||
|
||
public class RatingServiceClient(HttpClient client) | ||
{ | ||
public Task<string> GetRatingAsync(int productId) | ||
{ | ||
return client.GetStringAsync($"averagerating/{productId.ToString(CultureInfo.InvariantCulture)}"); | ||
} | ||
} |
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
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,28 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.ComponentModel.DataAnnotations; | ||
using Newtonsoft.Json; | ||
|
||
namespace RatingsService; | ||
|
||
public class Rating | ||
{ | ||
/// <summary>A unique id for this rating.</summary> | ||
[Required, JsonProperty("id")] | ||
public string RatingId { get; set; } = ""; | ||
|
||
/// <summary>The ProductId that this rating is for.</summary> | ||
[Required] | ||
public string ProductId { get; set; } = ""; | ||
|
||
/// <summary>The value of this rating (from 1 to 5).</summary> | ||
[Range(1, 5)] | ||
public int RatingValue { get; set; } | ||
|
||
/// <summary>The user who gave this rating (optional).</summary> | ||
public string? User { get; set; } | ||
|
||
/// <summary>The text of the review (optional).</summary> | ||
public string? Review { get; set; } | ||
} |
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