Skip to content

Commit

Permalink
Merge pull request #78 from dianarrmiranda/77-imagens-notificacoes-pr…
Browse files Browse the repository at this point in the history
…oducao

77 imagens notificacoes producao
  • Loading branch information
jnluis authored Dec 11, 2023
2 parents 9b55243 + 6fb559a commit 84ca12c
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,15 @@ public ResponseEntity<byte[]> getImageById(@PathVariable Integer id) throws IOEx
return ResponseEntity.ok().contentType(MediaType.IMAGE_JPEG).body(image);
}

@GetMapping(path = "/notificationImage/{id}")
public ResponseEntity<byte[]> getNotificationImageById(@PathVariable Integer id) throws IOException{
Notification notification = notificationService.getNotificationById(id);
Path path = Paths.get(notification.getAvatar());
byte[] image = Files.readAllBytes(path);

return ResponseEntity.ok().contentType(MediaType.IMAGE_PNG).body(image);
}

@DeleteMapping(path = "/{id}")
public ResponseEntity<String> deleteVineById(@PathVariable Integer id){
try {
Expand Down Expand Up @@ -528,7 +537,7 @@ public ResponseEntity<String> harvestVine(@PathVariable Integer vineId) {
Notification notification = new Notification();
notification.setDescription("Ready to Harvest.");
notification.setType("harvest"); // Set the type
notification.setAvatar("/public/assets/images/notifications/harvest.png"); // Set the avatar
notification.setAvatar("src/main/resources/static/images/harvest.png"); // Set the avatar
notification.setIsUnRead(true); // Set the isUnRead
notification.setDate(LocalDateTime.now()); // Set the date
notification.setVineId(vineId); // Set the vineId directly
Expand All @@ -540,7 +549,6 @@ public ResponseEntity<String> harvestVine(@PathVariable Integer vineId) {
JSONObject notificationJson = new JSONObject();
notificationJson.put("id", notification.getId());
notificationJson.put("type", notification.getType());
notificationJson.put("avatar", notification.getAvatar());
notificationJson.put("isUnRead", notification.getIsUnRead());
notificationJson.put("vineId", notification.getVineId());
notificationJson.put("description", notification.getDescription());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void receiveMessage(String message) {
notification.setDescription("Water consumption is above the limit. Please check the vine " + vine.getName() + ".");
notification.setVine(vine); // Set the vine
notification.setType("waterConsumption"); // Set the type
notification.setAvatar("/public/assets/images/notifications/waterConsumption.png"); // Set the avatar
notification.setAvatar("src/main/resources/static/images/waterConsumption.png"); // Set the avatar
notification.setIsUnRead(isUnRead); // Set the isUnRead
notification.setDate(LocalDateTime.now()); // Set the date
notification.setVineId(vine.getId()); // Set the vineId directly
Expand All @@ -173,7 +173,6 @@ public void receiveMessage(String message) {
JSONObject notificationJson = new JSONObject();
notificationJson.put("id", notification.getId());
notificationJson.put("type", notification.getType());
notificationJson.put("avatar", notification.getAvatar());
notificationJson.put("isUnRead", notification.getIsUnRead());
notificationJson.put("vineId", notification.getVineId());
notificationJson.put("description", notification.getDescription());
Expand All @@ -196,7 +195,7 @@ public void receiveMessage(String message) {
notification.setDescription("Levels of the soil humidity are low.");
notification.setVine(vine); // Set the vine
notification.setType("moisture"); // Set the type
notification.setAvatar("/public/assets/images/notifications/water.png"); // Set the avatar
notification.setAvatar("src/main/resources/static/images/water.png"); // Set the avatar
notification.setIsUnRead(isUnRead); // Set the isUnRead
notification.setDate(LocalDateTime.now()); // Set the date
notification.setVineId(vine.getId()); // Set the vineId directly
Expand All @@ -220,7 +219,6 @@ public void receiveMessage(String message) {
JSONObject notificationJson = new JSONObject();
notificationJson.put("id", notification.getId());
notificationJson.put("type", notification.getType());
notificationJson.put("avatar", notification.getAvatar());
notificationJson.put("isUnRead", notification.getIsUnRead());
notificationJson.put("vineId", notification.getVineId());
notificationJson.put("description", notification.getDescription());
Expand Down Expand Up @@ -296,11 +294,11 @@ public void receiveMessage(String message) {

Boolean isUnRead = true;
Notification notification = new Notification();
// "weatherAlerts", "/assets/images/notifications/rain.png", isUnRead, vine3
// "weatherAlerts", "src/main/resources/static/images/rain.png", isUnRead, vine3
notification.setDescription(map.get(key).get(3).replaceAll("'", ""));
notification.setVine(vine3); // Set the vine
notification.setType("weatherAlerts"); // Set the type
notification.setAvatar("/public/assets/images/notifications/rain.png"); // Set the avatar
notification.setAvatar("src/main/resources/static/images/rain.png"); // Set the avatar
notification.setIsUnRead(isUnRead); // Set the isUnRead
notification.setDate(LocalDateTime.now()); // Set the date
notification.setVineId(vine3.getId()); // Set the vineId directly
Expand All @@ -322,7 +320,6 @@ public void receiveMessage(String message) {
JSONObject notificationJson = new JSONObject();
notificationJson.put("id", notification.getId());
notificationJson.put("type", notification.getType());
notificationJson.put("avatar", notification.getAvatar());
notificationJson.put("isUnRead", notification.getIsUnRead());
notificationJson.put("vineId", notification.getVineId());
notificationJson.put("description", notification.getDescription());
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Scrollbar from 'src/components/scrollbar';
// websocket
import SockJS from "sockjs-client";
import Stomp from "stompjs";
import axios from "axios";

// ----------------------------------------------------------------------

Expand All @@ -41,6 +42,7 @@ export default function NotificationsPopover() {

const user = JSON.parse(localStorage.getItem('user'));
console.log(user.id);
const [image, setImage] = useState(null);

useEffect(() => {
const init = async () => {
Expand All @@ -50,6 +52,19 @@ export default function NotificationsPopover() {
console.log("Notification: ", notifications);
const notificationsData = [];
for (const notification of notifications) {
// get notification's avatar

const image = await axios.get(`${import.meta.env.VITE_APP_SERVER_URL}:8080/vines/notificationImage/${notification.id}`, {
responseType: 'arraybuffer',
})
.then((response) => {
let image = btoa(
new Uint8Array(response.data)
.reduce((data, byte) => data + String.fromCharCode(byte), '')
);
return `data:;base64,${image}`;
});

// console.log("Notification Teste: ",notification);
notificationsData.push({
id: notification.id,
Expand All @@ -58,7 +73,7 @@ export default function NotificationsPopover() {
type: '',
isUnRead: notification.isUnRead,
createdAt: notification.date,
avatar: notification.avatar,
avatar: image,
});
}

Expand Down Expand Up @@ -88,6 +103,17 @@ export default function NotificationsPopover() {

// Check if the id is defined before processing the notification
// if (newNotification.id !== undefined) {
const image = await axios.get(`${import.meta.env.VITE_APP_SERVER_URL}:8080/vines/notificationImage/${newNotification.id}`, {
responseType: 'arraybuffer',
})
.then((response) => {
let image = btoa(
new Uint8Array(response.data)
.reduce((data, byte) => data + String.fromCharCode(byte), '')
);
return `data:;base64,${image}`;
});

const newFormattedNotification = {
id: newNotification.id,
vineId: newNotification.vineId,
Expand All @@ -96,7 +122,7 @@ export default function NotificationsPopover() {
type: '',
isUnRead: newNotification.isUnRead,
createdAt: newNotification.date,
avatar: newNotification.avatar,
avatar: image,
};

setLatestNotification(newFormattedNotification);
Expand Down

0 comments on commit 84ca12c

Please sign in to comment.