-
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.
refactor: organized mvc designer in controller
- Loading branch information
Showing
9 changed files
with
172 additions
and
208 deletions.
There are no files selected for viewing
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,77 +1,75 @@ | ||
using AutoMapper; | ||
using Microsoft.AspNetCore.Mvc; | ||
using PokedexApi.Domain.Dtos; | ||
using PokedexApi.Domain.Interfaces; | ||
using PokedexApi.Domain.Responses; | ||
using PokedexApi.Web.FormRequest; | ||
using PokedexApi.Web.Resources; | ||
// using AutoMapper; | ||
// using Microsoft.AspNetCore.Mvc; | ||
// using PokedexApi.Domain.Dtos; | ||
// using PokedexApi.Domain.Interfaces; | ||
// using PokedexApi.Web.FormRequest; | ||
|
||
namespace PokedexApi.Web.Controllers | ||
{ | ||
[ApiController] | ||
[Route("evolution")] | ||
public class EvolutionController : ControllerBase | ||
{ | ||
private readonly IEvolutionRepository _repository; | ||
private readonly IMapper _mapper; | ||
// namespace PokedexApi.Web.Controllers | ||
// { | ||
// [ApiController] | ||
// [Route("evolution")] | ||
// public class EvolutionController : ControllerBase | ||
// { | ||
// private readonly IEvolutionRepository _repository; | ||
// private readonly IMapper _mapper; | ||
|
||
public EvolutionController(IEvolutionRepository repository, IMapper mapper) | ||
{ | ||
_repository = repository; | ||
_mapper = mapper; | ||
} | ||
// public EvolutionController(IEvolutionRepository repository, IMapper mapper) | ||
// { | ||
// _repository = repository; | ||
// _mapper = mapper; | ||
// } | ||
|
||
[HttpPost("add")] | ||
public async Task<IActionResult> AddAsync([FromBody] EvolutionAddFormRequest payload) | ||
{ | ||
try | ||
{ | ||
var result = await _repository.AddAsync(new EvolutionAddDTO | ||
{ | ||
PokemonId = payload.PokemonId, | ||
PreEvolution = payload.PreEvolution, | ||
EvolutionForm = payload.EvolutionForm | ||
}); | ||
// [HttpPost("add")] | ||
// public async Task<IActionResult> AddAsync([FromBody] EvolutionAddFormRequest payload) | ||
// { | ||
// try | ||
// { | ||
// var result = await _repository.AddAsync(new EvolutionAddDTO | ||
// { | ||
// PokemonId = payload.PokemonId, | ||
// PreEvolution = payload.PreEvolution, | ||
// EvolutionForm = payload.EvolutionForm | ||
// }); | ||
|
||
return Created("Evolution has been registered", result); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return BadRequest(ex.Message); | ||
} | ||
} | ||
// return Created("Evolution has been registered", result); | ||
// } | ||
// catch (Exception ex) | ||
// { | ||
// return BadRequest(ex.Message); | ||
// } | ||
// } | ||
|
||
[HttpGet("{pokemonId}")] | ||
public async Task<IActionResult> GetByPokemonId([FromRoute] int pokemonId) | ||
{ | ||
try | ||
{ | ||
var result = await _repository.GetByIdAsync(new EvolutionGetByIdDTO | ||
{ | ||
PokemonId = pokemonId | ||
}); | ||
// [HttpGet("{pokemonId}")] | ||
// public async Task<IActionResult> GetByPokemonId([FromRoute] int pokemonId) | ||
// { | ||
// try | ||
// { | ||
// var result = await _repository.GetByIdAsync(new EvolutionGetByIdDTO | ||
// { | ||
// PokemonId = pokemonId | ||
// }); | ||
|
||
return Ok(_mapper.Map<EvolutionResource>(result)); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return BadRequest(ex.Message); | ||
} | ||
} | ||
// return Ok(_mapper.Map<EvolutionResource>(result)); | ||
// } | ||
// catch (Exception ex) | ||
// { | ||
// return BadRequest(ex.Message); | ||
// } | ||
// } | ||
|
||
[HttpDelete("{pokemonId}/remove")] | ||
public async Task<IActionResult> RemoveByPokemonId([FromRoute] Guid pokemonId) | ||
{ | ||
try | ||
{ | ||
await _repository.DeleteAsync(pokemonId); | ||
// [HttpDelete("{pokemonId}/remove")] | ||
// public async Task<IActionResult> RemoveByPokemonId([FromRoute] Guid pokemonId) | ||
// { | ||
// try | ||
// { | ||
// await _repository.DeleteAsync(pokemonId); | ||
|
||
return NoContent(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return BadRequest(ex.Message); | ||
} | ||
} | ||
} | ||
} | ||
// return NoContent(); | ||
// } | ||
// catch (Exception ex) | ||
// { | ||
// return BadRequest(ex.Message); | ||
// } | ||
// } | ||
// } | ||
// } |
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,94 +1,77 @@ | ||
using AutoMapper; | ||
using Microsoft.AspNetCore.Mvc; | ||
using PokedexApi.Domain.Dtos; | ||
using PokedexApi.Domain.Interfaces; | ||
using PokedexApi.Web.FormRequest; | ||
// using AutoMapper; | ||
// using Microsoft.AspNetCore.Mvc; | ||
// using PokedexApi.Domain.Dtos; | ||
// using PokedexApi.Domain.Interfaces; | ||
// using PokedexApi.Web.FormRequest; | ||
|
||
namespace PokedexApi.Web.Controllers | ||
{ | ||
[ApiController] | ||
[Route("special-stage")] | ||
public class SpecialStageController : ControllerBase | ||
{ | ||
private readonly ISpecialStageRepository _repository; | ||
private readonly IMapper _mapper; | ||
// namespace PokedexApi.Web.Controllers | ||
// { | ||
// [ApiController] | ||
// [Route("special-stage")] | ||
// public class SpecialStageController : ControllerBase | ||
// { | ||
// private readonly ISpecialStageRepository _repository; | ||
|
||
public SpecialStageController(ISpecialStageRepository repository, IMapper mapper) | ||
{ | ||
_repository = repository; | ||
_mapper = mapper; | ||
} | ||
// public SpecialStageController(ISpecialStageRepository repository, IMapper mapper) | ||
// { | ||
// _repository = repository; | ||
// } | ||
|
||
[HttpPost("add")] | ||
public async Task<IActionResult> Add ([FromBody] SpecialStageCreateFormRequest payload) | ||
{ | ||
try | ||
{ | ||
var result = await _repository.AddAsync(new SpecialStageAddDTO | ||
{ | ||
PokemonId = payload.PokemonId, | ||
DexNumber = payload.DexNumber, | ||
Image = payload.Image, | ||
Description = payload.Description, | ||
Height = payload.Height, | ||
Weight = payload.Weight, | ||
Region = payload.Region | ||
}); | ||
// [HttpPost("add")] | ||
// public async Task<IActionResult> Add ([FromBody] SpecialStageCreateFormRequest payload) | ||
// { | ||
// try | ||
// { | ||
// var result = await _repository.AddAsync(new SpecialStageAddDTO | ||
// { | ||
// PokemonId = payload.PokemonId, | ||
// DexNumber = payload.DexNumber, | ||
// Image = payload.Image, | ||
// Description = payload.Description, | ||
// Height = payload.Height, | ||
// Weight = payload.Weight, | ||
// Region = payload.Region | ||
// }); | ||
|
||
return Created("Special Stage has been registered", result); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return BadRequest(ex.Message); | ||
} | ||
} | ||
// return Created("Special Stage has been registered", result); | ||
// } | ||
// catch (Exception ex) | ||
// { | ||
// return BadRequest(ex.Message); | ||
// } | ||
// } | ||
|
||
[HttpGet("{id}")] | ||
public async Task<IActionResult> GetById ([FromRoute] int id) | ||
{ | ||
try | ||
{ | ||
var result = await _repository.GetByIdAsync(id); | ||
// [HttpGet("all")] | ||
// public async Task<IActionResult> All ([FromQuery] PokemonListAllFormRequest payload) | ||
// { | ||
// try | ||
// { | ||
// var result = await _repository.AllAsync(new SpecialStageListAllDTO | ||
// { | ||
// Page = payload.Page, | ||
// }); | ||
|
||
return Ok(result); | ||
} | ||
catch(Exception ex) | ||
{ | ||
return BadRequest(ex.Message); | ||
} | ||
} | ||
// return Ok(result); | ||
// } | ||
// catch(Exception ex) | ||
// { | ||
// return BadRequest(ex.Message); | ||
// } | ||
// } | ||
|
||
[HttpGet("all")] | ||
public async Task<IActionResult> All ([FromQuery] PokemonListAllFormRequest payload) | ||
{ | ||
try | ||
{ | ||
var result = await _repository.AllAsync(new SpecialStageListAllDTO | ||
{ | ||
Page = payload.Page, | ||
}); | ||
// [HttpDelete("{id}/remove")] | ||
// public async Task<IActionResult> Remove ([FromRoute] Guid id) | ||
// { | ||
// try | ||
// { | ||
// await _repository.DeleteAsync(id); | ||
|
||
return Ok(result); | ||
} | ||
catch(Exception ex) | ||
{ | ||
return BadRequest(ex.Message); | ||
} | ||
} | ||
|
||
[HttpDelete("{id}/remove")] | ||
public async Task<IActionResult> Remove ([FromRoute] Guid id) | ||
{ | ||
try | ||
{ | ||
await _repository.DeleteAsync(id); | ||
|
||
return NoContent(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return BadRequest(ex.Message); | ||
} | ||
} | ||
} | ||
} | ||
// return NoContent(); | ||
// } | ||
// catch (Exception ex) | ||
// { | ||
// return BadRequest(ex.Message); | ||
// } | ||
// } | ||
// } | ||
// } |
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,17 +1,14 @@ | ||
using AutoMapper; | ||
using PokedexApi.Domain.Entities; | ||
using PokedexApi.Domain.Responses; | ||
using PokedexApi.Web.Resources; | ||
using PokedexApi.Web.Models; | ||
|
||
namespace PokedexApi.Web.Mapper | ||
{ | ||
public class DomainProfile : Profile | ||
{ | ||
public DomainProfile() | ||
{ | ||
CreateMap<Pokemon, PokemonResource>(MemberList.Destination); | ||
CreateMap<Pokemon, PokemonEvolutionResource>(MemberList.Destination); | ||
CreateMap<EvolutionResponse, EvolutionResource>(MemberList.Destination); | ||
CreateMap<Pokemon, PokemonModel>(MemberList.Destination); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using PokedexApi.Core.Enums; | ||
namespace PokedexApi.Web.Models; | ||
|
||
public class PokemonModel | ||
{ | ||
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 GenderEnum Gender { get; set; } | ||
public RarityEnum Rarity { get; set; } | ||
public string Region { get; set; } | ||
} |
Oops, something went wrong.