{"id":29916621,"url":"https://github.com/leandrocunha526/hotel-api-challenge-dotnet","last_synced_at":"2026-05-10T05:12:27.103Z","repository":{"id":305128146,"uuid":"1020964022","full_name":"leandrocunha526/hotel-api-challenge-dotnet","owner":"leandrocunha526","description":"O objetivo é gerenciar o processo de hospedagem em um hotel, permitindo o controle de hóspedes, suítes e reservas.","archived":false,"fork":false,"pushed_at":"2025-07-18T12:27:04.000Z","size":37,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-18T13:45:09.928Z","etag":null,"topics":["asp-net-core","csharp","dotnet","dotnet-core","entity-framework","sql-server"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leandrocunha526.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-16T16:59:42.000Z","updated_at":"2025-07-18T12:27:07.000Z","dependencies_parsed_at":"2025-07-18T13:55:42.778Z","dependency_job_id":null,"html_url":"https://github.com/leandrocunha526/hotel-api-challenge-dotnet","commit_stats":null,"previous_names":["leandrocunha526/hotel-api-challenge-dotnet"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/leandrocunha526/hotel-api-challenge-dotnet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leandrocunha526%2Fhotel-api-challenge-dotnet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leandrocunha526%2Fhotel-api-challenge-dotnet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leandrocunha526%2Fhotel-api-challenge-dotnet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leandrocunha526%2Fhotel-api-challenge-dotnet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leandrocunha526","download_url":"https://codeload.github.com/leandrocunha526/hotel-api-challenge-dotnet/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leandrocunha526%2Fhotel-api-challenge-dotnet/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268337865,"owners_count":24234533,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asp-net-core","csharp","dotnet","dotnet-core","entity-framework","sql-server"],"created_at":"2025-08-02T05:01:11.181Z","updated_at":"2026-05-10T05:12:27.048Z","avatar_url":"https://github.com/leandrocunha526.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🏨 Sistema de Reservas de Hotel\n\n## 📚 Descrição do projeto\n\n**ATENÇÃO: Este projeto é um projeto de estudo e o conteúdo pode ser modificado seguindo boas práticas de desenvolvimento (não está pronto).**\n\nEste é um projeto de **API RESTful**, desenvolvido em **ASP.NET Core 9**, utilizando **Entity Framework Core 9** com persistência no **SQL Server**.  \nO objetivo é gerenciar o processo de hospedagem em um hotel, permitindo o controle de hóspedes, suítes e reservas.\n\n---\n\n## ⚙️ Funcionalidades principais\n\n✅ Cadastro e consulta de hóspedes (Pessoa)  \n✅ Cadastro e consulta de suítes (Suite)  \n✅ Cadastro de reservas (Reserva), associando hóspedes a uma suíte  \n✅ Cálculo do valor total da reserva com desconto automático de 10% para estadias iguais ou superiores a 10 dias  \n✅ Validação para impedir reservas com número de hóspedes superior à capacidade da suíte  \n✅ Persistência completa dos dados no SQL Server via Entity Framework Core  \n✅ Informa na rota de suítes quando há reserva nos dias atuais usando inner join do SQL  \n✅ Adiciona ambientes isolados de teste e desenvolvimento para seguir boas práticas de ambientes com mais 1 alternativa de banco de dados  \n\n---\n\n## 🏗️ Estrutura do projeto\n\n- **Pessoa**  \n  - Nome e sobrenome do hóspede.\n- **Suite**  \n  - Tipo da suíte, capacidade máxima de hóspedes e valor da diária.\n- **Reserva**  \n  - Dias reservados, hóspedes associados e a suíte escolhida.\n\n---\n\n## 💻 Tecnologias utilizadas\n\n- [.NET 9 (ASP.NET Core Web API)](https://dotnet.microsoft.com/)  \n- [Entity Framework Core 9](https://docs.microsoft.com/ef/core)  \n- [SQL Server](https://www.microsoft.com/sql-server)  \n- Swagger (para testes dos endpoints REST)  \n- C#\n- SQLite\n\n---\n\n## 🚀 Como executar o projeto\n\nGere as migrations do Entity Framework Core e aplique-as ao banco de dados SQL Server.\n\n```bash\ndotnet ef migrations add InitialCreate\n```\n\nCertifique-se de que o SQL Server esteja em execução e que a string de conexão no arquivo `appsettings.json` esteja configurada corretamente para apontar para o seu banco de dados.\n\nDepois, atualize o banco de dados com as migrations criadas:\n\n```bash\ndotnet ef database update\n```\n\nPara usar o ambiente de teste:\n\n```bash\nexport ASPNETCORE_ENVIRONMENT=Test\n```\n\nUso de gerador de código via aspnet-codegenerator ou via VS IDE, exemplo:\n\n```bash\ndotnet aspnet-codegenerator controller -name ReservationController -async -api -m Reservation -dc DataContext -outDir Controllers\n```\n\nNOTE: Os arquivos foram alterados seguindo a necessidade do projeto.\n\n## Regras de negócio\n\nHá um desconto inserido para reservas de 10 dias ou mais de 10% de desconto sendo adicionado ao inserir reserva de hotel.\n\nImplementando SQL Inner Join no SQL Server para verificação de reserva dentro do período de check in/check out:\n\n```sql\nSELECT\n    s.Id AS SuiteId,\n    s.Tipo,\n    s.Capacidade,\n    s.PriceByDay,\n    r.Id AS ReservationId,\n    r.CheckInDate,\n    r.CheckOutDate\nFROM\n    Suites s\nINNER JOIN\n    Reservations r ON r.SuiteId = s.Id\nWHERE\n    r.CheckInDate \u003c= GETDATE()\n    AND r.CheckOutDate \u003e= GETDATE()\nORDER BY r.SuiteId ASC\n```\n\nPara cálculo usando o banco de dados:\n\nUsando functions:\n\n```sql\nCREATE FUNCTION dbo.CalcularTotalComDesconto\n(\n    @CheckIn DATE,\n    @CheckOut DATE,\n    @PrecoPorDia DECIMAL(10, 2)\n)\nRETURNS DECIMAL(10, 2)\nAS\nBEGIN\n    DECLARE @Dias INT = DATEDIFF(DAY, @CheckIn, @CheckOut)\n    DECLARE @TotalPrice DECIMAL(10, 2)\n\n    IF @Dias \u003e= 10\n        SET @TotalPrice = @Dias * @PrecoPorDia * 0.9\n    ELSE\n        SET @TotalPrice = @Dias * @PrecoPorDia\n\n    RETURN @TotalPrice\nEND\n```\n\nPode usar com o exemplo: `SELECT dbo.CalcularTotalComDesconto('2025-08-01', '2025-08-11', 150.00) AS TotalComDesconto` ou:\n\n```sql\nDECLARE @CheckIn DATE = '2025-08-01';\nDECLARE @CheckOut DATE = '2025-08-12';\nDECLARE @PrecoPorDia DECIMAL(10,2) = 150.00;\n\nSELECT dbo.CalcularTotalComDesconto(@CheckIn, @CheckOut, @PrecoPorDia) AS TotalComDesconto;\n```\n\nPerfeito para simulações.\n\nPara obter com as informações salvas em banco de dados, use:\n\n```sql\nSELECT \n    r.Id AS ReservationId,\n    r.PersonId,\n    r.SuiteId,\n    r.CheckInDate,\n    r.CheckOutDate,\n    s.PriceByDay,\n    DATEDIFF(DAY, r.CheckInDate, r.CheckOutDate) AS Dias,\n    dbo.CalcularTotalComDesconto(r.CheckInDate, r.CheckOutDate, s.PriceByDay) AS TotalCalculado,\n    CASE \n        WHEN DATEDIFF(DAY, r.CheckInDate, r.CheckOutDate) \u003e= 10 THEN 'Desconto aplicado'\n        ELSE 'Sem desconto'\n    END AS Observacao\nFROM Reservations r\nJOIN Suites s ON r.SuiteId = s.Id\nWHERE DATEDIFF(DAY, r.CheckInDate, r.CheckOutDate) \u003e= 10;\n```\n\nUsando Trigger:\n\n```sql\nCREATE TRIGGER trg_InserirReservaComDesconto\nON Reservations\nINSTEAD OF INSERT\nAS\nBEGIN\n    SET NOCOUNT ON;\n\n    INSERT INTO Reservations (PersonId, SuiteId, CheckInDate, CheckOutDate, CreatedAt, UpdatedAt, TotalPrice)\n    SELECT \n        i.PersonId,\n        i.SuiteId,\n        i.CheckInDate,\n        i.CheckOutDate,\n        i.CreatedAt,\n        i.UpdatedAt,\n        CASE \n            WHEN DATEDIFF(DAY, i.CheckInDate, i.CheckOutDate) \u003e= 10\n                THEN DATEDIFF(DAY, i.CheckInDate, i.CheckOutDate) * s.PriceByDay * 0.9\n            ELSE DATEDIFF(DAY, i.CheckInDate, i.CheckOutDate) * s.PriceByDay\n        END AS TotalPrice\n    FROM inserted i\n    JOIN Suites s ON s.Id = i.SuiteId;\nEND\n```\n\nAo fornecer o comando:\n\n```sql\nselect * from Reservations\n```\n\nDeve exibir o campo \"TotalPrice\" já calculado após inserts.\n\n**Atenção**:\n\n- Use a trigger apenas para cenários onde você controla totalmente a inserção, como ambientes internos ou testes manuais.\n\n- **NOTE**: se sua API já estiver tratando o campo TotalPrice, desative a trigger ou use uma abordagem com AFTER INSERT e atualize o campo.\n\n- Teste bem antes de usar em produção.\n\n## TODO\n\n- [ ] Adicionar autenticação (ROLES: ADMIN/CLIENTE) (PENDENTE)\n- [ ] Adicionar testes automatizados (PENDENTE)\n- [ ] Ajustes nas regras de negócio que estão presentes no controller que deverão ser refatoradas (isso pode atrapalhar testes automatizados e a forma que foi implementado seria para testes manuais) seguindo questão de SRP e deve conter as regras em um service (PENDENTE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleandrocunha526%2Fhotel-api-challenge-dotnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleandrocunha526%2Fhotel-api-challenge-dotnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleandrocunha526%2Fhotel-api-challenge-dotnet/lists"}