@@ -175,7 +175,7 @@ public LocationDTO save(LocationDTO dto) {
175175 dto .setHref (basePath + "/" + uuid );
176176 dto .setLanguages (Collections .singletonList (dto .getLanguage ()));
177177
178- validateDTO (uuid , dto .getLanguage ());
178+ validateRequest (uuid , dto .getLanguage ());
179179
180180 LocationModel dtoToModel = modelMapper .map (dto , LocationModel .class );
181181 dtoToModel .getTranslation ().setLocationUuid (uuid );
@@ -192,7 +192,11 @@ public LocationDTO save(LocationDTO dto) {
192192 * @since 1.0.0
193193 */
194194 public LocationTranslationDTO saveTranslation (UUID uuid , LocationTranslationDTO dto ) {
195- validateDTO (uuid , dto .getLanguage ());
195+ if (!repository .existsById (uuid )) {
196+ throw new ItemNotFoundException ("Item '" + uuid + "' doesn't exist!" );
197+ }
198+
199+ validateRequest (uuid , dto .getLanguage ());
196200
197201 LocationTranslation dtoToModel = modelMapper .map (dto , LocationTranslation .class );
198202 dtoToModel .setLocationUuid (uuid );
@@ -261,7 +265,7 @@ public void deleteTranslation(UUID uuid, String language) {
261265 }
262266
263267 /**
264- * Method to validate an DTO
268+ * Method to validate an request
265269 * <ul>
266270 * <li>Validate if language is valid</li>
267271 * <li>Validate if field with same uuid and language already exists</li>
@@ -273,15 +277,11 @@ public void deleteTranslation(UUID uuid, String language) {
273277 * @throws SaveConflictException If item already exists
274278 * @since 1.0.0
275279 */
276- private void validateDTO (UUID uuid , String language ) {
280+ private void validateRequest (UUID uuid , String language ) {
277281 if (StringUtils .isNullOrEmpty (language )) {
278282 throw new BadRequestException ("Column 'language' is required" );
279283 }
280284
281- if (!repository .existsById (uuid )) {
282- throw new ItemNotFoundException ("Item '" + uuid + "' doesn't exist!" );
283- }
284-
285285 if (translationRepository .existsByLocationUuidAndLanguage (uuid , language )) {
286286 throw new SaveConflictException ("Language '" + language + "' already exist!" );
287287 }
0 commit comments