bug fixed

pull/2/head
Vyacheslav N. Boyko 2018-02-05 12:32:52 +03:00
parent 4195c8bea3
commit dff99f91f1
3 changed files with 24 additions and 4 deletions

View File

@ -15,5 +15,6 @@ import java.util.List;
public interface GrammarCorrectionRepository extends JpaRepository<GrammarCorrection, Long> {
GrammarCorrection findFirstByWordAndCorrection(String word, String correction);
List<GrammarCorrection> findAllByWord(String word);
}

View File

@ -94,6 +94,14 @@ public class GrammarCorrectionService {
return false;
}
public Boolean removeAllCorrectionsByWord(String word) {
List<GrammarCorrection> gcList = grammarCorrectionRepository.findAllByWord(word);
gcList.forEach(gc -> {
grammarCorrectionRepository.delete(gc);
});
return gcList.size() > 0;
}
public List<GrammarCorrection> getAllCorrections() {
List<GrammarCorrection> list = grammarCorrectionRepository.findAll(new Sort(Sort.Direction.DESC, "id"));
return list;

View File

@ -71,13 +71,24 @@ public class GrammarCorrectorListener extends ImprovedListenerAdapter {
grammarCorrectionService.saveGrammarCorrection(params[0].trim(), params[1].trim(), event.getUser().getNick());
event.respond("added correction: "+params[0].trim()+" > "+params[1].trim());
}
} else if (commands[1].trim().equalsIgnoreCase("remove")) {
} else if (commands[0].trim().equalsIgnoreCase("remove")) {
String params[] = commands[1].trim().split(">");
if (grammarCorrectionService.removeCorrection(params[0].trim(), params[1].trim())) {
event.respond("added correction: "+params[0].trim()+" > "+params[1].trim());
if (params.length == 1) {
// by word
if (grammarCorrectionService.removeAllCorrectionsByWord(commands[1].trim())) {
event.respond("all corrections by word "+commands[1].trim()+" were removed");
} else {
event.respond("corrections by word "+commands[1].trim()+" not found");
}
} else {
event.respond("correction not found: "+params[0].trim()+" > "+params[1].trim());
// by correction
if (grammarCorrectionService.removeCorrection(params[0].trim(), params[1].trim())) {
event.respond("removed correction: "+params[0].trim()+" > "+params[1].trim());
} else {
event.respond("correction not found: "+params[0].trim()+" > "+params[1].trim());
}
}
} else {
event.respond(helpMessage());
}