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

baby dto updated

parent 98eae013
......@@ -8,20 +8,54 @@ import lombok.NoArgsConstructor;
import java.time.LocalDate;
import static com.kaluwa.enterprises.babycarebackendservice.constants.Status.STATUS_NEW;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BabyDto {
private Long babyId;
@NotNull(message = "Baby name is required")
@NotEmpty(message = "Baby name is required")
private String babyName;
private String babyGender;
private LocalDate babyDob;
private String babyWeight;
@NotNull(message = "Baby's first name is required")
@NotEmpty(message = "Baby's first name is required")
private String firstName;
private String lastName;
@NotNull(message = "Baby's date of birth is required")
@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;
@NotNull(message = "Logged user id is required")
@NotEmpty(message = "Logged user id is required")
private Long userId;
private Long documentId;
}
......@@ -18,11 +18,39 @@ public class Baby {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private Long babyId;
private String babyName;
private String babyGender;
private LocalDate babyDob;
private String babyWeight;
private String firstName;
private String lastName;
private LocalDate dob;
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)
@JoinColumn(name = "userId", referencedColumnName = "userId", nullable = false)
private User user;
private Long documentId;
}
package com.kaluwa.enterprises.babycarebackendservice.service.impl;
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.ResponseDto;
import com.kaluwa.enterprises.babycarebackendservice.error.BadRequestAlertException;
import com.kaluwa.enterprises.babycarebackendservice.mappers.BabyMapper;
import com.kaluwa.enterprises.babycarebackendservice.model.Baby;
import com.kaluwa.enterprises.babycarebackendservice.model.Document;
import com.kaluwa.enterprises.babycarebackendservice.service.BabyService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
......@@ -15,15 +18,17 @@ import java.util.List;
import java.util.Optional;
@Service
@Slf4j
public class BabyServiceImpl implements BabyService {
private static final Logger log = LoggerFactory.getLogger(BabyServiceImpl.class);
private final BabyDao babyDao;
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.babyMapper = babyMapper;
this.documentDao = documentDao;
}
@Override
......@@ -92,6 +97,10 @@ public class BabyServiceImpl implements BabyService {
if (babyOp.isEmpty()) {
throw new BadRequestAlertException("Baby not found", "baby", "baby.error");
} else {
Optional<Document> documentOp = documentDao.findById(babyOp.get().getDocumentId());
if (documentOp.isPresent()) {
documentDao.deleteById(babyOp.get().getDocumentId());
}
babyDao.deleteById(babyId);
ResponseDto responseDto = new ResponseDto();
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