From 2df01e26334504302577a5ed4ea4f9dab8890274 Mon Sep 17 00:00:00 2001 From: alitpc25 Date: Sat, 23 Dec 2023 02:12:50 +0300 Subject: [PATCH] #592 NullPointerException handled in Need and Resource entities. In addition, EGender's two fields changed back to the old version. --- .../java/com/groupa1/resq/converter/NeedConverter.java | 7 ++++--- .../java/com/groupa1/resq/converter/ResourceConverter.java | 6 ++++-- .../main/java/com/groupa1/resq/entity/enums/EGender.java | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/converter/NeedConverter.java b/resq/backend/resq/src/main/java/com/groupa1/resq/converter/NeedConverter.java index 8f9b4ddd..323007ca 100644 --- a/resq/backend/resq/src/main/java/com/groupa1/resq/converter/NeedConverter.java +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/converter/NeedConverter.java @@ -31,7 +31,8 @@ public NeedDto convertToDto(Need need) { needDto.setLatitude(need.getLatitude()); needDto.setLongitude(need.getLongitude()); needDto.setCreatedDate(need.getCreatedAt()); - needDto.setSize(need.getSize()); + if (need.getSize() != null) + needDto.setSize(need.getSize()); Request request = need.getRequest(); if (request != null) { needDto.setRequestId(request.getId()); @@ -52,11 +53,11 @@ public Need convertToEntity(NeedDto needDto) { need.setLongitude(needDto.getLongitude()); need.setStatus(needDto.getStatus()); need.setCreatedAt(needDto.getCreatedDate()); - need.setSize(needDto.getSize()); + if (needDto.getSize() != null) + need.setSize(needDto.getSize()); Request request = requestRepository.findById(needDto.getRequestId()).orElse(null); need.setRequest(request); return need; } - } diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/converter/ResourceConverter.java b/resq/backend/resq/src/main/java/com/groupa1/resq/converter/ResourceConverter.java index 966cb069..0a92c38e 100644 --- a/resq/backend/resq/src/main/java/com/groupa1/resq/converter/ResourceConverter.java +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/converter/ResourceConverter.java @@ -27,7 +27,8 @@ public ResourceDto convertToDto(Resource resource){ resourceDto.setLatitude(resource.getLatitude()); resourceDto.setLongitude(resource.getLongitude()); resourceDto.setCreatedDate(resource.getCreatedAt()); - resourceDto.setSize(resource.getSize().toString()); + if (resource.getSize() != null) + resourceDto.setSize(resource.getSize().toString()); return resourceDto; } @@ -49,7 +50,8 @@ public Resource convertToEntity(ResourceDto resourceDto){ resource.setLatitude(resourceDto.getLatitude()); resource.setLongitude(resourceDto.getLongitude()); resource.setCreatedAt(resourceDto.getCreatedDate()); - resource.setSize(ESize.valueOf(resourceDto.getSize())); + if (resourceDto.getSize() != null) + resource.setSize(ESize.valueOf(resourceDto.getSize())); return resource; } } diff --git a/resq/backend/resq/src/main/java/com/groupa1/resq/entity/enums/EGender.java b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/enums/EGender.java index 8e41e575..5386ae75 100644 --- a/resq/backend/resq/src/main/java/com/groupa1/resq/entity/enums/EGender.java +++ b/resq/backend/resq/src/main/java/com/groupa1/resq/entity/enums/EGender.java @@ -1,8 +1,8 @@ package com.groupa1.resq.entity.enums; public enum EGender { - MAN, - WOMAN, + MALE, + FEMALE, CHILDREN_BOY, CHILDREN_GIRL, BABY }