-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored translator service API design
- Loading branch information
1 parent
5be72f4
commit 8cdd040
Showing
6 changed files
with
70 additions
and
14 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
40 changes: 40 additions & 0 deletions
40
common/src/DbLocalizationProvider.Abstractions/TranslationResult.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,40 @@ | ||
namespace DbLocalizationProvider.Abstractions; | ||
|
||
/// <summary> | ||
/// Result of the translation operation from AI service. | ||
/// </summary> | ||
/// <param name="IsSuccessful">Is operation successful?</param> | ||
/// <param name="Result">Translated text to target language.</param> | ||
/// <param name="Error">Filled in with problem details if any.</param> | ||
public record TranslationResult(bool IsSuccessful, string? Result, Problem? Error = null) | ||
{ | ||
/// <summary> | ||
/// Translation was successful. | ||
/// </summary> | ||
/// <param name="text">Translated text to target language.</param> | ||
/// <returns>Successful translation result.</returns> | ||
public static TranslationResult Ok(string text) | ||
{ | ||
return new TranslationResult(true, text); | ||
} | ||
|
||
/// <summary> | ||
/// Translation was failing. | ||
/// </summary> | ||
/// <param name="message">Error details if translation failed.</param> | ||
/// <param name="details">More details about an error.</param> | ||
/// <returns>Failed translation result.</returns> | ||
public static TranslationResult Failed(string message, string? details = null) | ||
{ | ||
return new TranslationResult(false, null, new Problem(message, details)); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// More details about failed translation. | ||
/// </summary> | ||
/// <param name="Message">Message about an error.</param> | ||
/// <param name="Details">More information about an error.</param> | ||
public record Problem(string? Message, string? Details) | ||
{ | ||
} |
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