-
Notifications
You must be signed in to change notification settings - Fork 41
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
base: main
Are you sure you want to change the base?
Conversation
private final PaymentService paymentService; | ||
private final UserValidator userValidator; | ||
|
||
public PaymentController(PaymentService paymentService, UserValidator userValidator) { |
There was a problem hiding this comment.
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())}) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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())
?
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: