Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create endpoint to register customers #28

Merged
merged 5 commits into from
May 1, 2024

Conversation

italopessoa
Copy link
Member

No description provided.

…register-customers

# Conflicts:
#	.docker/setup.sql
#	docker-compose.yml
#	src/FIAP.TechChallenge.ByteMeBurger.Api/Configuration/MySqlSettings.cs
#	src/FIAP.TechChallenge.ByteMeBurger.Api/Program.cs
#	src/FIAP.TechChallenge.ByteMeBurger.Api/appsettings.Development.json
Copy link

coderabbitai bot commented May 1, 2024

Walkthrough

The recent updates focus on enhancing the application's infrastructure, error handling, and overall robustness. Changes include adding MySQL support alongside MongoDB, refining error messages, improving health checks, and restructuring service configurations. The codebase underwent reorganization for clarity and maintainability, introducing new classes for service registration, database configuration, and repository patterns. These modifications aim to enhance the application's functionality and developer experience.

Changes

Files Change Summary
.env.template, docker-compose.yml Updated to support MySQL configurations, modified service tags, port mappings, and added health checks.
src/.../OrderController.cs, src/.../CreateOrderCommandDto.cs, src/.../OrderDto.cs, src/.../InMemoryOrderRepository.cs Enhanced error messages, simplified data transfer objects, and reorganized class properties.
src/.../FIAP.TechChallenge.ByteMeBurger.Api.csproj, src/.../Program.cs Added package references for health checks, restructured service configurations, and registered new services.
src/.../ServiceCollectionExtensions.cs, src/.../WebApplicationBuilderExtensions.cs, src/.../Repository/... Introduced new classes for service registration, database configuration, and implemented repository patterns.
tests/.../Repository/... Added test cases for repository methods and minor adjustments in test file structures.

Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 9145769 and dd8c8b8.
Files selected for processing (1)
  • tests/FIAP.TechChallenge.ByteMeBurger.Infrastructure.Test/Repository/CustomerRepositoryDapperTest.cs (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/FIAP.TechChallenge.ByteMeBurger.Infrastructure.Test/Repository/CustomerRepositoryDapperTest.cs

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Out of diff range and nitpick comments (1)
src/FIAP.TechChallenge.ByteMeBurger.Infrastructure/Repository/InMemoryOrderRepository.cs (1)

Line range hint 27-27: Mismatch in nullability between the method's return type and the actual returned value. Ensure consistency to avoid runtime issues.

- return Task.FromResult<Order?>(null);
+ return Task.FromResult<Order?>(null);

Comment on lines +9 to +13
MYSQL_DATABASE=techchallenge
MYSQL_PORT=3306
MYSQL_USERID=techchallenge
MYSQL_PASSWORD=techchallengeFIAP
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that sensitive information such as MYSQL_PASSWORD is securely managed and not hardcoded in environment files in production environments.

docker-compose.yml Show resolved Hide resolved
Comment on lines +37 to +38
builder.Services.AddHealthChecks()
.AddMySql(provider => provider.GetRequiredService<DbConnectionStringBuilder>().ConnectionString);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The verification process has revealed that the appsettings.json file does not contain the necessary ConnectionString key required for the MySQL database connection. This is a critical issue as the application relies on this connection string to interact with the database. It is recommended to add the appropriate connection string configuration to ensure the application functions correctly.

  • Please add the ConnectionString key with the correct format to the appsettings.json file.
Analysis chain

Added MySQL health check. Verify that the connection string provided matches the expected format and contains all necessary information.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the MySQL connection string format in the configuration.

# Check the connection string format in the configuration file.
grep 'ConnectionString' src/FIAP.TechChallenge.ByteMeBurger.Api/appsettings.json

Length of output: 80



Script:

#!/bin/bash
# Check if the appsettings.json file exists and list its contents
if [ -f src/FIAP.TechChallenge.ByteMeBurger.Api/appsettings.json ]; then
    echo "appsettings.json exists."
    cat src/FIAP.TechChallenge.ByteMeBurger.Api/appsettings.json
else
    echo "appsettings.json does not exist."
fi

Length of output: 341

Comment on lines 49 to 67
[Fact]
public async Task FindByCpf_Success()
{
// Arrange
var expectedCustomer = new Customer(Cpf, "italo", "italo@gmail.com");

_mockConnection.SetupDapperAsync(c => c.QuerySingleOrDefaultAsync<Customer>(It.IsAny<string>(), null, null, null, null))
.ReturnsAsync(expectedCustomer);

// Act
var result = await _target.FindByCpfAsync(Cpf);

// Assert
using (new AssertionScope())
{
result.Should().NotBeNull();
result.Should().Be(expectedCustomer);
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FindByCpf_Success test method effectively tests the scenario where a customer is found. Consider adding more detailed assertions to verify the properties of the returned customer object.

- result.Should().Be(expectedCustomer);
+ result.Should().BeEquivalentTo(expectedCustomer, options => options.ComparingByMembers<Customer>());

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
[Fact]
public async Task FindByCpf_Success()
{
// Arrange
var expectedCustomer = new Customer(Cpf, "italo", "italo@gmail.com");
_mockConnection.SetupDapperAsync(c => c.QuerySingleOrDefaultAsync<Customer>(It.IsAny<string>(), null, null, null, null))
.ReturnsAsync(expectedCustomer);
// Act
var result = await _target.FindByCpfAsync(Cpf);
// Assert
using (new AssertionScope())
{
result.Should().NotBeNull();
result.Should().Be(expectedCustomer);
}
}
[Fact]
public async Task FindByCpf_Success()
{
// Arrange
var expectedCustomer = new Customer(Cpf, "italo", "italo@gmail.com");
_mockConnection.SetupDapperAsync(c => c.QuerySingleOrDefaultAsync<Customer>(It.IsAny<string>(), null, null, null, null))
.ReturnsAsync(expectedCustomer);
// Act
var result = await _target.FindByCpfAsync(Cpf);
// Assert
using (new AssertionScope())
{
result.Should().NotBeNull();
result.Should().BeEquivalentTo(expectedCustomer, options => options.ComparingByMembers<Customer>());
}
}

@italopessoa italopessoa merged commit 9e9c246 into main May 1, 2024
@italopessoa
Copy link
Member Author

italopessoa commented May 1, 2024

@coderabbitai could you create a readme file describing this repository and how you can test it after cloning the repository?

Copy link

coderabbitai bot commented May 1, 2024

Tip

For best results, initiate chat on the files or code changes.

@italopessoa Here's a draft for the README file that describes the repository and provides instructions on how to test it after cloning:

# FIAP Tech Challenge - ByteMeBurger API

## Description
This repository contains the source code for the ByteMeBurger API, part of the FIAP Tech Challenge. The API is designed to manage a burger restaurant's operations, including order placement, customer registration, and product management. The recent updates introduce a new endpoint for customer registration and enhance various aspects of the application, such as error handling, data models, and service configurations.

## Getting Started

### Prerequisites
- Docker
- .NET SDK
- Optionally, an IDE such as Visual Studio or VSCode

### Setup
1. Clone the repository:
   ```bash
   git clone https://github.com/soat-fiap/FIAP.TechChallenge.ByteMeBurger.git
   cd FIAP.TechChallenge.ByteMeBurger
  1. Start the services using Docker:

    docker-compose up -d
  2. Apply any necessary database migrations (if applicable):

    dotnet ef database update

Testing

To run the automated tests included in the repository, use the following command:

dotnet test

This command will execute all tests defined in the test projects and provide a summary of the test results.

Contributing

Contributions to the project are welcome! Please refer to the contributing guidelines for more information on how to submit pull requests.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.


Please review this draft and let me know if there are any specific sections or details you'd like to add or modify!

@italopessoa italopessoa deleted the 1-create-endpoint-to-register-customers branch May 2, 2024 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Phase 1 Containers in Software Architecture
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Create endpoint to register customers
1 participant