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

Enabling User to have multiple questions #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pavan541cs
Copy link
Contributor

@pavan541cs pavan541cs commented Aug 30, 2020

This PR is to address #69 .

@pavan541cs
Copy link
Contributor Author

@daltonfury42 Can you review this PR


@JsonInclude(JsonInclude.Include.NON_NULL)
public static class Question {
@JsonProperty("questionId")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm wondering if we're using our own custom representation of the questions object. Then we'll need to write our own parsing library to generate the forms on UI.
Maybe we should try an existing library like
https://github.com/rjsf-team/react-jsonschema-form ?

} catch (JsonProcessingException e) {
e.printStackTrace();
}
return queueRepository.save(queue1);
Copy link
Contributor

Choose a reason for hiding this comment

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

This line should be moved in try block, and return null instead.

.orElseThrow(SQInvalidRequestException::queueNotFoundException);
}

@Transactional
public CustomQuestions createCustomQuestions(String queueId, String customQuestions) throws JsonProcessingException {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove the throws part

try {
queue1.setCustomQuestions(mapper.writeValueAsString(customQuestionsObject));
} catch (JsonProcessingException e) {
e.printStackTrace();
Copy link
Contributor

@chalx chalx Feb 2, 2021

Choose a reason for hiding this comment

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

I think this is better to be logged using a logger, for future debugging.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also I think you should throw an 500 internal error here

queue.getQueueCreationTimestamp()))
{
try {
CustomQuestions customQuestions = queue.getCustomQuestions() != null
Copy link
Contributor

Choose a reason for hiding this comment

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

You have duplicate code starting with line +122

Copy link
Contributor

@chalx chalx Feb 4, 2021

Choose a reason for hiding this comment

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

Also you can do flatMap and create a method with the following body.
Option.ofNullable(queue.getCustomQuestions()).map(this::deserializeQuestions).map(this::createQueueStatusResponse)
And the code will be ....flatMap(this::createResponse).orElseThrow... and you can use same code on the other method

Copy link
Contributor

Choose a reason for hiding this comment

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

Also why do we store json? We can handle this using table relationship and we can avoid this complicated logic. Plus it adds a lot of computational overhead.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed. If you want to redo this as a table, with just textual questions and answers, we can do that. But we should think first about how we would display the user input along with each token in the admin page. Maybe some collapsable expansion panel would do the job.

That's the reason why I have been delaying this feature for a long time, till all the easy features are done and I get some real customers.

@@ -40,6 +33,9 @@
@Temporal(TemporalType.TIMESTAMP)
Date queueCreationTimestamp;

@Column(length = 100000)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can use Text type here maybe. It is just a proposal

@PostMapping(path = "/queue/{queueId}/custom-questions")
public ResponseEntity<CustomQuestions> createCustomQuestions(
@PathVariable("queueId") String queueId,
@RequestBody String customQuestions) throws JsonProcessingException {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove throws parts

try {
queue1.setCustomQuestions(mapper.writeValueAsString(customQuestionsObject));
} catch (JsonProcessingException e) {
e.printStackTrace();
Copy link
Contributor

Choose a reason for hiding this comment

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

Also I think you should throw an 500 internal error here

@daltonfury42
Copy link
Collaborator

@chalx Thanks for the review. All makes sense. I want to merge this change a little after, will address them then.

@chalx
Copy link
Contributor

chalx commented Feb 4, 2021

@daltonfury42 Also we need to write tests.

image

@daltonfury42
Copy link
Collaborator

@chalx Yes, I know there is no excuses that would justify not having unit tests, but I have been living with some end to end integration tests till now.

https://github.com/SimplQ/simplQ-backend/blob/master/simplq/src/test/java/me/simplq/IntegrationTests.java

@chalx
Copy link
Contributor

chalx commented Feb 6, 2021

@daltonfury42 I saw that tests. They are ok, but we need to take real unit tests into consideration. This can be a quality gate for each merge request

@daltonfury42
Copy link
Collaborator

daltonfury42 commented Feb 6, 2021

Understood. I'll make it a point to write/insist on unit tests from now on.

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.

4 participants