Skip to content

Commit

Permalink
Merge pull request #69 from Julio-Pupim/fix/salvando-projeto
Browse files Browse the repository at this point in the history
Fix/salvando projeto
  • Loading branch information
Julio-Pupim authored Nov 22, 2024
2 parents c86bda1 + 40c9191 commit bbd0921
Show file tree
Hide file tree
Showing 44 changed files with 898 additions and 642 deletions.
4 changes: 3 additions & 1 deletion backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
</scm>
<properties>
<java.version>21</java.version>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -149,7 +151,7 @@
<configuration>
<linkXRef>false</linkXRef>
<minimumTokens>100</minimumTokens>
<targetJdk>1.7</targetJdk>
<targetJdk>21</targetJdk>
</configuration>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@CrossOrigin("*")
@RestController
@RequestMapping("/agenda")
@RequestMapping("/api/agenda")
public class AgendaController extends AbstractController<Agenda, AgendaRepository, AgendaService> {

public AgendaController(AgendaService service) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import br.com.servicemaker.domain.Servico;
import br.com.servicemaker.repository.ServicoRepository;
import br.com.servicemaker.service.ServicoService;
import java.util.List;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -13,8 +17,16 @@
public class ServicoController extends
AbstractController<Servico, ServicoRepository, ServicoService> {

private final ServicoService servicoService;

public ServicoController(ServicoService service) {
super(service);
this.servicoService = service;
}

@GetMapping("/prestador/{idPrestador}")
public ResponseEntity<List<Servico>> findAllServicosPorPrestador(@PathVariable Long idPrestador) {
List<Servico> servicosPorPrestador = servicoService.findAllServicosPorPrestador(idPrestador);
return ResponseEntity.ok(servicosPorPrestador);
}
}
3 changes: 1 addition & 2 deletions backend/src/main/java/br/com/servicemaker/domain/Agenda.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ public class Agenda extends AbstractEntity {


@OneToMany(mappedBy = "agenda", cascade = CascadeType.REMOVE)
@JsonManagedReference
private List<CronogramaTrabalho> cronogramas;

@OneToMany(mappedBy = "agenda")
@JsonManagedReference
@JsonManagedReference("agenda-reservas")
private List<Reserva> reservas;

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,5 @@ public class Avaliacao extends AbstractEntity {
@JsonBackReference
private Usuario cliente;

@ManyToOne()
@JoinColumn(name = "ID_PRESTADOR", nullable = false)
@JsonBackReference
private Prestador prestador;

}

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package br.com.servicemaker.domain;

import br.com.servicemaker.abstractcrud.AbstractEntity;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.fasterxml.jackson.annotation.JsonBackReference;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.JoinColumn;
Expand Down Expand Up @@ -32,7 +32,7 @@ public class Certificado extends AbstractEntity {

@ManyToOne()
@JoinColumn(name = "ID_PRESTADOR", nullable = false)
@JsonManagedReference
@JsonBackReference("prestador-certificados")
private Prestador prestador;

}
15 changes: 11 additions & 4 deletions backend/src/main/java/br/com/servicemaker/domain/Prestador.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import java.util.Collection;
Expand All @@ -14,6 +15,7 @@
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;

Expand All @@ -23,23 +25,26 @@
@AllArgsConstructor
@NoArgsConstructor
@DiscriminatorValue("prestador")
@ToString(exclude = "servicos")
public class Prestador extends Usuario {


@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "id_agenda", nullable = false, referencedColumnName = "id")
@JsonManagedReference
private Agenda agenda;

@OneToMany(mappedBy = "prestador", cascade = {CascadeType.REMOVE, CascadeType.MERGE})
@JsonManagedReference
@JsonManagedReference("prestador-servico")
private List<Servico> servicos;

@OneToMany(mappedBy = "prestador", cascade = {CascadeType.REMOVE,
CascadeType.MERGE}, orphanRemoval = true)
@JsonManagedReference
@JsonManagedReference("prestador-certificados")
private List<Certificado> certificados;

@ManyToOne
@JoinColumn(name = "id_setor")
private Setor setor;

public Prestador(String nome, String cpf, String senha, Contato contato, Endereco endereco,
Roles role,
Agenda agenda) {
Expand All @@ -52,4 +57,6 @@ public Collection<? extends GrantedAuthority> getAuthorities() {
return List.of(new SimpleGrantedAuthority(Roles.ROLE_PRESTADOR.getRole()),
new SimpleGrantedAuthority(Roles.ROLE_CLIENTE.getRole()));
}


}
11 changes: 3 additions & 8 deletions backend/src/main/java/br/com/servicemaker/domain/Reserva.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,19 @@ public class Reserva extends AbstractEntity {

@ManyToOne()
@JoinColumn(name = "ID_CLIENTE", nullable = false)
@JsonBackReference
@JsonBackReference("clientes-reservas")
private Usuario cliente;

@ManyToOne()
@JoinColumn(name = "ID_AGENDA", nullable = false)
@JsonBackReference
@JsonBackReference("agenda-reservas")
private Agenda agenda;

@ManyToOne()
@JoinColumn(name = "ID_SERVICO", nullable = false)
@JsonBackReference
@JsonBackReference("reservas-servicos")
private Servico servico;

@ManyToOne()
@JoinColumn(name = "id_prestador", nullable = false)
@JsonBackReference
private Prestador prestador;

@Enumerated(EnumType.STRING)
private Status status;

Expand Down
11 changes: 4 additions & 7 deletions backend/src/main/java/br/com/servicemaker/domain/Servico.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,17 @@
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;

@EqualsAndHashCode(callSuper = false)
@Entity
@Table(name = "SERVICO")
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString(exclude = "prestador")
public class Servico extends AbstractEntity {

@ManyToOne
@JoinColumn(name = "ID_SETOR", nullable = false)
@JsonBackReference
private Setor setor;

private String descricao;

@Column(name = "tempo_servico")
Expand All @@ -38,11 +35,11 @@ public class Servico extends AbstractEntity {

@ManyToOne
@JoinColumn(name = "ID_PRESTADOR", nullable = false)
@JsonBackReference
@JsonBackReference("prestador-servico")
private Prestador prestador;

@OneToMany(mappedBy = "servico")
@JsonManagedReference
@JsonManagedReference("reservas-servicos")
private List<Reserva> reservas;

}
5 changes: 2 additions & 3 deletions backend/src/main/java/br/com/servicemaker/domain/Usuario.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,12 @@ public class Usuario extends AbstractEntity implements UserDetails {
@Enumerated(EnumType.STRING)
private Roles role;

@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "id_contato")
@JsonManagedReference
private Contato contato;

@OneToMany(mappedBy = "cliente", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JsonManagedReference
@JsonManagedReference("clientes-reservas")
private List<Reserva> reservas;

@OneToMany(mappedBy = "cliente", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

import br.com.servicemaker.abstractcrud.AbstractRepository;
import br.com.servicemaker.domain.Servico;
import java.util.List;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface ServicoRepository extends AbstractRepository<Servico> {

@Query("SELECT s FROM Servico s WHERE s.prestador.id = :idPrestador ")
List<Servico> findAllServicosPorPrestador(@Param("idPrestador") Long idPrestador);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@
import br.com.servicemaker.domain.Servico;
import br.com.servicemaker.repository.ServicoRepository;
import jakarta.persistence.EntityManager;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ServicoService extends AbstractService<Servico, ServicoRepository> {

private final ServicoRepository servicoRepository;

@Autowired
public ServicoService(ServicoRepository repository, EntityManager em) {
super(repository, em);
this.servicoRepository = repository;
}

public List<Servico> findAllServicosPorPrestador(Long idPrestador) {
return servicoRepository.findAllServicosPorPrestador(idPrestador);
}
}
3 changes: 3 additions & 0 deletions backend/src/main/resources/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: br.com.servicemaker.SerivceMakerApplication

4 changes: 2 additions & 2 deletions backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
spring.application.name=serivceMaker
spring.datasource.url=jdbc:postgresql://localhost:5432/servicemaker
spring.datasource.url=jdbc:postgresql://autorack.proxy.rlwy.net:44626/railway
spring.datasource.username=postgres
spring.datasource.password=root
spring.datasource.password=VkSHVJkKYqUAopijrQfXuNeAYnkygFLT
spring.datasource.driver-class-name=org.postgresql.Driver
api.security.token.secret=${JWT_SECRET:my-secret-key}
spring.jpa.show-sql=true
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
INSERT INTO servicemaker.public.setor (DESCRICAO)
INSERT INTO setor (DESCRICAO)
VALUES
('Encanador'),
('Eletricista'),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ALTER TABLE IF EXISTS usuario
ADD COLUMN IF NOT EXISTS id_setor bigint;

ALTER TABLE IF EXISTS usuario
ADD CONSTRAINT usuario_setor_fk FOREIGN KEY (id_setor) REFERENCES setor (id);

alter table if exists servico
drop column if exists id_setor
Loading

0 comments on commit bbd0921

Please sign in to comment.