Commit to switch and release, do not return.

This commit is contained in:
Kira Jiroux 2025-02-17 18:33:05 -05:00
parent f083ff3f23
commit 1513c9eaed
20 changed files with 1260 additions and 31 deletions

View File

@ -8,6 +8,8 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.2" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.2" />
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -0,0 +1,90 @@
using Newtonsoft.Json;
using Portfolio.Domain.Features.Dtos;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using static Portfolio.Domain.Utility.StaticDetails;
namespace Portfolio.Application.Services
{
public class BaseService : IBaseService
{
private readonly IHttpClientFactory _httpClientFactory;
public BaseService(IHttpClientFactory httpClientFactory)
{
_httpClientFactory = httpClientFactory;
}
public async Task<ResponseDto?> SendAsync(RequestDto requestDto)
{
try
{
HttpClient client = _httpClientFactory.CreateClient("PokemonSleepAPI");
HttpRequestMessage message = new();
message.Headers.Add("Accept", "application/json");
//token here
message.RequestUri = new Uri(requestDto.Url);
if (requestDto.Data != null)
{
message.Content = new StringContent(JsonConvert.SerializeObject(requestDto.Data), Encoding.UTF8, "application/json");
}
HttpResponseMessage? apiResponse = null;
switch (requestDto.ApiType)
{
case ApiType.POST:
message.Method = HttpMethod.Post;
break;
case ApiType.DELETE:
message.Method = HttpMethod.Delete;
break;
case ApiType.PUT:
message.Method = HttpMethod.Put;
break;
default:
message.Method = HttpMethod.Get;
break;
}
apiResponse = await client.SendAsync(message);
switch (apiResponse.StatusCode)
{
case HttpStatusCode.NotFound:
return new() { IsSuccess = false, Message = "Not Found." };
case HttpStatusCode.Forbidden:
return new() { IsSuccess = false, Message = "Access Denied." };
case HttpStatusCode.Unauthorized:
return new() { IsSuccess = false, Message = "Unauthorized." };
case HttpStatusCode.InternalServerError:
return new() { IsSuccess = false, Message = "Internal Server Error." };
default:
var apiContent = await apiResponse.Content.ReadAsStringAsync();
var apiResponseDto = JsonConvert.DeserializeObject<ResponseDto>(apiContent);
return apiResponseDto;
}
}
catch (Exception ex)
{
var dto = new ResponseDto
{
IsSuccess = false,
Message = ex.Message.ToString()
};
return dto;
}
}
}
}

View File

@ -0,0 +1,14 @@
using Portfolio.Domain.Features.Dtos;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Portfolio.Application.Services
{
public interface IBaseService
{
Task<ResponseDto?> SendAsync(RequestDto requestDto);
}
}

View File

@ -1,4 +1,5 @@
using Portfolio.Domain.Features.Pokemon; using Portfolio.Domain.Features.Dtos;
using Portfolio.Domain.Features.Pokemon;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -9,6 +10,6 @@ namespace Portfolio.Application.Services.PokemonService
{ {
public interface IPokemonService public interface IPokemonService
{ {
Task<List<Pokemon>> GetAllPokemonAsync(); Task<List<PokemonDto>> GetAllPokemonAsync();
} }
} }

View File

