-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from samorysundjata/develop
Develop
- Loading branch information
Showing
10 changed files
with
217 additions
and
55 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,31 +1 @@ | ||
{ | ||
"collection": { | ||
"name": "MalaDiretaCollection", | ||
"requests": [ | ||
{ | ||
"name": "GetAllContacts", | ||
"request": { | ||
"method": "GET", | ||
"url": "http://localhost:5000/api/contacts", | ||
"headers": { | ||
"Content-Type": "application/json" | ||
} | ||
} | ||
}, | ||
{ | ||
"name": "AddContact", | ||
"request": { | ||
"method": "POST", | ||
"url": "http://localhost:5000/api/contacts", | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"body": { | ||
"name": "John Doe", | ||
"email": "[email protected]" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
{"_type":"export","__export_format":4,"__export_date":"2024-10-28T21:46:45.361Z","__export_source":"insomnia.desktop.app:v2023.2.2","resources":[{"_id":"req_3a5028089c284c9d99b06b0d83afc55b","parentId":"fld_2a507f61639c445786f708d6055e72d4","modified":1700824063451,"created":1697028460944,"url":"https://localhost:7275/login","name":"Autenticacao","description":"","method":"POST","body":{"mimeType":"application/json","text":"{\r\n \"userName\": \"user\",\r\n \"password\": \"pass123\"\r\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json"}],"authentication":{"type":"bearer","disabled":false,"token":"{{access_token}}","prefix":""},"metaSortKey":-1697028460957.5,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"fld_2a507f61639c445786f708d6055e72d4","parentId":"fld_50452a95a9b3411caa886fc2d9fc279f","modified":1700824059793,"created":1700824059793,"name":"Autenticação","description":"","environment":{},"environmentPropertyOrder":null,"metaSortKey":-1700824059793,"_type":"request_group"},{"_id":"fld_50452a95a9b3411caa886fc2d9fc279f","parentId":"wrk_88f6c367626e4a66869b60ab048f0d46","modified":1697028460933,"created":1697028460933,"name":"MalaDireta","description":"Collections para o projeto Mala Direta em C#","environment":{"access_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoidXNlciIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL25hbWVpZGVudGlmaWVyIjoiZTI4NzQ3Y2ItOWIyYS00MWZhLTgwN2EtZGI0NjA2OTU1N2ZhIiwiZXhwIjoxNjkxMTQ4MjAyLCJpc3MiOiJTaXN0ZW1hc1Jlc3BvbnNpdm9zLmNvbS5iciIsImF1ZCI6Imh0dHBzOi8vc2lzdGVtYXNyZXNwb25zaXZvcy5jb20uYnIifQ.Atl8d3_8gRwmtXhGyUI1D1pvfOmxDCc3TeLgPfOl_N0"},"environmentPropertyOrder":null,"metaSortKey":-1697028460933,"_type":"request_group"},{"_id":"wrk_88f6c367626e4a66869b60ab048f0d46","parentId":null,"modified":1697028395061,"created":1697028395061,"name":"Mala Direta C#","description":"","scope":"collection","_type":"workspace"},{"_id":"req_e9c0f762b32b4914a3604bb06aea3e6f","parentId":"fld_76bfa89b7701417f97d2d731a5b95fb3","modified":1730151672354,"created":1697028460947,"url":"{{ _.localhost }}/Destinatario/destinatarios","name":"Clientes","description":"","method":"GET","body":{"mimeType":"application/json","text":""},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json"}],"authentication":{"type":"bearer","disabled":false,"token":"{{access_token}}","prefix":""},"metaSortKey":-1697028460923,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"fld_76bfa89b7701417f97d2d731a5b95fb3","parentId":"fld_50452a95a9b3411caa886fc2d9fc279f","modified":1730151413575,"created":1700824027993,"name":"Destinatarios","description":"","environment":{},"environmentPropertyOrder":null,"metaSortKey":-1700824027993,"_type":"request_group"},{"_id":"req_f57700ee3d3448bebc033b8e2b564612","parentId":"fld_76bfa89b7701417f97d2d731a5b95fb3","modified":1730151799418,"created":1697028460948,"url":"{{ _.localhost }}/Cliente/5","name":"Cliente","description":"","method":"GET","body":{"mimeType":"application/json","text":""},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json"}],"authentication":{},"metaSortKey":-1697028460873,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_7f2db88851fa48fcbf4c66584428bb99","parentId":"fld_76bfa89b7701417f97d2d731a5b95fb3","modified":1730151857434,"created":1697028460950,"url":"{{ _.localhost }}/Destinatario/destinatario","name":"Cliente","description":"","method":"POST","body":{"mimeType":"application/json","text":"{\n \"nome\": \"{% gerarNome false, '', true, true, '', true, false %}\",\n \"telefone\": \"2199966887\",\n \"email\": \"{% gerarEmail 'email.test.', true, 1, 9999, '', 'mock.com.br' %}\",\n \"endereco\": {\n \"enderecoId\": {% prompt 'Numero', 'Numero', '1', '', false, true %},\n \"logradouro\": \"Rua Qualquer, {% now 'custom', 'ss' %}\",\n \"complemento\": \"apto {% now 'custom', 'ss' %}\",\n \"bairro\": \"Botafogo\",\n \"cidade\": \"Cidade\",\n \"estado\": \"RJ\",\n \"cep\": \"{% geradorDeCEP false, 'sp', false, false %}\"\n }\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json"}],"authentication":{"type":"bearer","token":"{{ _.access_token }}"},"metaSortKey":-1697028460848,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_70182c8a22e7400096520aaa4b269a32","parentId":"fld_76bfa89b7701417f97d2d731a5b95fb3","modified":1700824079878,"created":1697028460951,"url":"https://localhost:7275/Cliente/2","name":"Cliente","description":"","method":"PUT","body":{"mimeType":"application/json","text":"{\n \"clienteId\": 2,\n \"nome\": \"Joe Cabbage Jr\",\n \"telefone\": \"219997475\",\n \"email\": \"[email protected]\",\n \"endereco\": {\n\t\t\"enderecoId\": 2,\n\t\t\"logradouro\": \"Rua Domingos José Poli, 50\",\n\t\t\"complemento\": \"apto 12\",\n\t\t\"cidade\": \"Porto Alegre\",\n\t\t\"bairro\": \"Restinga\",\n\t\t\"estado\": \"RS\",\n\t\t\"cep\": \"91790072\"\n\t}\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json"}],"authentication":{},"metaSortKey":-1697028460823,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_64e6989997be4de9bdd7a075a7c0341b","parentId":"fld_76bfa89b7701417f97d2d731a5b95fb3","modified":1700824589393,"created":1697028460952,"url":"https://localhost:7275/Cliente/3","name":"Cliente","description":"","method":"DELETE","body":{"mimeType":"application/json","text":""},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json"}],"authentication":{},"metaSortKey":-1697028460773,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_8b582992b2b844a8987303d56ac27a35","parentId":"fld_ba99f498c60c427984bb5f0339032267","modified":1730151693499,"created":1697028460953,"url":"{{ _.localhost }}/Endereco/enderecos","name":"Enderecos","description":"","method":"GET","body":{"mimeType":"application/json","text":""},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json"}],"authentication":{"type":"bearer","disabled":false,"token":"{{access_token}}","prefix":""},"metaSortKey":-1697028460957.375,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"fld_ba99f498c60c427984bb5f0339032267","parentId":"fld_50452a95a9b3411caa886fc2d9fc279f","modified":1730151425145,"created":1700824206706,"name":"Enderecos","description":"","environment":{},"environmentPropertyOrder":null,"metaSortKey":-1700824027943,"_type":"request_group"},{"_id":"req_8c6a382584e54c2fa78e1416c97ad989","parentId":"fld_ba99f498c60c427984bb5f0339032267","modified":1730151704880,"created":1697028460954,"url":"{{ _.localhost }}/Endereco/1","name":"Endereco","description":"","method":"GET","body":{"mimeType":"application/json","text":""},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json"}],"authentication":{"type":"bearer","disabled":false,"token":"{{access_token}}","prefix":""},"metaSortKey":-1697028460907.375,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_db4e8525ff294d359378e87ad3b3d10c","parentId":"fld_ba99f498c60c427984bb5f0339032267","modified":1730151716533,"created":1697028460955,"url":"{{ _.localhost }}/Endereco/","name":"Endereco","description":"","method":"POST","body":{"mimeType":"application/json","text":"{\n \"logradouro\": \"Rua dos Andrades, 666\",\n \"complemento\": \"apto 12\",\n \"cidade\": \"Pouso Alegre\",\n \"bairro\": \"Centro\",\n \"estado\": \"MG\",\n \"cep\": \"{% geradorDeCEP false, 'sp', false, false %}\"\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json"}],"authentication":{"type":"bearer","disabled":false,"token":"{{access_token}}","prefix":""},"metaSortKey":-1697028460857.375,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_ef65d32eafd94e64a318ecb72afbe67a","parentId":"fld_ba99f498c60c427984bb5f0339032267","modified":1730151787437,"created":1697028460956,"url":"{{ _.localhost }}/Endereco/10","name":"Endereco","description":"","method":"PUT","body":{"mimeType":"application/json","text":"{\n \"enderecoId\": 10,\n \"logradouro\": \"Rua dos Andrades\",\n \"complemento\": \"apto {% geradorDeCPF false %}\",\n \"cidade\": \"Porto Alegre\",\n \"bairro\": \"Restinga\",\n \"estado\": \"MG\",\n \"cep\": \"{% geradorDeCEP false, 'mg', false, false %}\"\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json"}],"authentication":{"type":"bearer","disabled":false,"token":"{{access_token}}","prefix":""},"metaSortKey":-1697028460807.375,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_801a49d35b6b42358fba5bef94be2693","parentId":"fld_ba99f498c60c427984bb5f0339032267","modified":1730151779464,"created":1697028460957,"url":"{{ _.localhost }}/Endereco/8","name":"Endereco","description":"","method":"DELETE","body":{"mimeType":"application/json","text":""},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json"}],"authentication":{"type":"bearer","disabled":false,"token":"{{access_token}}","prefix":""},"metaSortKey":-1697028460757.375,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_d515dda0cbf441648e596d64cd77353c","parentId":"fld_ba99f498c60c427984bb5f0339032267","modified":1730151773945,"created":1697028460958,"url":"{{ _.localhost }}/Endereco/buscacep/","name":"CEP","description":"","method":"GET","body":{"mimeType":"application/json","text":""},"parameters":[{"name":"zipcode","value":"{% geradorDeCEP false, 'sp', false, false %}","disabled":false,"id":"pair_6489e835641f4e2099bc34a87a438bd8"}],"headers":[{"name":"Content-Type","value":"application/json"}],"authentication":{"type":"bearer","token":"{{ _.access_token }}"},"metaSortKey":-1697028460707.375,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"env_5d93bf96b567cf88f0fa52b50baa80c2ee0a56e2","parentId":"wrk_88f6c367626e4a66869b60ab048f0d46","modified":1730151667531,"created":1697028395146,"name":"Base Environment","data":{"localhost":"https://localhost:44372"},"dataPropertyOrder":{"&":["localhost"]},"color":null,"isPrivate":false,"metaSortKey":1697028395146,"_type":"environment"},{"_id":"jar_5d93bf96b567cf88f0fa52b50baa80c2ee0a56e2","parentId":"wrk_88f6c367626e4a66869b60ab048f0d46","modified":1697028395154,"created":1697028395154,"name":"Default Jar","cookies":[],"_type":"cookie_jar"},{"_id":"spc_7e8f21bdd3674fec8a69f2f2611b54c2","parentId":"wrk_88f6c367626e4a66869b60ab048f0d46","modified":1697028395062,"created":1697028395062,"fileName":"Mala Direta C#","contents":"","contentType":"yaml","_type":"api_spec"}]} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,102 @@ | ||
using Core.Services.Interfaces; | ||
using Core.Entities; | ||
using Core.Services.Interfaces; | ||
using log4net; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Core.Services | ||
{ | ||
public class DestinatarioService : IDestinatarioService | ||
public class DestinatarioService: IDestinatarioService | ||
{ | ||
private static readonly ILog Log = LogManager.GetLogger(typeof(DestinatarioService)); | ||
private readonly DbContext _context; | ||
|
||
public DestinatarioService(DbContext context) | ||
{ | ||
context = _context; | ||
} | ||
|
||
public async Task AddDestinatarioAsync(Destinatario destinatario) | ||
{ | ||
if (destinatario == null) | ||
{ | ||
throw new ArgumentNullException(nameof(destinatario)); | ||
} | ||
else | ||
{ | ||
try | ||
{ | ||
await _context.Set<Destinatario>().AddAsync(destinatario); | ||
await _context.SaveChangesAsync(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Error($"An error occurred while adding the destinatario: {ex.Message}", ex); | ||
throw new Exception($"An error occurred while adding the destinatario: {ex.Message}", ex); | ||
} | ||
} | ||
} | ||
|
||
public async Task DeleteDestinatarioAsync(int id) | ||
{ | ||
var destinatario = await _context.Set<Destinatario>().FindAsync(id); | ||
if (destinatario != null) | ||
{ | ||
try | ||
{ | ||
_context.Set<Destinatario>().Remove(destinatario); | ||
await _context.SaveChangesAsync(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Error($"An error occurred while deleting the destinatario with ID {id}: {ex.Message}", ex); | ||
throw new Exception($"An error occurred while deleting the destinatario with ID {id}: {ex.Message}", ex); | ||
} | ||
} | ||
} | ||
|
||
public async Task<IEnumerable<Destinatario>> GetAllDestinatariosAsync() | ||
{ | ||
try | ||
{ | ||
return await _context.Set<Destinatario>().ToListAsync(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Error($"An error occurred while retrieving all destinatarios: {ex.Message}", ex); | ||
throw new Exception($"An error occurred while retrieving all destinatarios: {ex.Message}", ex); | ||
} | ||
} | ||
|
||
public async Task<Destinatario?> GetDestinatarioByIdAsync(int id) | ||
Check warning on line 70 in src/Core/Services/DestinatarioService.cs GitHub Actions / build
|
||
{ | ||
try | ||
{ | ||
return await _context.Set<Destinatario>().FindAsync(id); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Error($"An error occurred while retrieving the destinatario with ID {id}: {ex.Message}", ex); | ||
throw new Exception($"An error occurred while retrieving the destinatario with ID {id}: {ex.Message}", ex); | ||
} | ||
} | ||
|
||
public async Task UpdateDestinatarioAsync(Destinatario destinatario) | ||
{ | ||
if (destinatario == null) | ||
{ | ||
throw new ArgumentNullException(nameof(destinatario)); | ||
} | ||
|
||
try | ||
{ | ||
_context.Set<Destinatario>().Update(destinatario); | ||
await _context.SaveChangesAsync(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Error($"An error occurred while updating the destinatario with ID {destinatario.Id}: {ex.Message}", ex); | ||
throw new Exception($"An error occurred while updating the destinatario with ID {destinatario.Id}: {ex.Message}", ex); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.