Commit cf4fb4d5 authored by Ishankha K.C's avatar Ishankha K.C

Merge branch 'feature/chamode_dev' into 'master'

clear notification api

See merge request !7
parents 61df0ae6 0a605754
...@@ -56,7 +56,7 @@ public class WebSocketClient { ...@@ -56,7 +56,7 @@ public class WebSocketClient {
scheduler.schedule(this::connectToWebSocket, 2, TimeUnit.MINUTES); scheduler.schedule(this::connectToWebSocket, 2, TimeUnit.MINUTES);
} }
@Scheduled(fixedDelay = 120000) // Check every 5 minutes @Scheduled(fixedDelay = 60000) // Check every 1 minutes
private void checkConnection() { private void checkConnection() {
if (session == null || !session.isOpen()) { if (session == null || !session.isOpen()) {
System.out.println("WebSocket connection is closed. Reconnecting..."); System.out.println("WebSocket connection is closed. Reconnecting...");
......
...@@ -3,6 +3,7 @@ package com.kaluwa.enterprises.babycarebackendservice.dto; ...@@ -3,6 +3,7 @@ package com.kaluwa.enterprises.babycarebackendservice.dto;
import lombok.*; import lombok.*;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDateTime;
/** /**
* DTO for {@link com.kaluwa.enterprises.babycarebackendservice.model.ActivityLog} * DTO for {@link com.kaluwa.enterprises.babycarebackendservice.model.ActivityLog}
...@@ -14,4 +15,5 @@ public class ActivityLogDto implements Serializable { ...@@ -14,4 +15,5 @@ public class ActivityLogDto implements Serializable {
private Long activityLogId; private Long activityLogId;
private String activityLogType; private String activityLogType;
private String activityLogDescription; private String activityLogDescription;
private LocalDateTime logTime;
} }
\ No newline at end of file
...@@ -5,6 +5,8 @@ import lombok.AllArgsConstructor; ...@@ -5,6 +5,8 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
import static com.kaluwa.enterprises.babycarebackendservice.constants.TableNames.ACTIVITY_LOG_TABLE; import static com.kaluwa.enterprises.babycarebackendservice.constants.TableNames.ACTIVITY_LOG_TABLE;
@Data @Data
...@@ -18,4 +20,5 @@ public class ActivityLog { ...@@ -18,4 +20,5 @@ public class ActivityLog {
private Long activityLogId; private Long activityLogId;
private String activityLogType; private String activityLogType;
private String activityLogDescription; private String activityLogDescription;
private LocalDateTime logTime;
} }
package com.kaluwa.enterprises.babycarebackendservice.rest; package com.kaluwa.enterprises.babycarebackendservice.rest;
import com.kaluwa.enterprises.babycarebackendservice.dto.ActivityLogDto; import com.kaluwa.enterprises.babycarebackendservice.dto.ActivityLogDto;
import com.kaluwa.enterprises.babycarebackendservice.dto.ResponseDto;
import com.kaluwa.enterprises.babycarebackendservice.service.ActivityLogService; import com.kaluwa.enterprises.babycarebackendservice.service.ActivityLogService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -27,4 +29,10 @@ public class ActivityLogController { ...@@ -27,4 +29,10 @@ public class ActivityLogController {
return activityLogService.getAllActivityLogs(); return activityLogService.getAllActivityLogs();
} }
@DeleteMapping
public ResponseEntity<ResponseDto> clearNotifications() {
log.info("Inside activity log controller clearNotifications method");
return activityLogService.clearNotifications();
}
} }
package com.kaluwa.enterprises.babycarebackendservice.service; package com.kaluwa.enterprises.babycarebackendservice.service;
import com.kaluwa.enterprises.babycarebackendservice.dto.ActivityLogDto; import com.kaluwa.enterprises.babycarebackendservice.dto.ActivityLogDto;
import com.kaluwa.enterprises.babycarebackendservice.dto.ResponseDto;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import java.util.List; import java.util.List;
...@@ -10,4 +11,6 @@ public interface ActivityLogService { ...@@ -10,4 +11,6 @@ public interface ActivityLogService {
ActivityLogDto saveActivityLog(ActivityLogDto activityLogDto); ActivityLogDto saveActivityLog(ActivityLogDto activityLogDto);
ResponseEntity<List<ActivityLogDto>> getAllActivityLogs(); ResponseEntity<List<ActivityLogDto>> getAllActivityLogs();
ResponseEntity<ResponseDto> clearNotifications();
} }
...@@ -2,6 +2,7 @@ package com.kaluwa.enterprises.babycarebackendservice.service.impl; ...@@ -2,6 +2,7 @@ package com.kaluwa.enterprises.babycarebackendservice.service.impl;
import com.kaluwa.enterprises.babycarebackendservice.dao.ActivityLogDao; import com.kaluwa.enterprises.babycarebackendservice.dao.ActivityLogDao;
import com.kaluwa.enterprises.babycarebackendservice.dto.ActivityLogDto; import com.kaluwa.enterprises.babycarebackendservice.dto.ActivityLogDto;
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.ActivityLogMapper; import com.kaluwa.enterprises.babycarebackendservice.mappers.ActivityLogMapper;
import com.kaluwa.enterprises.babycarebackendservice.service.ActivityLogService; import com.kaluwa.enterprises.babycarebackendservice.service.ActivityLogService;
...@@ -9,6 +10,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -9,6 +10,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
@Service @Service
...@@ -27,6 +29,7 @@ public class ActivityLogServiceImpl implements ActivityLogService { ...@@ -27,6 +29,7 @@ public class ActivityLogServiceImpl implements ActivityLogService {
public ActivityLogDto saveActivityLog(ActivityLogDto activityLogDto) { public ActivityLogDto saveActivityLog(ActivityLogDto activityLogDto) {
log.info("Inside saveActivityLog method in ActivityLogServiceImpl"); log.info("Inside saveActivityLog method in ActivityLogServiceImpl");
try { try {
activityLogDto.setLogTime(LocalDateTime.now());
return activityLogMapper.toDto(activityLogDao.save(activityLogMapper.toEntity(activityLogDto))); return activityLogMapper.toDto(activityLogDao.save(activityLogMapper.toEntity(activityLogDto)));
} catch (Exception e) { } catch (Exception e) {
log.error("Error occurred while saving activity log: {}", e.getMessage()); log.error("Error occurred while saving activity log: {}", e.getMessage());
...@@ -46,4 +49,17 @@ public class ActivityLogServiceImpl implements ActivityLogService { ...@@ -46,4 +49,17 @@ public class ActivityLogServiceImpl implements ActivityLogService {
throw new BadRequestAlertException(e.getMessage(), "ActivityLog", "errorFetchingActivityLogs"); throw new BadRequestAlertException(e.getMessage(), "ActivityLog", "errorFetchingActivityLogs");
} }
} }
@Override
public ResponseEntity<ResponseDto> clearNotifications() {
log.info("Inside clearNotifications method in ActivityLogServiceImpl");
try {
activityLogDao.deleteAll();
return ResponseEntity.ok(new ResponseDto(Long.parseLong("200"), "Notifications cleared successfully"));
} catch (Exception e) {
log.error("Error occurred while clearing notifications: {}", e.getMessage());
e.printStackTrace();
throw new BadRequestAlertException(e.getMessage(), "ActivityLog", "errorClearingNotifications");
}
}
} }
...@@ -6,7 +6,7 @@ spring: ...@@ -6,7 +6,7 @@ spring:
name: user name: user
password: password password: password
datasource: datasource:
url: jdbc:mysql://192.168.1.8:30306/baby_care_db?useSSL=false&serverTimezone=UTC url: jdbc:mysql://192.168.1.8:30306/baby_care_db?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
username: root username: root
password: password password: password
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
......
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