Skip to content

Commit 80c7321

Browse files
committed
added
0 parents  commit 80c7321

File tree

138 files changed

+25433
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+25433
-0
lines changed
150 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

.vs/ApiPractise/FileContentIndex/read.lock

Whitespace-only changes.

.vs/ApiPractise/config/applicationhost.config

+1,011
Large diffs are not rendered by default.

.vs/ApiPractise/v17/.futdcache.v2

138 Bytes
Binary file not shown.

.vs/ApiPractise/v17/.suo

86 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

ApiPractise.sln

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.5.33530.505
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiPractise", "ApiPractise\ApiPractise.csproj", "{ACEAAE35-A63D-4828-AF9D-05976BC7E700}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{ACEAAE35-A63D-4828-AF9D-05976BC7E700}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{ACEAAE35-A63D-4828-AF9D-05976BC7E700}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{ACEAAE35-A63D-4828-AF9D-05976BC7E700}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{ACEAAE35-A63D-4828-AF9D-05976BC7E700}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {008B57B8-9A4C-48E0-86D5-9BAC141D28A6}
24+
EndGlobalSection
25+
EndGlobal

ApiPractise/ApiPractise.csproj

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="AutoMapper" Version="12.0.1" />
11+
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
12+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.16" />
13+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.16" />
14+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.16">
15+
<PrivateAssets>all</PrivateAssets>
16+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
17+
</PackageReference>
18+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
19+
</ItemGroup>
20+
21+
</Project>