@ -1,9 +1,12 @@
using Portfolio.Domain.Features.Articles; using Newtonsoft.Json;
using Portfolio.Domain.Features.Articles;
using Portfolio.Domain.Features.Dtos;
using Portfolio.Domain.Features.Pokemon; using Portfolio.Domain.Features.Pokemon;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Portfolio.Application.Services.PokemonService namespace Portfolio.Application.Services.PokemonService
@ -16,9 +19,19 @@ namespace Portfolio.Application.Services.PokemonService
{ {
_pokemonRepository = pokemonRepository; _pokemonRepository = pokemonRepository;
} }
public async Task<List<Pokemon>> GetAllPokemonAsync() public async Task<List<PokemonDto>> GetAllPokemonAsync()
{ {
return await _pokemonRepository.GetAllPokemonsAsync(); List<PokemonDto> pokemons = new List<PokemonDto>();
ResponseDto? response = await _pokemonRepository.GetAllPokemon();
if (response != null && response.IsSuccess)
{
pokemons = JsonConvert.DeserializeObject<List<PokemonDto>>(Convert.ToString(response.Result));
}
return pokemons;
//return new List<Pokemon>() { //return new List<Pokemon>() {
// new Pokemon // new Pokemon

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Portfolio.Domain.Features.Dtos
{
public class PokemonDto
{
public int Id { get; set; }
public int PokemonId { get; set; }
public required string PokemonName { get; set; }
public bool IsVariation { get; set; } = false;
public string? VariationName { get; set; }
public required string SleepType { get; set; }
public required string Speciality { get; set; }
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;
using static Portfolio.Domain.Utility.StaticDetails;
namespace Portfolio.Domain.Features.Dtos
{
public class RequestDto
{
public ApiType ApiType { get; set; } = ApiType.GET;
public string Url { get; set; }
public object Data { get; set; }
public string AccessToken { get; set; }
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Portfolio.Domain.Features.Dtos
{
public class ResponseDto
{
public object? Result { get; set; }
public bool IsSuccess { get; set; }
public string Message { get; set; }
}
}

View File

@ -1,4 +1,5 @@
using System; using Portfolio.Domain.Features.Dtos;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -8,6 +9,6 @@ namespace Portfolio.Domain.Features.Pokemon
{ {
public interface IPokemonRepository public interface IPokemonRepository
{ {
Task<List<Pokemon>> GetAllPokemonsAsync(); Task<ResponseDto> GetAllPokemon();
} }
} }

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Portfolio.Domain.Utility
{
public class StaticDetails
{
public static string PokemonSleepAPIBase { get; set; }
public enum ApiType
{
GET, POST, PUT, DELETE
}
}
}

View File

@ -13,7 +13,7 @@ namespace Portfolio.Infrastructure
{ {
public class ApplicationDbContext : DbContext public class ApplicationDbContext : DbContext
{ {
public ApplicationDbContext(DbContextOptions options) :base(options) public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{ {
} }
@ -21,5 +21,233 @@ namespace Portfolio.Infrastructure
public DbSet<PokemonNatures> PokemonNatures { get; set; } public DbSet<PokemonNatures> PokemonNatures { get; set; }
public DbSet<PokemonSubskills> PokemonSubskills { get; set; } public DbSet<PokemonSubskills> PokemonSubskills { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
//Pokemon
modelBuilder.Entity<Pokemon>().HasData(new Pokemon
{
Id = 1,
PokemonId = 1,
PokemonName = "Bulbasaur",
SleepType = "Dozing",
Speciality = "Ingredients"
});
modelBuilder.Entity<Pokemon>().HasData(new Pokemon
{
Id = 2,
PokemonId = 2,
PokemonName = "Ivysaur",
SleepType = "Dozing",
Speciality = "Ingredients"
});
modelBuilder.Entity<Pokemon>().HasData(new Pokemon
{
Id = 3,
PokemonId = 3,
PokemonName = "Venasaur",
SleepType = "Dozing",
Speciality = "Ingredients"
});
modelBuilder.Entity<Pokemon>().HasData(new Pokemon
{
Id = 4,
PokemonId = 4,
PokemonName = "Charmander",
SleepType = "Snoozing",
Speciality = "Ingredients"
});
modelBuilder.Entity<Pokemon>().HasData(new Pokemon
{
Id = 5,
PokemonId = 5,
PokemonName = "Charmeleon",
SleepType = "Snoozing",
Speciality = "Ingredients"
});
modelBuilder.Entity<Pokemon>().HasData(new Pokemon
{
Id = 6,
PokemonId = 6,
PokemonName = "Charizard",
SleepType = "Snoozing",
Speciality = "Ingredients"
});
modelBuilder.Entity<Pokemon>().HasData(new Pokemon
{
Id = 7,
PokemonId = 7,
PokemonName = "Squirtle",
SleepType = "Slumbering",
Speciality = "Ingredients"
});
modelBuilder.Entity<Pokemon>().HasData(new Pokemon
{
Id = 8,
PokemonId = 8,
PokemonName = "Wartortle",
SleepType = "Slumbering",
Speciality = "Ingredients"
});
modelBuilder.Entity<Pokemon>().HasData(new Pokemon
{
Id = 9,
PokemonId = 9,
PokemonName = "Blastoise",
SleepType = "Slumbering",
Speciality = "Ingredients"
});
modelBuilder.Entity<Pokemon>().HasData(new Pokemon
{
Id = 10,
PokemonId = 10,
PokemonName = "Caterpie",
SleepType = "Dozing",
Speciality = "Berries"
});
modelBuilder.Entity<Pokemon>().HasData(new Pokemon
{
Id = 11,
PokemonId = 11,
PokemonName = "Metapod",
SleepType = "Dozing",
Speciality = "Berries"
});
modelBuilder.Entity<Pokemon>().HasData(new Pokemon
{
Id = 12,
PokemonId = 12,
PokemonName = "Butterfree",
SleepType = "Dozing",
Speciality = "Berries"
});
modelBuilder.Entity<Pokemon>().HasData(new Pokemon
{
Id = 13,
PokemonId = 19,
PokemonName = "Rattata",
SleepType = "Snoozing",
Speciality = "Berries"
});
modelBuilder.Entity<Pokemon>().HasData(new Pokemon
{
Id = 14,
PokemonId = 20,
PokemonName = "Raticate",
SleepType = "Snoozing",
Speciality = "Berries"
});
modelBuilder.Entity<Pokemon>().HasData(new Pokemon
{
Id = 15,
PokemonId = 23,
PokemonName = "Ekans",
SleepType = "Dozing",
Speciality = "Berries"
});
modelBuilder.Entity<Pokemon>().HasData(new Pokemon
{
Id = 16,
PokemonId = 24,
PokemonName = "Arbok",
SleepType = "Dozing",
Speciality = "Berries"
});
modelBuilder.Entity<Pokemon>().HasData(new Pokemon
{
Id = 17,
PokemonId = 25,
PokemonName = "Pikachu",
SleepType = "Snoozing",
Speciality = "Berries"
});
modelBuilder.Entity<Pokemon>().HasData(new Pokemon
{
Id = 18,
PokemonId = 26,
PokemonName = "Raticate",
SleepType = "Snoozing",
Speciality = "Berries"
});
modelBuilder.Entity<Pokemon>().HasData(new Pokemon
{
Id = 19,
PokemonId = 35,
PokemonName = "Clefairy",
SleepType = "Snoozing",
Speciality = "Berries"
});
modelBuilder.Entity<Pokemon>().HasData(new Pokemon
{
Id = 20,
PokemonId = 36,
PokemonName = "Clefable",
SleepType = "Snoozing",
Speciality = "Berries"
});
modelBuilder.Entity<Pokemon>().HasData(new Pokemon
{
Id = 21,
PokemonId = 37,
PokemonName = "Vulpix",
SleepType = "Snoozing",
Speciality = "Berries"
});
modelBuilder.Entity<Pokemon>().HasData(new Pokemon
{
Id = 22,
PokemonId = 38,
PokemonName = "Ninetails",
SleepType = "Snoozing",
Speciality = "Berries"
});
modelBuilder.Entity<Pokemon>().HasData(new Pokemon
{
Id = 23,
PokemonId = 37,
PokemonName = "Vulpix",
IsVariation = true,
VariationName = "Alolan",
SleepType = "Slumbering",
Speciality = "Berries"
});
modelBuilder.Entity<Pokemon>().HasData(new Pokemon
{
Id = 24,
PokemonId = 38,
PokemonName = "Ninetails",
IsVariation = true,
VariationName = "Alolan",
SleepType = "Slumbering",
Speciality = "Berries"
});
}
} }
} }

View File

@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore; using AutoMapper;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Portfolio.Application.Services.Articles; using Portfolio.Application.Services.Articles;
@ -17,11 +18,21 @@ namespace Portfolio.Infrastructure
{ {
public static IServiceCollection AddInfrastructure( this IServiceCollection services, IConfiguration configuration) public static IServiceCollection AddInfrastructure( this IServiceCollection services, IConfiguration configuration)
{ {
IMapper mapper = MappingConfig.RegisterMaps().CreateMapper();
services.AddDbContext<ApplicationDbContext>(options => services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(configuration.GetConnectionString("DefaultConnection") options.UseSqlServer(configuration.GetConnectionString("DefaultConnection")
)); ));
services.AddScoped<IPokemonRepository, PokemonRepository>(); services.AddScoped<IPokemonRepository, PokemonRepository>();
services.AddSingleton(mapper);
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
return services; return services;
} }
} }

View File

@ -0,0 +1,25 @@
using AutoMapper;
using Portfolio.Domain.Features.Dtos;
using Portfolio.Domain.Features.Pokemon;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
namespace Portfolio.Infrastructure
{
public class MappingConfig
{
public static MapperConfiguration RegisterMaps()
{
var mappingConfig = new MapperConfiguration(config =>
{
config.CreateMap<PokemonDto, Pokemon>();
config.CreateMap<Pokemon, PokemonDto>();
});
return mappingConfig;
}
}
}

View File

@ -0,0 +1,335 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Portfolio.Infrastructure;
#nullable disable
namespace Portfolio.Infrastructure.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20250217221142_AddPokemon")]
partial class AddPokemon
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.2")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("Portfolio.Domain.Features.Pokemon.Pokemon", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<bool>("IsVariation")
.HasColumnType("bit");
b.Property<int>("PokemonId")
.HasColumnType("int");
b.Property<string>("PokemonName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("SleepType")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Speciality")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("VariationName")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Pokemons");
b.HasData(
new
{
Id = 1,
IsVariation = false,
PokemonId = 1,
PokemonName = "Bulbasaur",
SleepType = "Dozing",
Speciality = "Ingredients"
},
new
{
Id = 2,
IsVariation = false,
PokemonId = 2,
PokemonName = "Ivysaur",
SleepType = "Dozing",
Speciality = "Ingredients"
},
new
{
Id = 3,
IsVariation = false,
PokemonId = 3,
PokemonName = "Venasaur",
SleepType = "Dozing",
Speciality = "Ingredients"
},
new
{
Id = 4,
IsVariation = false,
PokemonId = 4,
PokemonName = "Charmander",
SleepType = "Snoozing",
Speciality = "Ingredients"
},
new
{
Id = 5,
IsVariation = false,
PokemonId = 5,
PokemonName = "Charmeleon",
SleepType = "Snoozing",
Speciality = "Ingredients"
},
new
{
Id = 6,
IsVariation = false,
PokemonId = 6,
PokemonName = "Charizard",
SleepType = "Snoozing",
Speciality = "Ingredients"
},
new
{
Id = 7,
IsVariation = false,
PokemonId = 7,
PokemonName = "Squirtle",
SleepType = "Slumbering",
Speciality = "Ingredients"
},
new
{
Id = 8,
IsVariation = false,
PokemonId = 8,
PokemonName = "Wartortle",
SleepType = "Slumbering",
Speciality = "Ingredients"
},
new
{
Id = 9,
IsVariation = false,
PokemonId = 9,
PokemonName = "Blastoise",
SleepType = "Slumbering",
Speciality = "Ingredients"
},
new
{
Id = 10,
IsVariation = false,
PokemonId = 10,
PokemonName = "Caterpie",
SleepType = "Dozing",
Speciality = "Berries"
},
new
{
Id = 11,
IsVariation = false,
PokemonId = 11,
PokemonName = "Metapod",
SleepType = "Dozing",
Speciality = "Berries"
},
new
{
Id = 12,
IsVariation = false,
PokemonId = 12,
PokemonName = "Butterfree",
SleepType = "Dozing",
Speciality = "Berries"
},
new
{
Id = 13,
IsVariation = false,
PokemonId = 19,
PokemonName = "Rattata",
SleepType = "Snoozing",
Speciality = "Berries"
},
new
{
Id = 14,
IsVariation = false,
PokemonId = 20,
PokemonName = "Raticate",
SleepType = "Snoozing",
Speciality = "Berries"
},
new
{
Id = 15,
IsVariation = false,
PokemonId = 23,
PokemonName = "Ekans",
SleepType = "Dozing",
Speciality = "Berries"
},
new
{
Id = 16,
IsVariation = false,
PokemonId = 24,
PokemonName = "Arbok",
SleepType = "Dozing",
Speciality = "Berries"
},
new
{
Id = 17,
IsVariation = false,
PokemonId = 25,
PokemonName = "Pikachu",
SleepType = "Snoozing",
Speciality = "Berries"
},
new
{
Id = 18,
IsVariation = false,
PokemonId = 26,
PokemonName = "Raticate",
SleepType = "Snoozing",
Speciality = "Berries"
},
new
{
Id = 19,
IsVariation = false,
PokemonId = 35,
PokemonName = "Clefairy",
SleepType = "Snoozing",
Speciality = "Berries"
},
new
{
Id = 20,
IsVariation = false,
PokemonId = 36,
PokemonName = "Clefable",
SleepType = "Snoozing",
Speciality = "Berries"
},
new
{
Id = 21,
IsVariation = false,
PokemonId = 37,
PokemonName = "Vulpix",
SleepType = "Snoozing",
Speciality = "Berries"
},
new
{
Id = 22,
IsVariation = false,
PokemonId = 38,
PokemonName = "Ninetails",
SleepType = "Snoozing",
Speciality = "Berries"
},
new
{
Id = 23,
IsVariation = true,
PokemonId = 37,
PokemonName = "Vulpix",
SleepType = "Slumbering",
Speciality = "Berries",
VariationName = "Alolan"
},
new
{
Id = 24,
IsVariation = true,
PokemonId = 38,
PokemonName = "Ninetails",
SleepType = "Slumbering",
Speciality = "Berries",
VariationName = "Alolan"
});
});
modelBuilder.Entity("Portfolio.Domain.Features.Pokemon_Natures.PokemonNatures", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BerryRating")
.HasColumnType("int");
b.Property<int>("IngredientRating")
.HasColumnType("int");
b.Property<string>("Nature")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("SkillRating")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("PokemonNatures");
});
modelBuilder.Entity("Portfolio.Domain.Features.Pokemon_Subskills.PokemonSubskills", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("BerryRank")
.HasColumnType("int");
b.Property<int>("IngredientRank")
.HasColumnType("int");
b.Property<int>("SkillRank")
.HasColumnType("int");
b.Property<string>("SubSkill")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("PokemonSubskills");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,171 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
namespace Portfolio.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class AddPokemon : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.InsertData(
table: "Pokemons",
columns: new[] { "Id", "IsVariation", "PokemonId", "PokemonName", "SleepType", "Speciality", "VariationName" },
values: new object[,]
{
{ 1, false, 1, "Bulbasaur", "Dozing", "Ingredients", null },
{ 2, false, 2, "Ivysaur", "Dozing", "Ingredients", null },
{ 3, false, 3, "Venasaur", "Dozing", "Ingredients", null },
{ 4, false, 4, "Charmander", "Snoozing", "Ingredients", null },
{ 5, false, 5, "Charmeleon", "Snoozing", "Ingredients", null },
{ 6, false, 6, "Charizard", "Snoozing", "Ingredients", null },
{ 7, false, 7, "Squirtle", "Slumbering", "Ingredients", null },
{ 8, false, 8, "Wartortle", "Slumbering", "Ingredients", null },
{ 9, false, 9, "Blastoise", "Slumbering", "Ingredients", null },
{ 10, false, 10, "Caterpie", "Dozing", "Berries", null },
{ 11, false, 11, "Metapod", "Dozing", "Berries", null },
{ 12, false, 12, "Butterfree", "Dozing", "Berries", null },
{ 13, false, 19, "Rattata", "Snoozing", "Berries", null },
{ 14, false, 20, "Raticate", "Snoozing", "Berries", null },
{ 15, false, 23, "Ekans", "Dozing", "Berries", null },
{ 16, false, 24, "Arbok", "Dozing", "Berries", null },
{ 17, false, 25, "Pikachu", "Snoozing", "Berries", null },
{ 18, false, 26, "Raticate", "Snoozing", "Berries", null },
{ 19, false, 35, "Clefairy", "Snoozing", "Berries", null },
{ 20, false, 36, "Clefable", "Snoozing", "Berries", null },
{ 21, false, 37, "Vulpix", "Snoozing", "Berries", null },
{ 22, false, 38, "Ninetails", "Snoozing", "Berries", null },
{ 23, true, 37, "Vulpix", "Slumbering", "Berries", "Alolan" },
{ 24, true, 38, "Ninetails", "Slumbering", "Berries", "Alolan" }
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DeleteData(
table: "Pokemons",
keyColumn: "Id",
keyValue: 1);
migrationBuilder.DeleteData(
table: "Pokemons",
keyColumn: "Id",
keyValue: 2);
migrationBuilder.DeleteData(
table: "Pokemons",
keyColumn: "Id",
keyValue: 3);
migrationBuilder.DeleteData(
table: "Pokemons",
keyColumn: "Id",
keyValue: 4);
migrationBuilder.DeleteData(
table: "Pokemons",
keyColumn: "Id",
keyValue: 5);
migrationBuilder.DeleteData(
table: "Pokemons",
keyColumn: "Id",
keyValue: 6);
migrationBuilder.DeleteData(
table: "Pokemons",
keyColumn: "Id",
keyValue: 7);
migrationBuilder.DeleteData(
table: "Pokemons",
keyColumn: "Id",
keyValue: 8);
migrationBuilder.DeleteData(
table: "Pokemons",
keyColumn: "Id",
keyValue: 9);
migrationBuilder.DeleteData(
table: "Pokemons",
keyColumn: "Id",
keyValue: 10);
migrationBuilder.DeleteData(
table: "Pokemons",
keyColumn: "Id",
keyValue: 11);
migrationBuilder.DeleteData(
table: "Pokemons",
keyColumn: "Id",
keyValue: 12);
migrationBuilder.DeleteData(
table: "Pokemons",
keyColumn: "Id",
keyValue: 13);
migrationBuilder.DeleteData(
table: "Pokemons",
keyColumn: "Id",
keyValue: 14);
migrationBuilder.DeleteData(
table: "Pokemons",
keyColumn: "Id",
keyValue: 15);
migrationBuilder.DeleteData(
table: "Pokemons",
keyColumn: "Id",
keyValue: 16);
migrationBuilder.DeleteData(
table: "Pokemons",
keyColumn: "Id",
keyValue: 17);
migrationBuilder.DeleteData(
table: "Pokemons",
keyColumn: "Id",
keyValue: 18);
migrationBuilder.DeleteData(
table: "Pokemons",
keyColumn: "Id",
keyValue: 19);
migrationBuilder.DeleteData(
table: "Pokemons",
keyColumn: "Id",
keyValue: 20);
migrationBuilder.DeleteData(
table: "Pokemons",
keyColumn: "Id",
keyValue: 21);
migrationBuilder.DeleteData(
table: "Pokemons",
keyColumn: "Id",
keyValue: 22);
migrationBuilder.DeleteData(
table: "Pokemons",
keyColumn: "Id",
keyValue: 23);
migrationBuilder.DeleteData(
table: "Pokemons",
keyColumn: "Id",
keyValue: 24);
}
}
}

View File

@ -53,6 +53,226 @@ namespace Portfolio.Infrastructure.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.ToTable("Pokemons"); b.ToTable("Pokemons");
b.HasData(
new
{
Id = 1,
IsVariation = false,
PokemonId = 1,
PokemonName = "Bulbasaur",
SleepType = "Dozing",
Speciality = "Ingredients"
},
new
{
Id = 2,
IsVariation = false,
PokemonId = 2,
PokemonName = "Ivysaur",
SleepType = "Dozing",
Speciality = "Ingredients"
},
new
{
Id = 3,
IsVariation = false,
PokemonId = 3,
PokemonName = "Venasaur",
SleepType = "Dozing",
Speciality = "Ingredients"
},
new
{
Id = 4,
IsVariation = false,
PokemonId = 4,
PokemonName = "Charmander",
SleepType = "Snoozing",
Speciality = "Ingredients"
},
new
{
Id = 5,
IsVariation = false,
PokemonId = 5,
PokemonName = "Charmeleon",
SleepType = "Snoozing",
Speciality = "Ingredients"
},
new
{
Id = 6,
IsVariation = false,
PokemonId = 6,
PokemonName = "Charizard",
SleepType = "Snoozing",
Speciality = "Ingredients"
},
new
{
Id = 7,
IsVariation = false,
PokemonId = 7,
PokemonName = "Squirtle",
SleepType = "Slumbering",
Speciality = "Ingredients"
},
new
{
Id = 8,
IsVariation = false,
PokemonId = 8,
PokemonName = "Wartortle",
SleepType = "Slumbering",
Speciality = "Ingredients"
},
new
{
Id = 9,
IsVariation = false,
PokemonId = 9,
PokemonName = "Blastoise",
SleepType = "Slumbering",
Speciality = "Ingredients"
},
new
{
Id = 10,
IsVariation = false,
PokemonId = 10,
PokemonName = "Caterpie",
SleepType = "Dozing",
Speciality = "Berries"
},
new
{
Id = 11,
IsVariation = false,
PokemonId = 11,
PokemonName = "Metapod",
SleepType = "Dozing",
Speciality = "Berries"
},
new
{
Id = 12,
IsVariation = false,
PokemonId = 12,
PokemonName = "Butterfree",
SleepType = "Dozing",
Speciality = "Berries"
},
new
{
Id = 13,
IsVariation = false,
PokemonId = 19,
PokemonName = "Rattata",
SleepType = "Snoozing",
Speciality = "Berries"
},
new
{
Id = 14,
IsVariation = false,
PokemonId = 20,
PokemonName = "Raticate",
SleepType = "Snoozing",
Speciality = "Berries"
},
new
{
Id = 15,
IsVariation = false,
PokemonId = 23,
PokemonName = "Ekans",
SleepType = "Dozing",
Speciality = "Berries"
},
new
{
Id = 16,
IsVariation = false,
PokemonId = 24,
PokemonName = "Arbok",
SleepType = "Dozing",
Speciality = "Berries"
},
new
{
Id = 17,
IsVariation = false,
PokemonId = 25,
PokemonName = "Pikachu",
SleepType = "Snoozing",
Speciality = "Berries"
},
new
{
Id = 18,
IsVariation = false,
PokemonId = 26,
PokemonName = "Raticate",
SleepType = "Snoozing",
Speciality = "Berries"
},
new
{
Id = 19,
IsVariation = false,
PokemonId = 35,
PokemonName = "Clefairy",
SleepType = "Snoozing",
Speciality = "Berries"
},
new
{
Id = 20,
IsVariation = false,
PokemonId = 36,
PokemonName = "Clefable",
SleepType = "Snoozing",
Speciality = "Berries"
},
new
{
Id = 21,
IsVariation = false,
PokemonId = 37,
PokemonName = "Vulpix",
SleepType = "Snoozing",
Speciality = "Berries"
},
new
{
Id = 22,
IsVariation = false,
PokemonId = 38,
PokemonName = "Ninetails",
SleepType = "Snoozing",
Speciality = "Berries"
},
new
{
Id = 23,
IsVariation = true,
PokemonId = 37,
PokemonName = "Vulpix",
SleepType = "Slumbering",
Speciality = "Berries",
VariationName = "Alolan"
},
new
{
Id = 24,
IsVariation = true,
PokemonId = 38,
PokemonName = "Ninetails",
SleepType = "Slumbering",
Speciality = "Berries",
VariationName = "Alolan"
});
}); });
modelBuilder.Entity("Portfolio.Domain.Features.Pokemon_Natures.PokemonNatures", b => modelBuilder.Entity("Portfolio.Domain.Features.Pokemon_Natures.PokemonNatures", b =>

View File

@ -7,6 +7,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="AutoMapper" Version="14.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.2" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.2" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.2"> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.2">

View File

@ -1,5 +1,10 @@
using Microsoft.EntityFrameworkCore; using AutoMapper;
using Azure;
using Microsoft.EntityFrameworkCore;
using Portfolio.Application.Services;
using Portfolio.Domain.Features.Dtos;
using Portfolio.Domain.Features.Pokemon; using Portfolio.Domain.Features.Pokemon;
using Portfolio.Domain.Utility;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -11,15 +16,40 @@ namespace Portfolio.Infrastructure.Repositories
public class PokemonRepository : IPokemonRepository public class PokemonRepository : IPokemonRepository
{ {
private readonly ApplicationDbContext _context; private readonly ApplicationDbContext _context;
private readonly IBaseService _baseService;
private ResponseDto _response;
private IMapper _mapper;
public PokemonRepository(ApplicationDbContext context) public PokemonRepository(ApplicationDbContext context, IMapper mapper, IBaseService baseService)
{ {
_context = context; _context = context;
_baseService = baseService;
_mapper = mapper;
_response = new ResponseDto();
} }
public async Task<List<Pokemon>> GetAllPokemonsAsync()
public async Task<ResponseDto> GetAllPokemon()
{ {
return await _context.Pokemons.ToListAsync(); return await _baseService.SendAsync(new RequestDto()
{
ApiType = StaticDetails.ApiType.GET,
Url = StaticDetails.PokemonSleepAPIBase + "/api/pokemon"
});
//try
//{
// IEnumerable<Pokemon> objList = _context.Pokemons.ToList();
// _response.IsSuccess = true;
// _response.Message = "All Pokemon found.";
// _response.Result = _mapper.Map<IEnumerable<PokemonDto>>(objList);
//}
//catch (Exception ex)
//{
// _response.IsSuccess = false;
// _response.Message = ex.Message;
//}
//return _response;
} }
} }
} }

