Commit 4d8d4bc8 authored by Chamod Ishankha's avatar Chamod Ishankha

baby dto updated

parent 98eae013
...@@ -8,20 +8,54 @@ import lombok.NoArgsConstructor; ...@@ -8,20 +8,54 @@ import lombok.NoArgsConstructor;
import java.time.LocalDate; import java.time.LocalDate;
import static com.kaluwa.enterprises.babycarebackendservice.constants.Status.STATUS_NEW;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class BabyDto { public class BabyDto {
private Long babyId; private Long babyId;
@NotNull(message = "Baby name is required") @NotNull(message = "Baby's first name is required")
@NotEmpty(message = "Baby name is required") @NotEmpty(message = "Baby's first name is required")
private String babyName; private String firstName;
private String babyGender; private String lastName;
private LocalDate babyDob; @NotNull(message = "Baby's date of birth is required")
private String babyWeight; @NotEmpty(message = "Baby's date of birth is required")
private LocalDate dob;
@NotNull(message = "Baby's gender is required")
@NotEmpty(message = "Baby's gender is required")
private String sex;
private String status = STATUS_NEW;
private boolean isActive;
private float weight;
private float height;
private String bloodType;
private String eyeColor;
private String hairColor;
private String allergies;
private String medicalConditions;
private String medications;
private String vaccinateRecords;
private String docName;
private String docContactNumber;
private String healthInsuranceInfo;
private LocalDate firstSmileDate;
private LocalDate firstToothDate;
private LocalDate firstWordDate;
private LocalDate firstStepDate;
private String favFoods;
private String foodsDislikes;
private String primaryEmergencyContactName;
private String primaryEmergencyRelationship;
private String primaryEmergencyContactNumber;
private String secondaryEmergencyContactName;
private String secondaryEmergencyRelationship;
private String secondaryEmergencyContactNumber;
private String notes;
private UserDto user; private UserDto user;
@NotNull(message = "Logged user id is required") @NotNull(message = "Logged user id is required")
@NotEmpty(message = "Logged user id is required") @NotEmpty(message = "Logged user id is required")
private Long userId; private Long userId;
private Long documentId;
} }
...@@ -18,11 +18,39 @@ public class Baby { ...@@ -18,11 +18,39 @@ public class Baby {
@Id @Id
@GeneratedValue(strategy= GenerationType.AUTO) @GeneratedValue(strategy= GenerationType.AUTO)
private Long babyId; private Long babyId;
private String babyName; private String firstName;
private String babyGender; private String lastName;
private LocalDate babyDob; private LocalDate dob;
private String babyWeight; private String sex;
private String status;
private boolean isActive;
private float weight;
private float height;
private String bloodType;
private String eyeColor;
private String hairColor;
private String allergies;
private String medicalConditions;
private String medications;
private String vaccinateRecords;
private String docName;
private String docContactNumber;
private String healthInsuranceInfo;
private LocalDate firstSmileDate;
private LocalDate firstToothDate;
private LocalDate firstWordDate;
private LocalDate firstStepDate;
private String favFoods;
private String foodsDislikes;
private String primaryEmergencyContactName;
private String primaryEmergencyRelationship;
private String primaryEmergencyContactNumber;
private String secondaryEmergencyContactName;
private String secondaryEmergencyRelationship;
private String secondaryEmergencyContactNumber;
private String notes;
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "userId", referencedColumnName = "userId", nullable = false) @JoinColumn(name = "userId", referencedColumnName = "userId", nullable = false)
private User user; private User user;
private Long documentId;
} }
package com.kaluwa.enterprises.babycarebackendservice.service.impl; package com.kaluwa.enterprises.babycarebackendservice.service.impl;
import com.kaluwa.enterprises.babycarebackendservice.dao.BabyDao; import com.kaluwa.enterprises.babycarebackendservice.dao.BabyDao;
import com.kaluwa.enterprises.babycarebackendservice.dao.DocumentDao;
import com.kaluwa.enterprises.babycarebackendservice.dto.BabyDto; import com.kaluwa.enterprises.babycarebackendservice.dto.BabyDto;
import com.kaluwa.enterprises.babycarebackendservice.dto.ResponseDto; import com.kaluwa.enterprises.babycarebackendservice.dto.ResponseDto;
import com.kaluwa.enterprises.babycarebackendservice.error.BadRequestAlertException; import com.kaluwa.enterprises.babycarebackendservice.error.BadRequestAlertException;
import com.kaluwa.enterprises.babycarebackendservice.mappers.BabyMapper; import com.kaluwa.enterprises.babycarebackendservice.mappers.BabyMapper;
import com.kaluwa.enterprises.babycarebackendservice.model.Baby; import com.kaluwa.enterprises.babycarebackendservice.model.Baby;
import com.kaluwa.enterprises.babycarebackendservice.model.Document;
import com.kaluwa.enterprises.babycarebackendservice.service.BabyService; import com.kaluwa.enterprises.babycarebackendservice.service.BabyService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -15,15 +18,17 @@ import java.util.List; ...@@ -15,15 +18,17 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
@Service @Service
@Slf4j
public class BabyServiceImpl implements BabyService { public class BabyServiceImpl implements BabyService {
private static final Logger log = LoggerFactory.getLogger(BabyServiceImpl.class);
private final BabyDao babyDao; private final BabyDao babyDao;
private final BabyMapper babyMapper; private final BabyMapper babyMapper;
private final DocumentDao documentDao;
public BabyServiceImpl(BabyDao babyDao, BabyMapper babyMapper) { public BabyServiceImpl(BabyDao babyDao, BabyMapper babyMapper, DocumentDao documentDao) {
this.babyDao = babyDao; this.babyDao = babyDao;
this.babyMapper = babyMapper; this.babyMapper = babyMapper;
this.documentDao = documentDao;
} }
@Override @Override
...@@ -92,6 +97,10 @@ public class BabyServiceImpl implements BabyService { ...@@ -92,6 +97,10 @@ public class BabyServiceImpl implements BabyService {
if (babyOp.isEmpty()) { if (babyOp.isEmpty()) {
throw new BadRequestAlertException("Baby not found", "baby", "baby.error"); throw new BadRequestAlertException("Baby not found", "baby", "baby.error");
} else { } else {
Optional<Document> documentOp = documentDao.findById(babyOp.get().getDocumentId());
if (documentOp.isPresent()) {
documentDao.deleteById(babyOp.get().getDocumentId());
}
babyDao.deleteById(babyId); babyDao.deleteById(babyId);
ResponseDto responseDto = new ResponseDto(); ResponseDto responseDto = new ResponseDto();
responseDto.setId(babyId); responseDto.setId(babyId);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment