using Supabase.Postgrest; using Supabase.Postgrest.Attributes; using Supabase.Postgrest.Models; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using static Supabase.Postgrest.Constants; namespace ConsoleAppForUniqWear { public interface IDatabaseClient { Task GetUserById(Guid id); Task> GetAllUsers(); } public interface IReadyMadeClothingDatabaseClient { Task GetReadyMadeClothingById(Guid id); Task> GetAllReadyMadeClothing(); } public interface IClothingTypeDatabaseClient { Task GetClothingTypeById(Guid id); Task> GetAllClothingTypes(); } public class UserService { private readonly IDatabaseClient _dbClient; // Изменено на интерфейс public UserService(IDatabaseClient dbClient) { _dbClient = dbClient; } public async Task GetUserByIdAsync(Guid id) { var result = await _dbClient.GetUserById(id); return result; } public async Task> GetAllUsersAsync() { var result = await _dbClient.GetAllUsers(); return result; } } public class ClothingTypeService { private readonly IClothingTypeDatabaseClient _dbClient; public ClothingTypeService(IClothingTypeDatabaseClient dbClient) { _dbClient = dbClient; } public async Task GetClothingTypeByIdAsync(Guid id) { return await _dbClient.GetClothingTypeById(id); } public async Task> GetAllClothingTypesAsync() { return await _dbClient.GetAllClothingTypes(); } } public class ReadyMadeClothingService { private readonly IReadyMadeClothingDatabaseClient _dbClient; public ReadyMadeClothingService(IReadyMadeClothingDatabaseClient dbClient) { _dbClient = dbClient; } public async Task GetReadyMadeClothingByIdAsync(Guid id) { return await _dbClient.GetReadyMadeClothingById(id); } public async Task> GetAllReadyMadeClothingAsync() { return await _dbClient.GetAllReadyMadeClothing(); } } public class TestReadyMadeClothingDatabaseClient : IReadyMadeClothingDatabaseClient { private readonly List _testReadyMadeClothing; public TestReadyMadeClothingDatabaseClient() { // Инициализация тестовых данных _testReadyMadeClothing = new List { new ReadyMadeClothing { Id = Guid.NewGuid(), ClothingTypeId = Guid.NewGuid(), Name = "Классическая футболка", Description = "Удобная и стильная", ImageUrl = "image_url_1", Price = 19.99m }, new ReadyMadeClothing { Id = Guid.NewGuid(), ClothingTypeId = Guid.NewGuid(), Name = "Спортивная кофта", Description = "Для активных людей", ImageUrl = "image_url_2", Price = 29.99m }, new ReadyMadeClothing { Id = Guid.NewGuid(), ClothingTypeId = Guid.NewGuid(), Name = "Летние джинсы", Description = "Легкие и удобные", ImageUrl = "image_url_3", Price = 39.99m } }; } public Task GetReadyMadeClothingById(Guid id) { var clothing = _testReadyMadeClothing.FirstOrDefault(c => c.Id == id); return Task.FromResult(clothing); } public Task> GetAllReadyMadeClothing() { return Task.FromResult(_testReadyMadeClothing); } } public class TestDatabaseClient : IDatabaseClient { private readonly List _testUsers; public TestDatabaseClient() { // Инициализация тестовых данных _testUsers = new List { new User { Id = Guid.NewGuid(), FirstName = "John", LastName = "Doe" }, new User { Id = Guid.NewGuid(), FirstName = "Jane", LastName = "Smith" }, new User { Id = Guid.NewGuid(), FirstName = "Alice", LastName = "Johnson" } }; } public Task GetUserById(Guid id) { var user = _testUsers.FirstOrDefault(u => u.Id == id); return Task.FromResult(user); } public Task> GetAllUsers() { return Task.FromResult(_testUsers); } } public class TestClothingTypeDatabaseClient : IClothingTypeDatabaseClient { private readonly List _testClothingTypes; public TestClothingTypeDatabaseClient() { // Инициализация тестовых данных _testClothingTypes = new List { new ClothingType { Id = Guid.NewGuid(), Name = "Футболка", Description = "Комфортная футболка" }, new ClothingType { Id = Guid.NewGuid(), Name = "Кофта", Description = "Теплая кофта" }, new ClothingType { Id = Guid.NewGuid(), Name = "Джинсы", Description = "Удобные джинсы" } }; } public Task GetClothingTypeById(Guid id) { var clothingType = _testClothingTypes.FirstOrDefault(ct => ct.Id == id); return Task.FromResult(clothingType); } public Task> GetAllClothingTypes() { return Task.FromResult(_testClothingTypes); } } // Модель ReadyMadeClothing public class ReadyMadeClothing { [Column("id")] public Guid Id { get; set; } [Column("clothing_type_id")] public Guid ClothingTypeId { get; set; } [Column("name")] public string Name { get; set; } [Column("description")] public string Description { get; set; } [Column("image_url")] public string ImageUrl { get; set; } [Column("price")] public decimal Price { get; set; } [Column("created_at")] public DateTime CreatedAt { get; set; } } // Модель ClothingType public class ClothingType { [Column("id")] public Guid Id { get; set; } [Column("name")] public string Name { get; set; } [Column("description")] public string Description { get; set; } [Column("created_at")] public DateTime CreatedAt { get; set; } } // Модель User public class User : BaseModel { [Column("id")] public Guid Id { get; set; } [Column("uid")] public string Uid { get; set; } [Column("first_name")] public string FirstName { get; set; } [Column("last_name")] public string LastName { get; set; } [Column("middle_name")] public string MiddleName { get; set; } [Column("photo_url")] public string PhotoUrl { get; set; } [Column("created_at")] public DateTime CreatedAt { get; set; } [Column("updated_at")] public DateTime UpdatedAt { get; set; } } class Program { static async Task Main(string[] args) { // Инициализация тестового клиента для работы с базой данных var testClient = new TestDatabaseClient(); var userService = new UserService(testClient); // Используем TestDatabaseClient // Пример получения пользователя по ID Guid userId = Guid.Parse("вставьте_здесь_id_пользователя"); // Замените на фактический ID var user = await userService.GetUserByIdAsync(userId); Console.WriteLine($"Retrieved user: {user?.FirstName}"); // Пример получения всех пользователей var allUsers = await userService.GetAllUsersAsync(); Console.WriteLine($"Total users: {allUsers.Count}"); foreach (var u in allUsers) { Console.WriteLine($"User: {u.FirstName} {u.LastName}"); } } } }