Skip to content

Commit

Permalink
Add the validation mechanism for Survey submission
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarjanazy committed May 25, 2020
1 parent 18008e5 commit d854e02
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.validation.constraints.NotNull;

@Getter @Setter @NoArgsConstructor @AllArgsConstructor
public class QuestionSubmissionDTO {
@NotNull(message = "Question ID can't be null")
Integer questionId;
@NotNull(message = "Choice ID can't be null")
Integer choiceId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.validation.annotation.Validated;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

@Getter @Setter @NoArgsConstructor @AllArgsConstructor
public class SurveySubmissionDTO {
@NotNull(message = "Survey ID can't be null")
Integer surveyId;

@NotEmpty(message = "QuestionSubmissions can't be empty")
@Valid
List<QuestionSubmissionDTO> questionSubmissions;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.codeit.survey.services.SurveySubmissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -18,7 +19,7 @@ public SurveySubmissionController(SurveySubmissionService surveySubmissionServic
}

@PostMapping("/submitSurvey")
public ResponseEntity<?> submitSurvey(@RequestBody SurveySubmissionDTO surveySubmissionDTO){
public ResponseEntity<?> submitSurvey(@RequestBody @Validated SurveySubmissionDTO surveySubmissionDTO){
return surveySubmissionService.checkSurveyAndSubmit(surveySubmissionDTO);
}

Expand Down

0 comments on commit d854e02

Please sign in to comment.