-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
255 additions
and
513 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -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); | ||
} | ||
} |
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
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); | ||
} | ||
} |
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 |
---|---|---|
@@ -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); | ||
} | ||
} |
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 |
---|---|---|
@@ -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); | ||
} | ||
} |
Oops, something went wrong.