Code Duplication    Length = 21-21 lines in 2 locations

src/main/java/com/osomapps/pt/user/UserService.java 1 location

@@ 229-249 (lines=21) @@
226
            }
227
            setUserName(inUser, userRequest.getName());
228
        }
229
        if (userRequest.getGoals() != null) {
230
            if (userRequest.getGoals().size() > 2) {
231
                throw new UnauthorizedException("Amount of goals must be not more than 2");
232
            }
233
            inUserGoalRepository.deleteAll(inUser.getInUserGoals());
234
            inUser.setInUserGoals(new ArrayList<>());
235
            userRequest
236
                    .getGoals()
237
                    .forEach(
238
                            (userGoalRequestDTO) -> {
239
                                Goal goal =
240
                                        goalRepository
241
                                                .findById(userGoalRequestDTO.getId())
242
                                                .orElse(null);
243
                                if (goal == null) {
244
                                    throw new UnauthorizedException(
245
                                            "Goal with id "
246
                                                    + userGoalRequestDTO.getId()
247
                                                    + " not found");
248
                                }
249
                                String value = null;
250
                                try {
251
                                    value =
252
                                            new ObjectMapper()

src/main/java/com/osomapps/pt/admin/user/AdminUserService.java 1 location

@@ 211-231 (lines=21) @@
208
    }
209
210
    private void setupGoals(UserRequestDTO userRequestDTO, final InUser inUser) {
211
        if (userRequestDTO.getGoals() != null) {
212
            if (userRequestDTO.getGoals().size() > 2) {
213
                throw new UnauthorizedException("Amount of goals must be not more than 2");
214
            }
215
            inUserGoalRepository.deleteAll(inUser.getInUserGoals());
216
            inUser.setInUserGoals(new ArrayList<>());
217
            userRequestDTO
218
                    .getGoals()
219
                    .forEach(
220
                            (userGoalRequestDTO) -> {
221
                                Goal goal =
222
                                        goalRepository
223
                                                .findById(userGoalRequestDTO.getId())
224
                                                .orElse(null);
225
                                if (goal == null) {
226
                                    throw new UnauthorizedException(
227
                                            "Goal with id "
228
                                                    + userGoalRequestDTO.getId()
229
                                                    + " not found");
230
                                }
231
                                String value = null;
232
                                try {
233
                                    value =
234
                                            new ObjectMapper()