Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b32cf2b
feat(80): alters log_notificacao table
BryanARMatheus Nov 23, 2025
3521efb
feat(80): maps NotificationLog entity ti log_notificacao table
BryanARMatheus Nov 23, 2025
0546613
feat(80): adds put mapping to notification
BryanARMatheus Nov 23, 2025
0f3b0fd
feat(80): adds and alters columns in log_notificacao table
BryanARMatheus Nov 23, 2025
dc6ac93
fix(80): removes deprecated methods
BryanARMatheus Nov 24, 2025
777c5fe
fix(80): fixes methods names, adds imports and constructor
BryanARMatheus Nov 24, 2025
70a5cfd
fix(80): adds constructor with right parameters
BryanARMatheus Nov 24, 2025
aa2ae53
fix(80): fixes entity missing columns
BryanARMatheus Nov 28, 2025
d9cb140
fix(80): removes crossorigin from notificationlogcontroller
BryanARMatheus Nov 28, 2025
783bc01
refactor(80): makes the notification classes consistent with the proj…
BryanARMatheus Nov 30, 2025
07e9270
chore(80): resolves merge conflits
BryanARMatheus Nov 30, 2025
4762f30
feat(80): adds missing methods for indexType and indexValue
BryanARMatheus Nov 30, 2025
96cd1fd
fix(80): fix incorrect getter and setter names for messageText
BryanARMatheus Nov 30, 2025
131db91
fix(80): changes ServiceImpl to use the new method name
BryanARMatheus Nov 30, 2025
fc5087f
fix(80): changes incorrect method name in ServiceImpl
BryanARMatheus Nov 30, 2025
ea0ae24
fix(80): changes set functions to the correct function name
BryanARMatheus Nov 30, 2025
7022def
fix(80): fixes incorrect method names
BryanARMatheus Nov 30, 2025
a5080d9
feat(80): creates a Test post for a frontend feature
BryanARMatheus Nov 30, 2025
78b477e
fix(80): fixes random value selection wrong variable declaring
BryanARMatheus Dec 1, 2025
06babac
fix(80): fixes incorrect variables in ServiceImpl
BryanARMatheus Dec 1, 2025
6d96cde
fix(80): uses correct object when creating the object
BryanARMatheus Dec 1, 2025
ad38f13
fix(80): removes reportText not null verification
BryanARMatheus Dec 1, 2025
bbb650e
fix(80): changes user to be nullable
BryanARMatheus Dec 1, 2025
fb37535
fix(80): removes : from log_notificacao table
BryanARMatheus Dec 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions deploy/postgres/init.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
\c api;
\ c api;
-- Criar tipo ENUM para veículos
CREATE TYPE tipo_veiculo AS ENUM (
'Carro',
Expand All @@ -9,11 +9,7 @@ CREATE TYPE tipo_veiculo AS ENUM (
'Moto',
'Indefinido'
);
CREATE TYPE nivel_usuario AS ENUM (
'Admin',
'Gestor'
);

CREATE TYPE nivel_usuario AS ENUM ('Admin', 'Gestor');
-- Endereço
CREATE TABLE endereco (
id SERIAL PRIMARY KEY,
Expand All @@ -22,28 +18,28 @@ CREATE TABLE endereco (
regiao VARCHAR(30),
trecho GEOMETRY(LineString, 4326)
);

-- Radar
CREATE TABLE radar (
id VARCHAR(9) PRIMARY KEY, -- camera_numero
id_end INT NOT NULL, --refere-se ao id do endereço
id VARCHAR(9) PRIMARY KEY,
-- camera_numero
id_end INT NOT NULL,
--refere-se ao id do endereço
localizacao GEOMETRY(Point, 4326),
vel_reg INT NOT NULL,
carros_min_med NUMERIC(10, 2),
carros_min_max NUMERIC(10, 2),
CONSTRAINT fk_radar_endereco FOREIGN KEY (id_end) REFERENCES endereco(id)
);

-- Leitura
CREATE TABLE leitura (
id SERIAL PRIMARY KEY,
id_rad VARCHAR(9) NOT NULL, --refere-se ao id do radar
id_rad VARCHAR(9) NOT NULL,
--refere-se ao id do radar
dat_hora TIMESTAMP NOT NULL,
tip_vei tipo_veiculo NOT NULL,
vel INT NOT NULL,
CONSTRAINT fk_leitura_radar FOREIGN KEY (id_rad) REFERENCES radar(id)
);

-- Usuário
CREATE TABLE usuario (
id SERIAL PRIMARY KEY,
Expand All @@ -52,27 +48,26 @@ CREATE TABLE usuario (
senha VARCHAR(100) NOT NULL,
nivel nivel_usuario NOT NULL
);

-- Log de Notificações
CREATE TABLE log_notificacao (
id SERIAL PRIMARY KEY,
id_usuario INT NOT NULL,
titulo VARCHAR(50) NOT NULL,
id_usuario INT,
mensagem TEXT NOT NULL,
texto_relatorio TEXT,
tipo_indice VARCHAR(20) NOT NULL,
valor_indice INT NOT NULL,
data_emissao TIMESTAMP DEFAULT NOW(),
data_conclusao TIMESTAMP,
CONSTRAINT fk_log_usuario FOREIGN KEY (id_usuario) REFERENCES usuario(id) ON DELETE CASCADE
);

-- Regiões
CREATE TABLE regioes (
id SERIAL PRIMARY KEY,
nome_regiao VARCHAR(100) NOT NULL UNIQUE,
area_regiao GEOMETRY(Polygon, 4326) NOT NULL
);

-- Pontos de onibus
CREATE TABLE pontos_onibus(
id BIGINT PRIMARY KEY,
ponto GEOMETRY(Point, 4326) NOT NULL
);
);
Original file line number Diff line number Diff line change
@@ -1,47 +1,91 @@
package com.sqlutions.api_4_semestre_backend.controller;

import java.net.URI;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sqlutions.api_4_semestre_backend.entity.NotificationLog;
import com.sqlutions.api_4_semestre_backend.service.NotificationLogService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;

@RestController
@RequestMapping("/logs")
@CrossOrigin
@RequestMapping("/logs")
@Tag(name = "Notification Log", description = "Endpoints for managing notification logs")
public class NotificationLogController {

private final NotificationLogService service;

public NotificationLogController(NotificationLogService service) {
this.service = service;
}
@Autowired
private NotificationLogService service;

@GetMapping
public List<NotificationLog> getAllLogs() {
return service.findAll();
@Operation(summary = "Get all notification logs")
@ApiResponse(responseCode = "200", description = "Logs retrieved successfully")
public ResponseEntity<List<NotificationLog>> getAllLogs() {
return ResponseEntity.ok(service.getAllLogs());
}

@GetMapping("/{id}")
public NotificationLog getLogById(@PathVariable Long id) {
return service.findById(id).orElse(null);
@Operation(summary = "Get notification log by ID")
@ApiResponse(responseCode = "200", description = "Log retrieved successfully")
@ApiResponse(responseCode = "404", description = "Log not found")
public ResponseEntity<NotificationLog> getLogById(@PathVariable Long id) {
NotificationLog log = service.getLogById(id); // já lança 404 no service
return ResponseEntity.ok(log);
}

@PostMapping
public NotificationLog createLog(@RequestBody NotificationLog log) {
return service.save(log);
@Operation(summary = "Create a new notification log")
@ApiResponse(responseCode = "201", description = "Log created successfully")
public ResponseEntity<NotificationLog> createLog(@RequestBody NotificationLog log) {
NotificationLog saved = service.createLog(log);
return ResponseEntity
.created(URI.create("/logs/" + saved.getId()))
.body(saved);
}

@PostMapping("/test")
@Operation(summary = "Create a dummy test notification log")
@ApiResponse(responseCode = "201", description = "Test log created successfully")
public ResponseEntity<NotificationLog> createTestLog() {

NotificationLog saved = service.createTestLog();

return ResponseEntity
.created(URI.create("/logs/" + saved.getId()))
.body(saved);
}



@PutMapping
@Operation(summary = "Update an existing notification log")
@ApiResponse(responseCode = "200", description = "Log updated successfully")
@ApiResponse(responseCode = "404", description = "Log not found")
public ResponseEntity<NotificationLog> updateLog(@RequestBody NotificationLog log) {
NotificationLog updated = service.updateLog(log);
return ResponseEntity.ok(updated);
}

@DeleteMapping("/{id}")
public void deleteLog(@PathVariable Long id) {
service.delete(id);
@Operation(summary = "Delete a notification log")
@ApiResponse(responseCode = "202", description = "Log deletion accepted")
@ApiResponse(responseCode = "404", description = "Log not found")
public ResponseEntity<Void> deleteLog(@PathVariable Long id) {
return ResponseEntity.accepted()
.body(service.deleteLog(id));
}
}
Original file line number Diff line number Diff line change
@@ -1,127 +1,126 @@
package com.sqlutions.api_4_semestre_backend.entity;

import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.Set;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinTable;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;

@Entity
@Table(name = "notification_logs")
@Table(name = "log_notificacao")
public class NotificationLog {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Long id;

@Column(columnDefinition = "TEXT")
private String reportText; // descrição
@ManyToOne
@JoinColumn(name = "id_usuario", nullable = true)
private User user;

private String title; // título do log
@Column(name = "mensagem", columnDefinition = "TEXT", nullable = false)
private String messageText;

private String indexType; // tipo do índice (Segurança, Trafego ou Volume)
@Column(name = "texto_relatorio", columnDefinition = "TEXT")
private String reportText;

private Integer indexValue; // valor do índice (1-5)
@Column(name = "tipo_indice", nullable = false)
private String indexType;

private LocalDateTime startedAt;
@Column(name = "valor_indice", nullable = false)
private Integer indexValue;

private LocalDateTime completedAt;
@Column(name = "data_emissao")
private LocalDateTime emissionDate;

private boolean success;
@Column(name = "data_conclusao")
private LocalDateTime completionDate;

@Column(columnDefinition = "TEXT")
private String errorDetails;
public NotificationLog() {
}

public NotificationLog() {}
public NotificationLog(String reportText, String messageText) {
this.reportText = reportText;
this.messageText = messageText;
}

public NotificationLog(
String reportText,
String title,
String indexType,
Integer indexValue,
LocalDateTime startedAt,
LocalDateTime completedAt,
boolean success,
String errorDetails
) {
this.reportText = reportText;
this.title = title;
this.indexType = indexType;
this.indexValue = indexValue;
this.startedAt = startedAt;
this.completedAt = completedAt;
this.success = success;
this.errorDetails = errorDetails;
public NotificationLog(User user, String messageText, String reportText, LocalDateTime emissionDate, LocalDateTime completionDate) {
this.user = user;
this.messageText = messageText;
this.reportText = reportText;
this.emissionDate = emissionDate;
this.completionDate = completionDate;
}

// Getters and Setters
public Long getId() {
return id;
return id;
}

public String getReportText() {
return reportText;
public User getUser() {
return user;
}

public void setReportText(String reportText) {
this.reportText = reportText;
public void setUser(User user) {
this.user = user;
}

public String getTitle() {
return title;
public String getMessageText() {
return messageText;
}

public void setTitle(String title) {
this.title = title;
public void setMessageText(String messageText) {
this.messageText = messageText;
}

public String getIndexType() {
return indexType;
public String getReportText() {
return reportText;
}

public void setReportText(String reportText) {
this.reportText = reportText;
}

public String getIndexType() {
return indexType;
}

public void setIndexType(String indexType) {
this.indexType = indexType;
}

public Integer getIndexValue() {
return indexValue;
return indexValue;
}

public void setIndexValue(Integer indexValue) {
this.indexValue = indexValue;
}

public LocalDateTime getStartedAt() {
return startedAt;
}

public void setStartedAt(LocalDateTime startedAt) {
this.startedAt = startedAt;
}

public LocalDateTime getCompletedAt() {
return completedAt;
}

public void setCompletedAt(LocalDateTime completedAt) {
this.completedAt = completedAt;
public LocalDateTime getEmissionDate() {
return emissionDate;
}

public boolean isSuccess() {
return success;
public void setEmissionDate(LocalDateTime emissionDate) {
this.emissionDate = emissionDate;
}

public void setSuccess(boolean success) {
this.success = success;
public LocalDateTime getCompletionDate() {
return completionDate;
}

public String getErrorDetails() {
return errorDetails;
public void setCompletionDate(LocalDateTime completionDate) {
this.completionDate = completionDate;
}

public void setErrorDetails(String errorDetails) {
this.errorDetails = errorDetails;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@

@Repository
public interface NotificationLogRepository extends JpaRepository<NotificationLog, Long> {

}
Loading