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

avi8pE7N : Ticket from trello by [email protected] #50

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

aquintero2023
Copy link

You can check a demo of this on:

http://34.239.237.47:9999/swagger-ui/index.html

There are only 5 users with payment data, 2 cards for each user:

008a4215-0b1d-445e-b655-a964039cbb5a
00963d9b-f884-485e-9455-fcf30c6ac379
00bed3ac-5f3c-4a2d-a67b-80376ea9f941
0111d3ca-514b-4ae8-8f57-e85cca43fb1e
01316816-0cb7-41c4-8424-8367294aea27

private final PaymentService paymentService;
private final UserValidator userValidator;

public PaymentController(PaymentService paymentService, UserValidator userValidator) {
Copy link
Member

Choose a reason for hiding this comment

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

Have you heard of @RequiredArgsConstructor from Lombok?

@ApiResponse(responseCode = "200", content = {
@Content(schema = @Schema(implementation = List.class), mediaType = "application/json")
})
@ApiResponse(responseCode = "400", content = {@Content(schema = @Schema())})
Copy link
Member

Choose a reason for hiding this comment

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

The empty @Schema() is weird. Additionally the @ArraySchema seems better in this situation because you can list the PaymentDto type as well.
https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Annotations#arrayschema

{
log.info("Userid:{}", userId);
userValidator.validateId(userId);
return paymentService.retrieveByUserId(userId);
Copy link
Member

Choose a reason for hiding this comment

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

httpResponse is unused, and this log is vague and unnecessary.


public List<PaymentDto> retrieveByUserId(final String userId) {
final List<Payment> paymentList = paymentRepository.findByUserId(userId);
log.info("found {} payment(s)", paymentList.size());
Copy link
Member

Choose a reason for hiding this comment

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

Maybe the userId belongs in this log statement as well?


@BeforeEach
public void beforeEach() {
log.info("Initializing payment list");
Copy link
Member

@wheeleruniverse wheeleruniverse Aug 25, 2023

Choose a reason for hiding this comment

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

I think logs in tests are usually unnecessary as there are methods built into the testing tools to provide more clear output. Additionally the public modifier is unnecessary.

}

@Test
void getRetrieveByUserId() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

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

Weird formatting. What IDE are you using?

}

private PaymentDto createPaymentDto(String userId) {
final PaymentDto payment = new PaymentDto();
Copy link
Member

Choose a reason for hiding this comment

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

@Builder from Lombok might make this code nicer.

final List<Integer> userIds = IntStream.range(1, 10).boxed().toList();

final List<Payment> daoPayments = userIds.stream()
.map(id -> createPayment(Integer.toString(id))).collect(Collectors.toList());
Copy link
Member

Choose a reason for hiding this comment

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

If you update the createPayment method to accept a String then you can use method reference instead of this Lambda.

.map(this::createPayment)

when(paymentRepository.findByUserId(anyString())).thenReturn(daoPayments);

this.dtoPayments = userIds.stream().map(id -> createPaymentDto(Integer.toString(id)))
.collect(Collectors.toList());
Copy link
Member

Choose a reason for hiding this comment

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

Does .toList() work instead of .collect(Collectors.toList())?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants