66import com .objectcomputing .pulsesurvey .repositories .ResponseKeyRepository ;
77import com .objectcomputing .pulsesurvey .repositories .ResponseRepository ;
88import com .objectcomputing .pulsesurvey .repositories .UserCommentsRepository ;
9- import io .micronaut .context .annotation .Value ;
109import io .micronaut .core .util .CollectionUtils ;
1110import io .micronaut .http .HttpResponse ;
1211import io .micronaut .http .MediaType ;
2221import javax .inject .Inject ;
2322import java .net .URI ;
2423import java .net .URISyntaxException ;
24+ import java .util .List ;
2525import java .util .Optional ;
2626import java .util .UUID ;
2727import java .util .concurrent .atomic .AtomicBoolean ;
@@ -85,7 +85,7 @@ HttpResponse<String> happiness(String currentEmotion, String surveyKey) {
8585
8686 try {
8787 LOG .info ("redirecting to /happiness/comment" );
88- return HttpResponse .redirect (new URI ("/happiness/comment?surveyKey=" +surveyKey ));
88+ return HttpResponse .temporaryRedirect (new URI ("/happiness/comment?surveyKey=" +surveyKey ));
8989 } catch (URISyntaxException e ) {
9090 e .printStackTrace ();
9191 LOG .error ("unable to redirect to /happiness/comment " + e .getMessage ());
@@ -95,8 +95,7 @@ HttpResponse<String> happiness(String currentEmotion, String surveyKey) {
9595 LOG .warn ("This key is not valid: " + surveyKey );
9696 }
9797
98- return HttpResponse .ok ("Hello, your current emotion of " + currentEmotion + "!" +
99- " is duly noted." );
98+ return HttpResponse .ok ("This key has already been used." );
10099 }
101100
102101 @ Get ("comment" )
@@ -110,13 +109,12 @@ public HttpResponse displayComments(String surveyKey) {
110109 @ Post ("userComments" )
111110 @ Consumes (MediaType .APPLICATION_FORM_URLENCODED )
112111 @ View ("thankyou" )
113- public HttpResponse sendThankYouWithCommentBlock
114- (@ Value ("userComments" ) String userComments ,
115- @ Value ("surveyKey" ) String surveyKey ) {
112+ public HttpResponse sendThankYouWithCommentBlock (String userComments , String surveyKey ) {
116113
117114 LOG .info ("The user has commented: " + userComments );
118115 LOG .info ("With surveyKey: " + surveyKey );
119116 // put comment into the db using the survey key
117+
120118 boolean commentSaved = saveUserComment (surveyKey , userComments );
121119 LOG .info ("commentSaved: " + commentSaved );
122120
@@ -165,6 +163,17 @@ boolean saveResponse(String currentEmotion, String surveyKey) {
165163 return responseAdded ;
166164 }
167165
166+ private boolean checkForComment (String surveyKey ) {
167+
168+ LOG .info ("Validating comment " + surveyKey );
169+ List <UserComments > userComments = userCommentsRepo .findComments (surveyKey );
170+
171+ boolean isPresent = false ;
172+ isPresent = !userComments .isEmpty ();
173+ return isPresent ;
174+
175+ }
176+
168177 boolean saveUserComment (String surveyKey , String comments ) {
169178
170179 boolean commentsAdded = false ;
0 commit comments