ApiPractise/ApiPractise.csproj.user

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Controller_SelectedScaffolderID>ApiControllerEmptyScaffolder</Controller_SelectedScaffolderID>
5+
<Controller_SelectedScaffolderCategoryPath>root/Common/Api</Controller_SelectedScaffolderCategoryPath>
6+
</PropertyGroup>
7+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using System.Collections;
2+
using ApiPractise.DTOs;
3+
using ApiPractise.Interfaces;
4+
using ApiPractise.Models;
5+
using AutoMapper;
6+
using Microsoft.AspNetCore.Mvc;
7+
8+
namespace ApiPractise.Controllers;
9+
10+
[Route("api/[controller]")]
11+
[ApiController]
12+
public class CategoryController : ControllerBase
13+
{
14+
private readonly ICategoryRepository _categoryRepository;
15+
private readonly IMapper _mapper;
16+
17+
public CategoryController(ICategoryRepository categoryRepository, IMapper mapper)
18+
{
19+
_categoryRepository = categoryRepository;
20+
_mapper = mapper;
21+
}
22+
23+
24+
[HttpGet]
25+
[ProducesResponseType(200, Type = typeof(IEnumerable<Pokemon>))]
26+
public IActionResult GetCategories()
27+
{
28+
var categories = _mapper.Map<List<CategoryDTO>>(_categoryRepository.GetCategories());
29+
if (!ModelState.IsValid)
30+
return BadRequest(ModelState);
31+
return Ok(categories);
32+
}
33+
[HttpGet("{categoryId}")]
34+
[ProducesResponseType(200, Type = typeof(Category))]
35+
[ProducesResponseType(400)]
36+
public IActionResult GetCategory(int categoryId)
37+
{
38+
if (!_categoryRepository.CategoryExists(categoryId))
39+
return NotFound();
40+
var category = _mapper.Map<CategoryDTO>(_categoryRepository.GetCategoryById(categoryId));
41+
if (!ModelState.IsValid)
42+
return BadRequest();
43+
return Ok(category);
44+
}
45+
46+
[HttpGet("pokemon/{categoryId}")]
47+
[ProducesResponseType(200, Type = typeof(Category))]
48+
[ProducesResponseType(400)]
49+
public IActionResult GetPokemonByCategoryId(int categoryId)
50+
{
51+
var pokemon = _mapper.Map<List<PokemonDTO>>(_categoryRepository.GetPokemonByCategory(categoryId));
52+
if (!ModelState.IsValid)
53+
return BadRequest();
54+
return Ok(pokemon);
55+
56+
}
57+
58+
[HttpPost]
59+
[ProducesResponseType(204)]
60+
[ProducesResponseType(400)]
61+
public IActionResult CreateCategory([FromBody] CategoryDTO categoryCreate)
62+
{
63+
if (categoryCreate is null)
64+
return BadRequest(ModelState);
65+
var category = _categoryRepository.GetCategories().Where(c => c.Name.Trim().ToUpper() == categoryCreate
66+
.Name.Trim().ToUpper()).FirstOrDefault();
67+
if (category is not null)
68+
{
69+
ModelState.AddModelError("","Category alredy exists!");
70+
return StatusCode(409, ModelState);
71+
}
72+
73+
if (!ModelState.IsValid)
74+
return BadRequest(ModelState);
75+
var categoryMap = _mapper.Map<Category>(categoryCreate);
76+
if (!_categoryRepository.CreateCategory(categoryMap))
77+
{
78+
ModelState.AddModelError("","Something went wrong while saving!");
79+
return StatusCode(500, ModelState);
80+
}
81+
return Ok("Successful!");
82+
}
83+
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using ApiPractise.DTOs;
2+
using ApiPractise.Interfaces;
3+
using ApiPractise.Models;
4+
using AutoMapper;
5+
using Microsoft.AspNetCore.Mvc;
6+
7+
namespace ApiPractise.Controllers;
8+
9+
[Route("api/[controller]")]
10+
[ApiController]
11+
public class CountryController : ControllerBase
12+
{
13+
private readonly ICountryRepository _countryRepository;
14+
private readonly IMapper _mapper;
15+
16+
public CountryController(ICountryRepository countryRepository, IMapper mapper)
17+
{
18+
_countryRepository = countryRepository;
19+
_mapper = mapper;
20+
}
21+
22+
[HttpGet]
23+
[ProducesResponseType(200, Type = typeof(IEnumerable<Country>))]
24+
public IActionResult GetCountries()
25+
{
26+
var countries = _mapper.Map<List<CountryDTO>>(_countryRepository.GetCountries());
27+
if (!ModelState.IsValid)
28+
return BadRequest(ModelState);
29+
return Ok(countries);
30+
}
31+
[HttpGet("{countryId}")]
32+
[ProducesResponseType(200, Type = typeof(Country))]
33+
[ProducesResponseType(400)]
34+
public IActionResult GetCountry(int countryId)
35+
{
36+
if (!_countryRepository.CountryExists(countryId))
37+
return NotFound();
38+
var country = _mapper.Map<CountryDTO>(_countryRepository.GetCountry(countryId));
39+
if (!ModelState.IsValid)
40+
return BadRequest();
41+
return Ok(country);
42+
}
43+
[HttpGet("/owners/{ownerId}")]
44+
[ProducesResponseType(200, Type = typeof(Country))]
45+
[ProducesResponseType(400)]
46+
public IActionResult GetCountryOfAnOwner(int ownerId)
47+
{
48+
var country = _mapper.Map<CountryDTO>(_countryRepository.GetCountryByOwner(ownerId));
49+
if (!ModelState.IsValid)
50+
return BadRequest();
51+
return Ok(country);
52+
53+
54+
}
55+
}
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using ApiPractise.DTOs;
2+
using ApiPractise.Interfaces;
3+
using ApiPractise.Models;
4+
using ApiPractise.Repository;
5+
using AutoMapper;
6+
using Microsoft.AspNetCore.Mvc;
7+
8+
namespace ApiPractise.Controllers;
9+
10+
[Route("api/[controller]")]
11+
[ApiController]
12+
public class OwnerController : ControllerBase
13+
{
14+
private readonly IOwnerRepository _ownerRepository;
15+
private readonly IMapper _mapper;
16+
17+
public OwnerController(IOwnerRepository ownerRepository, IMapper mapper)
18+
{
19+
_ownerRepository = ownerRepository;
20+
_mapper = mapper;
21+
}
22+
[HttpGet]
23+
[ProducesResponseType(200, Type = typeof(IEnumerable<Owner>))]
24+
public IActionResult GetOwners()
25+
{
26+
var owners = _mapper.Map<List<OwnerDTO>>(_ownerRepository.GetOwners());
27+
if (!ModelState.IsValid)
28+
return BadRequest(ModelState);
29+
return Ok(owners);
30+
}
31+
[HttpGet("{ownerId}")]
32+
[ProducesResponseType(200, Type = typeof(Owner))]
33+
[ProducesResponseType(400)]
34+
public IActionResult GetOwner(int ownerId)
35+
{
36+
if (!_ownerRepository.OwnerExists(ownerId))
37+
return NotFound();
38+
var owner = _mapper.Map<OwnerDTO>(_ownerRepository.GetOwner(ownerId));
39+
if (!ModelState.IsValid)
40+
return BadRequest();
41+
return Ok(owner);
42+
}
43+
44+
[HttpGet("{ownerId}/pokemon")]
45+
[ProducesResponseType(200, Type = typeof(Owner))]
46+
[ProducesResponseType(400)]
47+
public IActionResult GetPokemonByOwner(int ownerId)
48+
{
49+
if (!_ownerRepository.OwnerExists(ownerId))
50+
return NotFound();
51+
var pokemon = _mapper.Map<List<PokemonDTO>>(_ownerRepository.GetPokemonByOwner(ownerId));
52+
if (!ModelState.IsValid)
53+
return BadRequest(ModelState);
54+
return Ok(pokemon);
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using ApiPractise.DTOs;
2+
using ApiPractise.Interfaces;
3+
using ApiPractise.Models;
4+
using AutoMapper;
5+
using Microsoft.AspNetCore.Http;
6+
using Microsoft.AspNetCore.Mvc;
7+
8+
namespace ApiPractise.Controllers;
9+
10+
[Route("api/[controller]")]
11+
[ApiController]
12+
13+
public class PokemonController : ControllerBase
14+
{
15+
private readonly IPokemonRepository _pokemon;
16+
private readonly IMapper _mapper;
17+
18+
public PokemonController(IPokemonRepository pokemon, IMapper mapper)
19+
{
20+
_pokemon = pokemon;
21+
_mapper = mapper;
22+
}
23+
24+
[HttpGet]
25+
[ProducesResponseType(200, Type = typeof(IEnumerable<Pokemon>))]
26+
public IActionResult GetPokemons()
27+
{
28+
var pokemons = _mapper.Map<List<PokemonDTO>>(_pokemon.GetPokemons());
29+
if (!ModelState.IsValid)
30+
return BadRequest(ModelState);
31+
return Ok(pokemons);
32+
}
33+
34+
[HttpGet("{pokeId}")]
35+
[ProducesResponseType(200, Type = typeof(Pokemon))]
36+
[ProducesResponseType(400)]
37+
public IActionResult GetPokemon(int pokeId)
38+
{
39+
if (!_pokemon.PokemonExists(pokeId))
40+
return NotFound();
41+
var pokemon = _mapper.Map<PokemonDTO>(_pokemon.GetPokemonByID(pokeId));
42+
if (!ModelState.IsValid)
43+
return BadRequest();
44+
return Ok(pokemon);
45+
}
46+
47+
[HttpGet("{pokeId}/rating")]
48+
[ProducesResponseType(200, Type = typeof(decimal))]
49+
[ProducesResponseType(400)]
50+
public IActionResult GetPokemonRating(int pokeId)
51+
{
52+
if (!_pokemon.PokemonExists(pokeId))
53+
return NotFound();
54+
var rating = _pokemon.GetPokemonRating(pokeId);
55+
if (!ModelState.IsValid)
56+
return BadRequest();
57+
return Ok(rating);
58+
59+
60+
61+
}
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using ApiPractise.DTOs;
2+
using ApiPractise.Interfaces;
3+
using ApiPractise.Models;
4+
using ApiPractise.Repository;
5+
using AutoMapper;
6+
using Microsoft.AspNetCore.Http;
7+
using Microsoft.AspNetCore.Mvc;
8+
9+
namespace ApiPractise.Controllers;
10+
11+
[Route("api/[controller]")]
12+
[ApiController]
13+
public class ReviewController : ControllerBase
14+
{
15+
private readonly IReviewRepository _reviewRepository;
16+
private readonly IMapper _mapper;
17+
18+
public ReviewController(IReviewRepository reviewRepository, IMapper mapper)
19+
{
20+
_reviewRepository = reviewRepository;
21+
_mapper = mapper;
22+
}
23+
[HttpGet]
24+
[ProducesResponseType(200, Type = typeof(IEnumerable<Review>))]
25+
public IActionResult GetReviews()
26+
{
27+
var reviews = _mapper.Map<List<ReviewDTO>>(_reviewRepository.GetReviews());
28+
if (!ModelState.IsValid)
29+
return BadRequest(ModelState);
30+
return Ok(reviews);
31+
}
32+
[HttpGet("{reviewId}")]
33+
[ProducesResponseType(200, Type = typeof(Review))]
34+
[ProducesResponseType(400)]
35+
public IActionResult GetReview(int reviewId)
36+
{
37+
if (!_reviewRepository.ReviewExists(reviewId))
38+
return NotFound();
39+
var review = _mapper.Map<ReviewDTO>(_reviewRepository.GetReview(reviewId));
40+
if (!ModelState.IsValid)
41+
return BadRequest();
42+
return Ok(review);
43+
}
44+
45+
[HttpGet("pokemon/{pokeId}")]
46+
[ProducesResponseType(200, Type = typeof(Review))]
47+
[ProducesResponseType(400)]
48+
public IActionResult GetReviewForAPokemon(int pokeId)
49+
{
50+
var review = _mapper.Map<List<ReviewDTO>>(_reviewRepository.GetReviewsOfPokemon(pokeId));
51+
if (!ModelState.IsValid)
52+
return BadRequest();
53+
return Ok(review);
54+
}
55+
}

0 commit comments

Comments
 (0)