diff --git a/modules/ContentStore/Model/RedPandaResponse.cs b/modules/ContentStore/Model/SomeRandomApiAnimalResponse.cs similarity index 78% rename from modules/ContentStore/Model/RedPandaResponse.cs rename to modules/ContentStore/Model/SomeRandomApiAnimalResponse.cs index bf61c02..c23e2ef 100644 --- a/modules/ContentStore/Model/RedPandaResponse.cs +++ b/modules/ContentStore/Model/SomeRandomApiAnimalResponse.cs @@ -1,6 +1,6 @@ namespace West.TelegramBot.ContentStore.Model; -public class RedPandaResponse +public class SomeRandomApiAnimalResponse { public string Image { get; set; } = null!; public string Fact { get; set; } = null!; diff --git a/modules/ContentStore/Service/BirdService.cs b/modules/ContentStore/Service/BirdService.cs new file mode 100644 index 0000000..7b25a01 --- /dev/null +++ b/modules/ContentStore/Service/BirdService.cs @@ -0,0 +1,7 @@ +namespace West.TelegramBot.ContentStore.Service; + +public class BirdService : SomeRandomApiAbstractService +{ + public BirdService(): base("bird", "Птица", 40, 165) + {} +} diff --git a/modules/ContentStore/Service/FoxService.cs b/modules/ContentStore/Service/FoxService.cs new file mode 100644 index 0000000..4ca1176 --- /dev/null +++ b/modules/ContentStore/Service/FoxService.cs @@ -0,0 +1,7 @@ +namespace West.TelegramBot.ContentStore.Service; + +public class FoxService : SomeRandomApiAbstractService +{ + public FoxService(): base("fox", "Лисица", 40, 170) + {} +} diff --git a/modules/ContentStore/Service/KangarooService.cs b/modules/ContentStore/Service/KangarooService.cs new file mode 100644 index 0000000..e4a1caa --- /dev/null +++ b/modules/ContentStore/Service/KangarooService.cs @@ -0,0 +1,7 @@ +namespace West.TelegramBot.ContentStore.Service; + +public class KangarooService : SomeRandomApiAbstractService +{ + public KangarooService(): base("kangaroo", "Кенгуру", 40, 175) + {} +} diff --git a/modules/ContentStore/Service/KoalaService.cs b/modules/ContentStore/Service/KoalaService.cs new file mode 100644 index 0000000..3b5b49e --- /dev/null +++ b/modules/ContentStore/Service/KoalaService.cs @@ -0,0 +1,7 @@ +namespace West.TelegramBot.ContentStore.Service; + +public class KoalaService : SomeRandomApiAbstractService +{ + public KoalaService() : base("koala", "Коала", 40, 180) + {} +} diff --git a/modules/ContentStore/Service/PandaService.cs b/modules/ContentStore/Service/PandaService.cs new file mode 100644 index 0000000..0198978 --- /dev/null +++ b/modules/ContentStore/Service/PandaService.cs @@ -0,0 +1,7 @@ +namespace West.TelegramBot.ContentStore.Service; + +public class PandaService : SomeRandomApiAbstractService +{ + public PandaService(): base("panda", "Панда", 40, 160) + {} +} diff --git a/modules/ContentStore/Service/RacoonService.cs b/modules/ContentStore/Service/RacoonService.cs new file mode 100644 index 0000000..25cbbaa --- /dev/null +++ b/modules/ContentStore/Service/RacoonService.cs @@ -0,0 +1,7 @@ +namespace West.TelegramBot.ContentStore.Service; + +public class RacoonService : SomeRandomApiAbstractService +{ + public RacoonService(): base("racoon", "Енот", 40, 160) + {} +} diff --git a/modules/ContentStore/Service/RedPandaService.cs b/modules/ContentStore/Service/RedPandaService.cs index 8fa4151..fdcbd66 100644 --- a/modules/ContentStore/Service/RedPandaService.cs +++ b/modules/ContentStore/Service/RedPandaService.cs @@ -1,28 +1,7 @@ -using System.Net.Http.Json; -using Newtonsoft.Json; -using Telegram.Bot.Types; -using West.TelegramBot.ContentStore.Model; +namespace West.TelegramBot.ContentStore.Service; -namespace West.TelegramBot.ContentStore.Service; - -public class RedPandaService : IRandomMediaService +public class RedPandaService : SomeRandomApiAbstractService { - public StoreItem StoreItem { get; } = new("red_panda", "Красная панда", 40, 150); - - private readonly HttpClient _httpClient; - - public RedPandaService() - { - // TODO: use factory or something, cause we have a lot of http clients in use - _httpClient = new HttpClient(); - } - - public async Task GetRandomMediaAsync() - { - var response = await _httpClient.GetStringAsync("https://some-random-api.com/animal/red_panda"); - - var image = JsonConvert.DeserializeObject(response); - - return new RandomMedia(new InputFileUrl(image.Image), image.Fact); - } + public RedPandaService(): base("red_panda", "Красная панда", 40, 150) + {} } diff --git a/modules/ContentStore/Service/SomeRandomApiAbstractService.cs b/modules/ContentStore/Service/SomeRandomApiAbstractService.cs new file mode 100644 index 0000000..788b733 --- /dev/null +++ b/modules/ContentStore/Service/SomeRandomApiAbstractService.cs @@ -0,0 +1,29 @@ +using Newtonsoft.Json; +using Telegram.Bot.Types; +using West.TelegramBot.ContentStore.Model; + +namespace West.TelegramBot.ContentStore.Service; + +public abstract class SomeRandomApiAbstractService : IRandomMediaService +{ + public StoreItem StoreItem { get; } + public string ApiId => StoreItem.Id; + + private readonly HttpClient _httpClient; + + public SomeRandomApiAbstractService(string id, string name, double price, int order) + { + StoreItem = new(id, name, price, order); + + // TODO: use factory or something, cause we have a lot of http clients in use + _httpClient = new HttpClient(); + } + + public async Task GetRandomMediaAsync() + { + var response = await _httpClient.GetStringAsync($"https://some-random-api.com/animal/{ApiId}"); + var image = JsonConvert.DeserializeObject(response); + + return new RandomMedia(new InputFileUrl(image.Image), image.Fact); + } +} \ No newline at end of file