View File

@ -1,4 +1,5 @@
@page "/pokemonsleep" @page "/pokemonsleep"
@inject IPokemonService PokemonService @inject IPokemonService PokemonService
@attribute [StreamRendering] @attribute [StreamRendering]
@ -11,6 +12,10 @@
{ {
<p><em>Loading...</em></p> <p><em>Loading...</em></p>
} }
else if(somethingWrong)
{
<p><em>Something went wrong...</em></p>
}
else else
{ {
<div class="card shadow border-0 mt-4" style ="margin: auto; width: 900px; max-width: 60%; "> <div class="card shadow border-0 mt-4" style ="margin: auto; width: 900px; max-width: 60%; ">
@ -44,6 +49,8 @@ else
</thead> </thead>
<tbody> <tbody>
@foreach (var pokemon in pokemons) @foreach (var pokemon in pokemons)
{
@if(pokemon.Id == 3)
{ {
string URL = "https://www.serebii.net/pokemonsleep/pokemon/" + pokemon.Id + ".png"; string URL = "https://www.serebii.net/pokemonsleep/pokemon/" + pokemon.Id + ".png";
string ShinyURL = "https://www.serebii.net/pokemonsleep/pokemon/shiny/" + pokemon.Id + ".png"; string ShinyURL = "https://www.serebii.net/pokemonsleep/pokemon/shiny/" + pokemon.Id + ".png";
@ -64,6 +71,8 @@ else
</td> </td>
</tr> </tr>
}
} }
</tbody> </tbody>
</table> </table>
@ -74,17 +83,24 @@ else
} }
@code { @code {
private List<Pokemon> pokemons = new List<Pokemon>(); private List<PokemonDto> pokemons = new List<PokemonDto>();
private bool somethingWrong = false;
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
// Simulate asynchronous loading to demonstrate streaming rendering // Simulate asynchronous loading to demonstrate streaming rendering
await Task.Delay(500); await Task.Delay(500);
var result = await PokemonService.GetAllPokemonAsync(); var result = await PokemonService.GetAllPokemonAsync();
if (result is not null) if (result is not null)
{ {
somethingWrong = false;
pokemons = result; pokemons = result;
} }
else
{
somethingWrong = true;
}
} }
} }

View File

@ -10,6 +10,8 @@
@using Portfolio.WebUI.Server.Components @using Portfolio.WebUI.Server.Components
@using Portfolio.Domain.Features.Articles @using Portfolio.Domain.Features.Articles
@using Portfolio.Domain.Features.Pokemon @using Portfolio.Domain.Features.Pokemon
@using Portfolio.Domain.Features.Dtos
@using Portfolio.Application.Services.Articles @using Portfolio.Application.Services.Articles
@using Portfolio.Application.Services.PokemonService @using Portfolio.Application.Services.PokemonService