Skip to content

Commit

Permalink
refactor: code review repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
Joaoms98 committed Feb 23, 2023
1 parent fee9fba commit d8e0775
Show file tree
Hide file tree
Showing 27 changed files with 255 additions and 513 deletions.
7 changes: 0 additions & 7 deletions PokedexApi.Domain/Dtos/EvolutionGetByIdDTO.cs

This file was deleted.

14 changes: 0 additions & 14 deletions PokedexApi.Domain/Dtos/EvolutionListAllDTO.cs

This file was deleted.

8 changes: 0 additions & 8 deletions PokedexApi.Domain/Dtos/PokemonGetWithParamsDTO.cs

This file was deleted.

4 changes: 3 additions & 1 deletion PokedexApi.Domain/Dtos/SpecialStageAddDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ namespace PokedexApi.Domain.Dtos
{
public class SpecialStageAddDTO
{
public int PokemonId { get; set; }
public int DexNumber { get; set; }
public string Name { get; set; }
public string Image { get; set; }
public string Description { get; set; }
public double Height { get; set; }
public double Weight { get; set; }
public string Region { get; set; }
public GenderEnum Gender { get; set; }
public RarityEnum Rarity { get; set; }
}
}
10 changes: 2 additions & 8 deletions PokedexApi.Domain/Dtos/TypePokemonAddDTO.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PokedexApi.Domain.Dtos
namespace PokedexApi.Domain.Dtos
{
public class TypePokemonAddDTO
{
public Guid? PokemonId { get; set; }
public int? PokemonId { get; set; }

public Guid? SpecialStageId { get; set; }

Expand Down
14 changes: 0 additions & 14 deletions PokedexApi.Domain/Dtos/TypePokemonDeleteDTO.cs

This file was deleted.

14 changes: 0 additions & 14 deletions PokedexApi.Domain/Dtos/TypePokemonGetByDTO.cs

This file was deleted.

8 changes: 1 addition & 7 deletions PokedexApi.Domain/Dtos/TypePokemonUpdateDTO.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PokedexApi.Domain.Dtos
namespace PokedexApi.Domain.Dtos
{
public class TypePokemonUpdateDTO
{
Expand Down
19 changes: 0 additions & 19 deletions PokedexApi.Domain/Dtos/WeaknessAddDTO.cs

This file was deleted.

2 changes: 1 addition & 1 deletion PokedexApi.Domain/Entities/SpecialStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace PokedexApi.Domain.Entities
public class SpecialStage
{
[Key]
public int DexNumber { get; set; }
public Guid Id { get; set; }

[Required]
[ForeignKey("Pokemon")]
Expand Down
2 changes: 1 addition & 1 deletion PokedexApi.Domain/Entities/Stats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Stats
public Pokemon Pokemon { get; set; }

[ForeignKey("SpecialStage")]
public int? SpecialStageId { get; set; }
public Guid? SpecialStageId { get; set; }
public SpecialStage SpecialStage { get; set; }

[Required]
Expand Down
2 changes: 1 addition & 1 deletion PokedexApi.Domain/Entities/TypePokemon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class TypePokemon
public Pokemon Pokemon { get; set; }

[ForeignKey("SpecialStage")]
public int? SpecialStageId { get; set; }
public Guid? SpecialStageId { get; set; }
public SpecialStage SpecialStage { get; set; }

[Required]
Expand Down
2 changes: 1 addition & 1 deletion PokedexApi.Domain/Entities/Weakness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Weakness
public Pokemon Pokemon { get; set; }

[ForeignKey("SpecialStage")]
public int? SpecialStageId { get; set; }
public Guid? SpecialStageId { get; set; }
public SpecialStage SpecialStage { get; set; }

[Required]
Expand Down
5 changes: 2 additions & 3 deletions PokedexApi.Domain/Interfaces/IEvolutionRepository.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using PokedexApi.Domain.Dtos;
using PokedexApi.Domain.Entities;
using PokedexApi.Domain.Responses;

namespace PokedexApi.Domain.Interfaces
{
public interface IEvolutionRepository
{
Task<Evolution> AddAsync(EvolutionAddDTO dto);
Task<EvolutionResponse> GetByIdAsync(int dexNumber);
Task<object> AddAsync(EvolutionAddDTO dto);
Task<object> DeleteAsync(int dexNumber);
Task<EvolutionResponse> GetByIdAsync(int dexNumber);
}
}
4 changes: 2 additions & 2 deletions PokedexApi.Domain/Interfaces/IPokemonRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public interface IPokemonRepository
Task<object> AddAsync (PokemonAddDTO dto);
Task<object> DeleteAsync (int id);
Task<Pokemon> GetByDexNumberAsync (int dexNumber);
Task<IEnumerable<Pokemon>> ListAllAsync (int page);
Task<IEnumerable<Pokemon>> ListWithParamsAsync (PokemonGetWithParamsDTO dto);
Task<IEnumerable<Pokemon>> ListByEvolutionAsync (int page);
Task<IEnumerable<Pokemon>> ListWithParamsAsync (int page, string param);
}
}
6 changes: 2 additions & 4 deletions PokedexApi.Domain/Interfaces/ISpecialStageRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ namespace PokedexApi.Domain.Interfaces
{
public interface ISpecialStageRepository
{
Task<SpecialStage> AddAsync (SpecialStageAddDTO dto);
Task<object> DeleteAsync (int dexNumber);
Task<SpecialStage> GetByIdAsync (int dexNumber);
Task<IEnumerable<SpecialStage>> AllAsync (int page);
Task<object> AddAsync (SpecialStageAddDTO dto);
Task<IEnumerable<SpecialStage>> ListByPokemonIdAsync (int dexNumber);
}
}
15 changes: 1 addition & 14 deletions PokedexApi.Domain/Interfaces/ITypePokemonRepository.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
using System;
using System.Threading.Tasks;
using PokedexApi.Core.Enums;
using PokedexApi.Domain.Dtos;
using PokedexApi.Domain.Entities;

namespace PokedexApi.Domain.Interfaces
namespace PokedexApi.Domain.Interfaces
{
public interface ITypePokemonRepository
{
Task<Entities.TypePokemon> AddAsync (TypePokemonAddDTO dto);

Task<Entities.TypePokemon> GetBy (TypePokemonGetByDTO dto);

Task<Entities.TypePokemon> Update (TypePokemonUpdateDTO dto);

Task<object> Delete(TypePokemonDeleteDTO dto);
}
}
4 changes: 0 additions & 4 deletions PokedexApi.Domain/Interfaces/IWeaknessRepository.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
using System;
using System.Threading.Tasks;
using PokedexApi.Core.Enums;
using PokedexApi.Domain.Dtos;
using PokedexApi.Domain.Entities;

namespace PokedexApi.Domain.Interfaces
{
public interface IWeaknessRepository
{
Task<Weakness> AddAsync (WeaknessAddDTO dto);
}
}
111 changes: 50 additions & 61 deletions PokedexApi.Infra/Implements/EvolutionRepository.cs
Original file line number Diff line number Diff line change
@@ -1,85 +1,74 @@
using Microsoft.EntityFrameworkCore;
using PokedexApi.Domain.Dtos;
using PokedexApi.Domain.Entities;
using PokedexApi.Domain.Interfaces;
using PokedexApi.Domain.Responses;

namespace PokedexApi.Infra.Implements
namespace PokedexApi.Infra.Implements;

public class EvolutionRepository : IEvolutionRepository
{
public class EvolutionRepository : IEvolutionRepository
private readonly DataContext _context;

public EvolutionRepository(DataContext context)
{
private readonly DataContext _context;
_context = context;
}

public EvolutionRepository(DataContext context)
public async Task<object> AddAsync(EvolutionAddDTO dto)
{
var evolution = new Evolution()
{
_context = context;
}
PokemonId = dto.PokemonId,
PreEvolution = dto.PreEvolution,
EvolutionForm = dto.EvolutionForm
};

public async Task<Evolution> AddAsync(EvolutionAddDTO dto)
{
var evolution = new Evolution()
{
PokemonId = dto.PokemonId,
PreEvolution = dto.PreEvolution,
EvolutionForm = dto.EvolutionForm
};

if(evolution.PreEvolution == null)
{
evolution.PreEvolution = 0;
}
if(evolution.EvolutionForm == null)
{
evolution.EvolutionForm = 0;
}

_context.Evolution.Add(evolution);
_context.SaveChanges();

return await Task.FromResult(evolution);
}
_context.Add(evolution);
_context.SaveChanges();

public async Task<EvolutionResponse> GetByIdAsync(int dexNumber)
{
Evolution evolution = _context.Evolution.Find(dexNumber);
return await Task.FromResult(evolution);
}

if(evolution is null)
{
throw new Exception($"Not found evolution with id {dexNumber}");
}
public async Task<object> DeleteAsync(int dexNumber)
{
Evolution evolution = _context.Evolution.Find(dexNumber);

Pokemon preEvolution = _context.Pokemon
.Find(evolution.PreEvolution);
if(evolution is null)
{
throw new Exception($"Not found evolution with id {dexNumber}");
}

Pokemon actualStage = _context.Pokemon
.Find(dexNumber);
_context.Remove(evolution);
_context.SaveChanges();

Pokemon evolutionForm = _context.Pokemon
.Find(evolution.EvolutionForm);
return await Task.FromResult(new object(){ });
}

var response = new EvolutionResponse()
{
PreEvolution = preEvolution,
ActualStage = actualStage,
EvolutionForm = evolutionForm
};
public async Task<EvolutionResponse> GetByIdAsync(int dexNumber)
{
Evolution evolution = _context.Evolution.Find(dexNumber);

return await Task.FromResult(response);
if(evolution is null)
{
throw new Exception($"Not found evolution with id {dexNumber}");
}

public async Task<object> DeleteAsync(int dexNumber)
{
Evolution evolution = _context.Evolution.Find(dexNumber);
Pokemon preEvolution = _context.Pokemon
.Find(evolution.PreEvolution);

if(evolution is null)
{
throw new Exception($"Not found evolution with id {dexNumber}");
}
Pokemon actualStage = _context.Pokemon
.Find(dexNumber);

_context.Evolution.Remove(evolution);
_context.SaveChanges();
Pokemon evolutionForm = _context.Pokemon
.Find(evolution.EvolutionForm);

return await Task.FromResult(new object(){ });
}
var response = new EvolutionResponse()
{
PreEvolution = preEvolution,
ActualStage = actualStage,
EvolutionForm = evolutionForm
};

return await Task.FromResult(response);
}
}
Loading

0 comments on commit d8e0775

Please sign in to comment.