Skip to content

Commit 8703e33

Browse files
up
1 parent 5341c71 commit 8703e33

File tree

84 files changed

+75101
-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.

84 files changed

+75101
-0
lines changed

DTO/cepRequest.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace mail_api.DTO
2+
{
3+
public class cepRequest
4+
{
5+
public string Cep { get; set; }
6+
}
7+
}

Data/CepRepository.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System.Security.Cryptography.Xml;
2+
using Dapper;
3+
using Npgsql;
4+
5+
namespace mail_api.Data
6+
{
7+
public class CepRepository: ICepRepository
8+
{
9+
private const string connectionString = " connection String ";
10+
11+
public async Task<CepInfo> GetAdressByCep(string cep)
12+
{
13+
const string sql = @"
14+
SELECT Cep, Logradouro, Complemento, Bairro, Localidade, Uf, Ibge, Gia, Ddd, Siafi
15+
FROM CepInfo
16+
WHERE Cep = @Cep";
17+
18+
try
19+
{
20+
await using (var connection = new NpgsqlConnection(connectionString))
21+
{
22+
var result = await connection.QuerySingleOrDefaultAsync<CepInfo>(sql, new { Cep = cep }).ConfigureAwait(false);
23+
return result;
24+
}
25+
}
26+
catch (Exception ex)
27+
{
28+
throw new Exception("Error fetching data from the database", ex);
29+
}
30+
}
31+
32+
public async Task<bool> Create(CepInfo cep)
33+
{
34+
const string sql = @"
35+
INSERT INTO CepInfo (Cep, Logradouro, Complemento, Bairro, Localidade, Uf, Ibge, Gia, Ddd, Siafi)
36+
VALUES (@Cep, @Logradouro, @Complemento, @Bairro, @Localidade, @Uf, @Ibge, @Gia, @Ddd, @Siafi)";
37+
38+
try
39+
{
40+
await using (var connection = new NpgsqlConnection(connectionString))
41+
{
42+
var result = await connection.ExecuteAsync(sql, new
43+
{
44+
cep.Cep,
45+
cep.Logradouro,
46+
cep.Complemento,
47+
cep.Bairro,
48+
cep.Localidade,
49+
cep.Uf,
50+
cep.Ibge,
51+
cep.Gia,
52+
cep.Ddd,
53+
cep.Siafi
54+
}).ConfigureAwait(false);
55+
56+
return result > 0;
57+
}
58+
}
59+
catch (Exception ex)
60+
{
61+
throw new Exception("Error fetching data from the database", ex);
62+
}
63+
}
64+
65+
}
66+
}

Model/CepInfo.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace mail_api.Model
2+
{
3+
public class CepInfo
4+
{
5+
public string Cep { get; set; }
6+
public string Logradouro { get; set; }
7+
public string Complemento { get; set; }
8+
public string Bairro { get; set; }
9+
public string Localidade { get; set; }
10+
public string Uf { get; set; }
11+
public string Ibge { get; set; }
12+
public string Gia { get; set; }
13+
public string Ddd { get; set; }
14+
public string Siafi { get; set; }
15+
}
16+
}

Pages/Error.cshtml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@page
2+
@model ErrorModel
3+
@{
4+
ViewData["Title"] = "Error";
5+
}
6+
7+
<h1 class="text-danger">Error.</h1>
8+
<h2 class="text-danger">An error occurred while processing your request.</h2>
9+
10+
@if (Model.ShowRequestId)
11+
{
12+
<p>
13+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
14+
</p>
15+
}
16+
17+
<h3>Development Mode</h3>
18+
<p>
19+
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
20+
</p>
21+
<p>
22+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
23+
It can result in displaying sensitive information from exceptions to end users.
24+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
25+
and restarting the app.
26+
</p>

Pages/Error.cshtml.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
using System.Diagnostics;
4+
5+
namespace mail_api.Pages
6+
{
7+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
8+
[IgnoreAntiforgeryToken]
9+
public class ErrorModel : PageModel
10+
{
11+
public string? RequestId { get; set; }
12+
13+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
14+
15+
private readonly ILogger<ErrorModel> _logger;
16+
17+
public ErrorModel(ILogger<ErrorModel> logger)
18+
{
19+
_logger = logger;
20+
}
21+
22+
public void OnGet()
23+
{
24+
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
25+
}
26+
}
27+
28+
}

Pages/Index.cshtml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@page
2+
@model IndexModel
3+
@{
4+
ViewData["Title"] = "Home page";
5+
}
6+
7+
<div class="text-center">
8+
<h1 class="display-4">Welcome</h1>
9+
<p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
10+
</div>

Pages/Index.cshtml.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
4+
namespace mail_api.Pages
5+
{
6+
public class IndexModel : PageModel
7+
{
8+
private readonly ILogger<IndexModel> _logger;
9+
10+
public IndexModel(ILogger<IndexModel> logger)
11+
{
12+
_logger = logger;
13+
}
14+
15+
public void OnGet()
16+
{
17+
18+
}
19+
}
20+
}

Pages/Privacy.cshtml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@page
2+
@model PrivacyModel
3+
@{
4+
ViewData["Title"] = "Privacy Policy";
5+
}
6+
<h1>@ViewData["Title"]</h1>
7+
8+
<p>Use this page to detail your site's privacy policy.</p>

Pages/Privacy.cshtml.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
4+
namespace mail_api.Pages
5+
{
6+
public class PrivacyModel : PageModel
7+
{
8+
private readonly ILogger<PrivacyModel> _logger;
9+
10+
public PrivacyModel(ILogger<PrivacyModel> logger)
11+
{
12+
_logger = logger;
13+
}
14+
15+
public void OnGet()
16+
{
17+
}
18+
}
19+
20+
}

Pages/Shared/_Layout.cshtml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>@ViewData["Title"] - mail_api</title>
7+
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
8+
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
9+
<link rel="stylesheet" href="~/mail_api.styles.css" asp-append-version="true" />
10+
</head>
11+
<body>
12+
<header>
13+
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
14+
<div class="container">
15+
<a class="navbar-brand" asp-area="" asp-page="/Index">mail_api</a>
16+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
17+
aria-expanded="false" aria-label="Toggle navigation">
18+
<span class="navbar-toggler-icon"></span>
19+
</button>
20+
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
21+
<ul class="navbar-nav flex-grow-1">
22+
<li class="nav-item">
23+
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
24+
</li>
25+
<li class="nav-item">
26+
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
27+
</li>
28+
</ul>
29+
</div>
30+
</div>
31+
</nav>
32+
</header>
33+
<div class="container">
34+
<main role="main" class="pb-3">
35+
@RenderBody()
36+
</main>
37+
</div>
38+
39+
<footer class="border-top footer text-muted">
40+
<div class="container">
41+
&copy; 2024 - mail_api - <a asp-area="" asp-page="/Privacy">Privacy</a>
42+
</div>
43+
</footer>
44+
45+
<script src="~/lib/jquery/dist/jquery.min.js"></script>
46+
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
47+
<script src="~/js/site.js" asp-append-version="true"></script>
48+
49+
@await RenderSectionAsync("Scripts", required: false)
50+
</body>
51+
</html>

0 commit comments

Comments
 (0)