Commit 5e9b943d authored by Ishankha K.C's avatar Ishankha K.C

baby wet checker

parent e6183d6e
...@@ -48,7 +48,8 @@ public class SecurityConfig { ...@@ -48,7 +48,8 @@ public class SecurityConfig {
"/swagger-ui.html", "/swagger-ui.html",
"/emotional/video-process", "/emotional/video-process",
"/test/**", "/test/**",
"/activity-logs/add" "/activity-logs/add",
"/baby/**"
}; };
@Bean @Bean
......
...@@ -10,5 +10,5 @@ import java.util.List; ...@@ -10,5 +10,5 @@ import java.util.List;
public interface ActivityLogDao extends JpaRepository<ActivityLog, Long> { public interface ActivityLogDao extends JpaRepository<ActivityLog, Long> {
List<ActivityLog> findAllByOrderByActivityLogIdDesc(); List<ActivityLog> findAllByOrderByActivityLogIdDesc();
List<ActivityLog> findAllByActivityLogTypeOrderByActivityLogIdDesc(String activityLogType); List<ActivityLog> findTop5ByActivityLogTypeOrderByActivityLogIdDesc(String activityLogType);
} }
\ No newline at end of file
package com.kaluwa.enterprises.babycarebackendservice.dao; package com.kaluwa.enterprises.babycarebackendservice.dao;
import com.kaluwa.enterprises.babycarebackendservice.dto.BabyDto;
import com.kaluwa.enterprises.babycarebackendservice.model.Baby; import com.kaluwa.enterprises.babycarebackendservice.model.Baby;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Optional;
@Repository @Repository
public interface BabyDao extends JpaRepository<Baby, Long> { public interface BabyDao extends JpaRepository<Baby, Long> {
boolean existsByDeviceUidAndBabyIdNot(String deviceUid, Long babyId); boolean existsByDeviceUidAndBabyIdNot(String deviceUid, Long babyId);
boolean existsByDeviceUid(String deviceUid); boolean existsByDeviceUid(String deviceUid);
List<Baby> findByUserUserId(Long userId);
Optional<Baby> findByDeviceUid(String deviceId);
} }
...@@ -57,6 +57,7 @@ public class BabyDto { ...@@ -57,6 +57,7 @@ public class BabyDto {
private String uniqKey; private String uniqKey;
private UserDto user; private UserDto user;
private byte[] imageData; private byte[] imageData;
private boolean wet;
@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")
......
...@@ -51,6 +51,7 @@ public class Baby { ...@@ -51,6 +51,7 @@ public class Baby {
private String secondaryEmergencyContactNumber; private String secondaryEmergencyContactNumber;
private String notes; private String notes;
private String uniqKey; private String uniqKey;
private boolean wet;
@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;
......
...@@ -28,9 +28,11 @@ public class BabyController { ...@@ -28,9 +28,11 @@ public class BabyController {
} }
@GetMapping() @GetMapping()
public ResponseEntity<List<BabyDto>> getAllbabies() { public ResponseEntity<List<BabyDto>> getAllbabies(
@RequestParam(value = "userId", required = false) Long userId
) {
log.info("Inside baby controller getAllbabies method"); log.info("Inside baby controller getAllbabies method");
return ResponseEntity.ok(babyService.getAllBabies()); return ResponseEntity.ok(babyService.getAllBabies(userId));
} }
@GetMapping("/{babyId}") @GetMapping("/{babyId}")
...@@ -50,4 +52,10 @@ public class BabyController { ...@@ -50,4 +52,10 @@ public class BabyController {
log.info("Inside baby controller deleteBaby method"); log.info("Inside baby controller deleteBaby method");
return ResponseEntity.ok(babyService.deleteBaby(babyId)); return ResponseEntity.ok(babyService.deleteBaby(babyId));
} }
@GetMapping("/byDeviceId/{deviceId}")
public ResponseEntity<BabyDto> getBabyByDeviceId(@PathVariable String deviceId) {
log.info("Inside baby controller getBabyByDeviceId method");
return ResponseEntity.ok(babyService.getBabyByDeviceId(deviceId));
}
} }
...@@ -8,11 +8,13 @@ import java.util.List; ...@@ -8,11 +8,13 @@ import java.util.List;
public interface BabyService { public interface BabyService {
BabyDto createBaby(BabyDto babyDto); BabyDto createBaby(BabyDto babyDto);
List<BabyDto> getAllBabies(); List<BabyDto> getAllBabies(Long userId);
BabyDto getBabyById(Long babyId); BabyDto getBabyById(Long babyId);
BabyDto updateBaby(Long babyId, BabyDto babyDto); BabyDto updateBaby(Long babyId, BabyDto babyDto);
ResponseDto deleteBaby(Long babyId); ResponseDto deleteBaby(Long babyId);
BabyDto getBabyByDeviceId(String deviceId);
} }
...@@ -43,7 +43,7 @@ public class ActivityLogServiceImpl implements ActivityLogService { ...@@ -43,7 +43,7 @@ public class ActivityLogServiceImpl implements ActivityLogService {
log.info("Inside getAllActivityLogs method in ActivityLogServiceImpl"); log.info("Inside getAllActivityLogs method in ActivityLogServiceImpl");
try { try {
if (activityLogType != null && !activityLogType.isEmpty()) { if (activityLogType != null && !activityLogType.isEmpty()) {
return ResponseEntity.ok(activityLogMapper.listToDto(activityLogDao.findAllByActivityLogTypeOrderByActivityLogIdDesc(activityLogType))); return ResponseEntity.ok(activityLogMapper.listToDto(activityLogDao.findTop5ByActivityLogTypeOrderByActivityLogIdDesc(activityLogType)));
} else { } else {
return ResponseEntity.ok(activityLogMapper.listToDto(activityLogDao.findAllByOrderByActivityLogIdDesc())); return ResponseEntity.ok(activityLogMapper.listToDto(activityLogDao.findAllByOrderByActivityLogIdDesc()));
} }
......
...@@ -12,13 +12,8 @@ import com.kaluwa.enterprises.babycarebackendservice.model.Document; ...@@ -12,13 +12,8 @@ import com.kaluwa.enterprises.babycarebackendservice.model.Document;
import com.kaluwa.enterprises.babycarebackendservice.service.BabyService; import com.kaluwa.enterprises.babycarebackendservice.service.BabyService;
import com.kaluwa.enterprises.babycarebackendservice.service.DocumentService; import com.kaluwa.enterprises.babycarebackendservice.service.DocumentService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
...@@ -68,6 +63,7 @@ public class BabyServiceImpl implements BabyService { ...@@ -68,6 +63,7 @@ public class BabyServiceImpl implements BabyService {
if (babyDto.getUserId() == null) { if (babyDto.getUserId() == null) {
throw new BadRequestAlertException("User id is required", "baby", "baby.error"); throw new BadRequestAlertException("User id is required", "baby", "baby.error");
} }
babyDto.setWet(false);
return babyMapper.toDto(babyDao.save(babyMapper.toEntity(babyDto))); return babyMapper.toDto(babyDao.save(babyMapper.toEntity(babyDto)));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -76,11 +72,15 @@ public class BabyServiceImpl implements BabyService { ...@@ -76,11 +72,15 @@ public class BabyServiceImpl implements BabyService {
} }
@Override @Override
public List<BabyDto> getAllBabies() { public List<BabyDto> getAllBabies(Long userId) {
log.info("Inside baby service getAllBabies method"); log.info("Inside baby service getAllBabies method");
try { try {
List<BabyDto> babyList = babyMapper.toDtoList(babyDao.findAll()); List<BabyDto> babyList;
if (userId != null) {
babyList = babyMapper.toDtoList(babyDao.findByUserUserId(userId));
} else {
babyList = babyMapper.toDtoList(babyDao.findAll());
babyList.forEach(babyDto -> { babyList.forEach(babyDto -> {
Optional<Document> documentOp = documentDao.findByTableNameAndUniqKeyAndDocumentType(BABY_TABLE, babyDto.getUniqKey(), IMAGE); Optional<Document> documentOp = documentDao.findByTableNameAndUniqKeyAndDocumentType(BABY_TABLE, babyDto.getUniqKey(), IMAGE);
documentOp.ifPresent(document -> { documentOp.ifPresent(document -> {
...@@ -90,7 +90,7 @@ public class BabyServiceImpl implements BabyService { ...@@ -90,7 +90,7 @@ public class BabyServiceImpl implements BabyService {
} }
}); });
}); });
}
return babyList; return babyList;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -176,4 +176,20 @@ public class BabyServiceImpl implements BabyService { ...@@ -176,4 +176,20 @@ public class BabyServiceImpl implements BabyService {
throw new BadRequestAlertException(e.getMessage(), "baby", "baby.error"); throw new BadRequestAlertException(e.getMessage(), "baby", "baby.error");
} }
} }
@Override
public BabyDto getBabyByDeviceId(String deviceId) {
log.info("Inside baby service getBabyByDeviceId method");
try {
Optional<Baby> babyOp = babyDao.findByDeviceUid(deviceId);
if (babyOp.isEmpty()) {
throw new BadRequestAlertException("Baby not found", "baby", "baby.error");
} else {
return babyMapper.toDto(babyOp.get());
}
} catch (Exception e) {
e.printStackTrace();
throw new BadRequestAlertException(e.getMessage(), "baby", "baby.error");
}
}
} }
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