Buscar

Trabalho Semestral

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes
Você viu 3, do total de 38 páginas

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes
Você viu 6, do total de 38 páginas

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes
Você viu 9, do total de 38 páginas

Faça como milhares de estudantes: teste grátis o Passei Direto

Esse e outros conteúdos desbloqueados

16 milhões de materiais de várias disciplinas

Impressão de materiais

Agora você pode testar o

Passei Direto grátis

Você também pode ser Premium ajudando estudantes

Prévia do material em texto

2
UNIVERSIDADE PAULISTA
SAMUEL SANTOS
TRABALHO SEMESTRAL
SÃO PAULO
2021
SUMÁRIO
1 INTRODUÇÃO	9
2 BACKEND	10
2.1 Domains/classes	10
2.2 Resources	16
2.2 Services	20
2.2 DTOs (Data Transfer Objects)	25
2.3 Repositories	29
3 FRONT-END	30
3.1 Componentes	30
3.2 Services	37
3.3 Rotas	40
3.4 Estilização (scss)	40
4 IMAGENS	43
	43
1 INTRODUÇÃO
Backend construído com JAVA + Spring Boot, Front-end construido em Angular 12+
2 BACKEND
2.1 Domains/classes
 
Proprietario: 
package com.erp.domain;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Proprietario implements Serializable {
	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	
	private String nome;
	
	@Column(unique = true)
	private String cpf;
	
	private String email;
	private String telefone;
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getNome() {
		return nome;
	}
	public void setNome(String nome) {
		this.nome = nome;
	}
	public String getCpf() {
		return cpf;
	}
	public void setCpf(String cpf) {
		this.cpf = cpf;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getTelefone() {
		return telefone;
	}
	public void setTelefone(String telefone) {
		this.telefone = telefone;
	}
	
	public Proprietario() {
		super();
		// TODO Auto-generated constructor stub
	}
	
	public Proprietario(Integer id, String nome, String cpf, String email, String telefone) {
		super();
		this.id = id;
		this.nome = nome;
		this.cpf = cpf;
		this.email = email;
		this.telefone = telefone;
	}
}
Propriedade:
package com.erp.domain;
import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
@Entity
public class Propriedade implements Serializable {
	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	private String nome;
	private String numeroInscricao;
	private String registro;
	@OneToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
	@JoinColumn(name = "endereco_id")
	private Endereco endereco;
	@OneToOne
	@JoinColumn(name = "proprietario_id")
	private Proprietario proprietario;
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getNome() {
		return nome;
	}
	public void setNome(String nome) {
		this.nome = nome;
	}
	public Endereco getEndereco() {
		return endereco;
	}
	public void setEndereco(Endereco endereco) {
		this.endereco = endereco;
	}
	public Proprietario getProprietario() {
		return proprietario;
	}
	public void setProprietario(Proprietario proprietario) {
		this.proprietario = proprietario;
	}
	
	
	public String getNumeroInscricao() {
		return numeroInscricao;
	}
	public void setNumeroInscricao(String numeroInscricao) {
		this.numeroInscricao = numeroInscricao;
	}
	public String getRegistro() {
		return registro;
	}
	public void setRegistro(String registro) {
		this.registro = registro;
	}
	public Propriedade(Integer id, String nome, Endereco endereco, Proprietario proprietario) {
		super();
		this.id = id;
		this.nome = nome;
		this.endereco = endereco;
		this.proprietario = proprietario;
	}
	public Propriedade() {
		super();
		// TODO Auto-generated constructor stub
	}
}
Endereço:
package com.erp.domain;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import com.fasterxml.jackson.annotation.JsonIgnore;
@Entity
public class Endereco implements Serializable {
	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	private String cep;
	private String logradouro;
	private Integer numero;
	private String cidade;
	private String estado;
	private String complemento;
	private String bairro;
	@JsonIgnore
	@JoinColumn(name = "propriedade_id")
	private Propriedade propriedade;
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getCep() {
		return cep;
	}
	public void setCep(String cep) {
		this.cep = cep;
	}
	public String getLogradouro() {
		return logradouro;
	}
	public void setLogradouro(String logradouro) {
		this.logradouro = logradouro;
	}
	public Integer getNumero() {
		return numero;
	}
	public void setNumero(Integer numero) {
		this.numero = numero;
	}
	public String getCidade() {
		return cidade;
	}
	public void setCidade(String cidade) {
		this.cidade = cidade;
	}
	public String getEstado() {
		return estado;
	}
	public void setEstado(String estado) {
		this.estado = estado;
	}
	public String getComplemento() {
		return complemento;
	}
	public void setComplemento(String complemento) {
		this.complemento = complemento;
	}
	public String getBairro() {
		return bairro;
	}
	public void setBairro(String bairro) {
		this.bairro = bairro;
	}
	public Propriedade getPropriedade() {
		return propriedade;
	}
	public void setPropriedade(Propriedade propriedade) {
		this.propriedade = propriedade;
	}
	public Endereco(Integer id, String cep, String logradouro, Integer numero, String cidade, String estado,
			String complemento, String bairro) {
		super();
		this.id = id;
		this.cep = cep;
		this.logradouro = logradouro;
		this.numero = numero;
		this.cidade = cidade;
		this.estado = estado;
		this.complemento = complemento;
		this.bairro = bairro;
	}
	public Endereco() {
		super();
	}
}
2.2 Resources
Proprietario:
package com.erp.resources; 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.erp.domain.Propriedade;
import com.erp.domain.Proprietario;
import com.erp.dto.ProprietarioDTO;
import com.erp.services.ProprietarioService;
@Controller
@RequestMapping(value = "/proprietarios")
public class ProprietarioResource {
	@Autowired
	private ProprietarioService service;
	
	@RequestMapping(value = "/{id}", method =RequestMethod.GET)
	public ResponseEntity<Proprietario> find(@PathVariable Integer id){
		Proprietario obj = service.find(id);
		return ResponseEntity.ok().body(obj);
	}
	@RequestMapping(method = RequestMethod.POST)
	public ResponseEntity<Proprietario> insert(@RequestBody ProprietarioDTO dto) {
		Proprietario obj = service.save(dto);
		return ResponseEntity.ok().body(obj);
	}
	@RequestMapping(method = RequestMethod.PUT)
	public ResponseEntity<Proprietario> update(@RequestBody Proprietario dto) {
		Proprietario obj = service.update(dto);
		return ResponseEntity.ok().body(obj);
	}
	@RequestMapping(method = RequestMethod.GET)
	public ResponseEntity<Page<Proprietario>> findPage(@RequestParam(value = "page", defaultValue = "0") Integer page,
			@RequestParam(value = "linesPerPage", defaultValue = "10") Integer linesPerPage,
			@RequestParam(value = "orderBy", defaultValue = "nome") String orderBy,
			@RequestParam(value = "direction", defaultValue = "ASC") String direction,
			@RequestParam(value = "nome", defaultValue = "") String nome) {
		Page<Proprietario>list = service.findPage(page, linesPerPage, orderBy, direction, nome);
		return ResponseEntity.ok().body(list);
	}
	@RequestMapping(value = "{/id}", method = RequestMethod.DELETE)
	public ResponseEntity<Propriedade> delete(@PathVariable Integer id) {
		service.delete(id);
		return ResponseEntity.ok().body(null);
	}
}
Propriedade:
package com.erp.resources;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.erp.domain.Propriedade;
import com.erp.dto.PropriedadeDTO;
import com.erp.services.PropriedadeService;
@Controller
@RequestMapping(value = "/propriedades")
public class PropriedadeResource {
	
	@Autowired
	private PropriedadeService service;
	
	@RequestMapping(value = "/{id}", method =RequestMethod.GET)
	public ResponseEntity<Propriedade> find(@PathVariable Integer id){
		Propriedade obj = service.find(id);
		return ResponseEntity.ok().body(obj);
	}
	
	@RequestMapping(method = RequestMethod.POST)
	public ResponseEntity<Propriedade> insert(@RequestBody PropriedadeDTO dto){
		Propriedade obj = service.save(dto);
		return ResponseEntity.ok().body(obj);
	}
	
	@RequestMapping(method = RequestMethod.PUT)
	public ResponseEntity<Propriedade> insert(@RequestBody Propriedade dto){
		Propriedade obj = service.update(dto);
		return ResponseEntity.ok().body(obj);
	}
	
	@RequestMapping(method = RequestMethod.GET)
	public ResponseEntity<Page<Propriedade>> findPage(
			@RequestParam(value="page", defaultValue="0") Integer page, 
			@RequestParam(value="linesPerPage", defaultValue="10") Integer linesPerPage,
			@RequestParam(value="orderBy", defaultValue="nome") String orderBy,
			@RequestParam(value="direction", defaultValue="ASC") String direction,
			@RequestParam(value="nome", defaultValue="") String nome){
		Page<Propriedade> list = service.findPage(page, linesPerPage, orderBy, direction, nome);
		return ResponseEntity.ok().body(list);
	}
	
	@RequestMapping(value="{/id}",method = RequestMethod.DELETE)
	public ResponseEntity<Propriedade> delete(@PathVariable Integer id){
		service.delete(id);
		return ResponseEntity.ok().body(null);
	}
}
Endereço:
package com.erp.resources;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.erp.domain.Endereco;
import com.erp.domain.Propriedade;
import com.erp.services.EnderecoService;
@Controller
@RequestMapping(value = "/enderecos")
public class EnderecoResource {
	@Autowired
	private EnderecoService service;
	
	@RequestMapping(value = "/{id}", method =RequestMethod.GET)
	public ResponseEntity<Endereco> find(@PathVariable Integer id){
		Endereco obj = service.find(id);
		return ResponseEntity.ok().body(obj);
	}
	@RequestMapping(method = RequestMethod.PUT)
	public ResponseEntity<Endereco> update(@RequestBody Endereco dto) {
		Endereco obj = service.update(dto);
		return ResponseEntity.ok().body(obj);
	}
	@RequestMapping(method = RequestMethod.GET)
	public ResponseEntity<Page<Endereco>> findPage(@RequestParam(value = "page", defaultValue = "0") Integer page,
			@RequestParam(value = "linesPerPage", defaultValue = "10") Integer linesPerPage,
			@RequestParam(value = "orderBy", defaultValue = "nome") String orderBy,
			@RequestParam(value = "direction", defaultValue = "ASC") String direction,
			@RequestParam(value = "nome", defaultValue = "") String nome) {
		Page<Endereco> list = service.findPage(page, linesPerPage, orderBy, direction, nome);
		return ResponseEntity.ok().body(list);
	}
	@RequestMapping(value = "{/id}", method = RequestMethod.DELETE)
	public ResponseEntity<Propriedade> delete(@PathVariable Integer id) {
		service.delete(id);
		return ResponseEntity.ok().body(null);
	}
}
2.2 Services
Propriedade:
package com.erp.services; 
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;
import com.erp.domain.Endereco;
import com.erp.domain.Propriedade;
import com.erp.domain.Proprietario;
import com.erp.dto.PropriedadeDTO;
import com.erp.enums.UserRole;
import com.erp.repositories.PropriedadeRepository;
import com.erp.security.UserSS;
import com.erp.services.exception.AuthorizationException;
import com.erp.services.exception.ObjectNotFoundException;
@Service
public class PropriedadeService {
	
	@Autowired
	private ProprietarioService proprietarioService;
	
	@Autowired
	private PropriedadeRepository rep;
	
	public Propriedade find(Integer id) {
		Optional<Propriedade> objOpt = rep.findById(id) ;
		objOpt.orElseThrow(()-> new ObjectNotFoundException(
				"Objeto não encontrado! Id: " + id + ", Tipo: " + Propriedade.class.getName()));
		
		UserSS user = UserService.authenticated();
		
		if (user == null || user.hasRole(UserRole.DIRETOR)) 
			throw new AuthorizationException("Acesso negado. Você não possui permissões para acessar esse conteudo!");
		
		Propriedade objSearch = objOpt.get();
		
		return objSearch;
	}
	
	public Propriedade save(PropriedadeDTO dto) {
		Proprietario proprietario = proprietarioService.find(dto.getProprietario());
		Endereco endereco = new Endereco(null, dto.getEndereco().getCep(), dto.getEndereco().getLogradouro(), dto.getEndereco().getNumero(),
				dto.getEndereco().getCidade(), dto.getEndereco().getEstado(), dto.getEndereco().getComplemento(), dto.getEndereco().getBairro());
		Propriedade obj = new Propriedade(null,dto.getNome() , endereco, proprietario);
		return rep.save(obj);
	}
	
	public Propriedade update(Propriedade obj) {
		return rep.save(obj);
	}
	
	public void delete(Integer id){
		rep.deleteById(id);
	}
	
	public Page<Propriedade> findPage( Integer page, Integer linesPerPage, String orderBy, String direction, String nome){
		PageRequest pageReq = PageRequest.of(page, linesPerPage, Direction.valueOf(direction), orderBy);
		return rep.findAll(pageReq);
	}
}
Propriedade:
package com.erp.services;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;
import com.erp.domain.Proprietario;
import com.erp.dto.ProprietarioDTO;
import com.erp.enums.UserRole;
import com.erp.repositories.ProprietarioRepository;
import com.erp.security.UserSS;
import com.erp.services.exception.AuthorizationException;
import com.erp.services.exception.ObjectNotFoundException;
@Service
public class ProprietarioService {
	@Autowired
	private ProprietarioRepository rep;
	public Proprietario find(Integer id) {
		Optional<Proprietario> objOpt = rep.findById(id);
		objOpt.orElseThrow(() -> new ObjectNotFoundException("Proprietario não encontrado. Id: " + id));
		UserSS user = UserService.authenticated();
		if (user == null || user.hasRole(UserRole.DIRETOR))
			throw new AuthorizationException("Acesso negado. Você não possui permissões para acessar esse conteudo!");
		Proprietario objSearch = objOpt.get();
		return objSearch;
	}
	public Proprietariosave(ProprietarioDTO dto) {
		Proprietario obj = new Proprietario(null, dto.getNome(), dto.getCpf(), dto.getEmail(), dto.getTelefone());
		return rep.save(obj);
	}
	public Proprietario update(Proprietario obj) {
		return rep.save(obj);
	}
	public void delete(Integer id) {
		rep.deleteById(id);
	}
	public Page<Proprietario> findPage(Integer page, Integer linesPerPage, String orderBy, String direction,
			String nome) {
		PageRequest pageReq = PageRequest.of(page, linesPerPage, Direction.valueOf(direction), orderBy);
		return rep.findAll(pageReq);
	}
}
Endereço:
package com.erp.services;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;
import com.erp.domain.Endereco;
import com.erp.domain.Propriedade;
import com.erp.enums.UserRole;
import com.erp.repositories.EnderecoRepository;
import com.erp.security.UserSS;
import com.erp.services.exception.AuthorizationException;
import com.erp.services.exception.ObjectNotFoundException;
@Service
public class EnderecoService {
	@Autowired
	private EnderecoRepository rep;
	public Endereco find(Integer id) {
		Optional<Endereco> objOpt = rep.findById(id);
		objOpt.orElseThrow(() -> new ObjectNotFoundException(
				"Objeto não encontrado! Id: " + id + ", Tipo: " + Propriedade.class.getName()));
		UserSS user = UserService.authenticated();
		if (user == null || user.hasRole(UserRole.DIRETOR))
			throw new AuthorizationException("Acesso negado. Você não possui permissões para acessar esse conteudo!");
		Endereco objSearch = objOpt.get();
		return objSearch;
	}
	public Endereco update(Endereco obj) {
		return rep.save(obj);
	}
	public void delete(Integer id) {
		rep.deleteById(id);
	}
	public Page<Endereco> findPage(Integer page, Integer linesPerPage, String orderBy, String direction, String nome) {
		PageRequest pageReq = PageRequest.of(page, linesPerPage, Direction.valueOf(direction), orderBy);
		return rep.findAll(pageReq);
	}
}
Services auxiliares:
package com.erp.services;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import com.erp.domain.Auth;
import com.erp.repositories.AuthRepository;
import com.erp.security.UserSS;
@Service
public class UserDetailsServiceImpl implements UserDetailsService{
	
	@Autowired
	private AuthRepository rep;
	@Override
	public UserDetails loadUserByUsername(String cpf) throws UsernameNotFoundException {
		Optional<Auth> objOpt = rep.findByusername(cpf);
		if(!objOpt.isPresent()) {
			throw new UsernameNotFoundException(cpf);
		}
		Auth user = objOpt.get();
		
		return new UserSS(user.getId(), user.getUsername(), user.getBiometria(), user.getRole());
	}
}
package com.erp.services;
import org.springframework.security.core.context.SecurityContextHolder;
import com.erp.security.UserSS;
public class UserService {
	public static UserSS authenticated() {
		try {
			return (UserSS) SecurityContextHolder.getContext().getAuthentication()
					.getPrincipal();
			} catch (Exception e) {
				return null;
			}
		}
}
2.2 DTOs (Data Transfer Objects)
Proprietario:
package com.erp.dto; 
import java.io.Serializable;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotEmpty;
import org.hibernate.validator.constraints.br.CPF;
public class ProprietarioDTO implements Serializable {
	private static final long serialVersionUID = 1L;
	@NotEmpty(message = "Nome obrigatório")
	private String nome;
	@CPF
	private String cpf;
	@Email
	private String email;
	private String telefone;
	public String getNome() {
		return nome;
	}
	public void setNome(String nome) {
		this.nome = nome;
	}
	public String getCpf() {
		return cpf;
	}
	public void setCpf(String cpf) {
		this.cpf = cpf;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getTelefone() {
		return telefone;
	}
	public void setTelefone(String telefone) {
		this.telefone = telefone;
	}
}
Propriedade:
package com.erp.dto;
import java.io.Serializable;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
public class PropriedadeDTO implements Serializable {
	private static final long serialVersionUID = 1L;
	@NotEmpty(message = "Nome obrigatório")
	private String nome;
	private String numeroInscricao;
	private String registro;
	@Min(value = 1, message = "Informe o dono da propriedade")
	private Integer proprietario;
	private EnderecoDTO endereco;
	public String getNome() {
		return nome;
	}
	public void setNome(String nome) {
		this.nome = nome;
	}
	public String getNumeroInscricao() {
		return numeroInscricao;
	}
	public void setNumeroInscricao(String numeroInscricao) {
		this.numeroInscricao = numeroInscricao;
	}
	public String getRegistro() {
		return registro;
	}
	public void setRegistro(String registro) {
		this.registro = registro;
	}
	public Integer getProprietario() {
		return proprietario;
	}
	public EnderecoDTO getEndereco() {
		return endereco;
	}
	public void setEndereco(EnderecoDTO endereco) {
		this.endereco = endereco;
	}
	public void setProprietario(Integer proprietario) {
		this.proprietario = proprietario;
	}
}
Endereço:
package com.erp.dto;
import java.io.Serializable;
import javax.validation.constraints.NotEmpty;
public class EnderecoDTO implements Serializable {
	private static final long serialVersionUID = 1L;
	@NotEmpty(message = "Cep obigatório")
	private String cep;
	@NotEmpty(message = "Logradouro obigatório")
	private String logradouro;
	@NotEmpty(message = "Numero obigatório")
	private Integer numero;
	private String cidade;
	private String estado;
	private String complemento;
	private String bairro;
	public String getCep() {
		return cep;
	}
	public void setCep(String cep) {
		this.cep = cep;
	}
	public String getLogradouro() {
		return logradouro;
	}
	public void setLogradouro(String logradouro) {
		this.logradouro = logradouro;
	}
	public Integer getNumero() {
		return numero;
	}
	public void setNumero(Integer numero) {
		this.numero = numero;
	}
	public String getCidade() {
		return cidade;
	}
	public void setCidade(String cidade) {
		this.cidade = cidade;
	}
	public String getEstado() {
		return estado;
	}
	public void setEstado(String estado) {
		this.estado = estado;
	}
	public String getComplemento() {
		return complemento;
	}
	public void setComplemento(String complemento) {
		this.complemento = complemento;
	}
	public String getBairro() {
		return bairro;
	}
	public void setBairro(String bairro) {
		this.bairro = bairro;
	}
}
2.3 Repositories
package com.erp.repositories;
import org.springframework.data.jpa.repository.support.JpaRepositoryImplementation;
import com.erp.domain.Propriedade;
public interface PropriedadeRepository extends JpaRepositoryImplementation<Propriedade, Integer>{
}
package com.erp.repositories;
import org.springframework.data.jpa.repository.support.JpaRepositoryImplementation;
import com.erp.domain.Proprietario;
public interface ProprietarioRepository extends JpaRepositoryImplementation<Proprietario, Integer>{
}
package com.erp.repositories;
import org.springframework.data.jpa.repository.support.JpaRepositoryImplementation;
import com.erp.domain.Endereco;
public interface EnderecoRepository extends JpaRepositoryImplementation<Endereco, Integer>{
	
}
3 FRONT-END
3.1 Componentes
Proprietario:
<div class="row"> 
 <div class="col-md-5 bg-dark"></div>
 <div class="col-md-7">
 <div class="content pt-6">
 <h1 class="title mb-4">Cadastre-se</h1><form (ngSubmit)="submit()">
 <div class="row">
 <div class="col-md-10 mb-3">
 <div class="form-group">
 <label for="name">Nome</label>
 <input class="form-control" type="text" id="name" name="name" [(ngModel)]="user.name">
 </div>
 </div>
 </div>
 <div class="row">
 <div class="col-md-10 mb-3">
 <div class="form-group">
 <label for="cpf">CPF</label>
 <input class="form-control" type="text" id="cpf" name="cpf" [(ngModel)]="user.cpf">
 </div>
 </div>
 </div>
 <div class="row">
 <div class="col-md-10 mb-3">
 <div class="form-group">
 <label for="email">Email</label>
 <input class="form-control" type="text" name="email" [(ngModel)]="user.email">
 </div>
 </div>
 </div>
 <div class="row">
 <div class="col-md-10 mb-3">
 <div class="form-group">
 <label for="password">Senha</label>
 <input class="form-control" type="password" name="password" [(ngModel)]="user.password">
 </div>
 </div>
 </div>
 <div class="row">
 <div class="col-md-10 mb-3">
 <div class="form-group">
 <label for="confirmPassword">Confirmar senha</label>
 <input class="form-control" type="password" name="confirmPassword" [(ngModel)]="user.confirmPassword">
 </div>
 </div>
 </div>
 <div class="row">
 <div class="col-md-10 flex-center">
 <button class="btn btn-primary mt-4" [class.loading]="loader">Avançar</button>
 </div>
 </div>
 </form>
 </div> 
 </div>
</div>
import { Component } from '@angular/core';
import { UserNewDTO } from '../../models/user-new-dto';
import { UserService } from '../../services/user.service';
@Component({
 selector: 'app-user-form',
 templateUrl: './user-form.component.html',
 styleUrls: ['./user-form.component.scss']
})
export class UserFormComponent {
 user: UserNewDTO= {
 name:'',
 cpf:'',
 email:'',
 password:'',
 confirmPassword:'',
 }
 loader = false;
 constructor(private service: UserService) { }
 submit(){
 this.loader = true;
 this.service.insert(this.user).subscribe(resp => {
 this.loader = false;
 console.log(resp)
 }, ()=> {
 this.loader = false;
 })
 }
 find(id: number) {
 this.loader = true;
 this.service.find(id).subscribe(resp => {
 this.loader = false;
 this.user = resp;
 }, err => {
 this.loader = true;
 })
 }
 update() {
 this.loader = true;
 this.service.update(this.user).subscribe(resp => {
 this.loader = false;
 }, err => {
 this.loader = true;
 })
 }
 delete(id: number) {
 this.loader = true;
 this.service.delete(id).subscribe(resp => {
 this.loader = false;
 }, err => {
 this.loader = true;
 })
 }
}
Propriedade:
<div class="row">
 <div class="col-md-5 bg-dark"></div>
 <div class="col-md-7">
 <div class="content pt-6">
 <h1 class="title mb-4">{{action}} Propriedade</h1>
 <form (ngSubmit)="submit()">
 <div class="row">
 <div class="col-md-10 mb-3">
 <div class="form-group">
 <label for="name">Nome</label>
 <input class="form-control" type="text" id="name" name="name" [(ngModel)]="propriedade.nome">
 </div>
 </div>
 </div>
 <div class="row">
 <div class="col-md-6 mb-3">
 <div class="form-group">
 <label for="name">Numero inscricao</label>
 <input class="form-control" type="text" id="name" name="name" [(ngModel)]="propriedade.inscricao">
 </div>
 </div>
 <div class="col-md-4 mb-3">
 <div class="form-group">
 <label for="name">Numero registro</label>
 <input class="form-control" type="text" id="name" name="name" [(ngModel)]="propriedade.registro">
 </div>
 </div>
 </div>
 <div class="row">
 <div class="col-md-10 flex-center">
 <button class="btn btn-primary mt-4" [class.loading]="loader">Avançar</button>
 </div>
 </div>
 </form>
 </div>
 
 </div>
</div>
import { Component, OnInit } from '@angular/core';
import { PropriedadeDTO } from '../../models/propriedade-dto';
import { PropriedadeService } from '../../services/propriedade.service';
@Component({
 selector: 'app-propriedade-form',
 templateUrl: './propriedade-form.component.html',
 styleUrls: ['./propriedade-form.component.scss']
})
export class PropriedadeFormComponent {
 action = 'Cadastrar';
 propriedade: PropriedadeDTO = {
 nome: '',
 registro: '',
 inscricao: '',
 endereco: {
 cep: '',
 cidade: '',
 logradouro: '',
 estado: '',
 complemento: '',
 bairro: '',
 numero: 0,
 }
 }
 loader = false;
 constructor(private service: PropriedadeService) { }
 submit() {
 this.loader = true;
 this.service.insert(this.propriedade).subscribe(resp => {
 this.loader = false;
 }, err => {
 this.loader = true;
 })
 }
 find(id: number) {
 this.loader = true;
 this.service.find(id).subscribe(resp => {
 this.loader = false;
 this.propriedade = resp;
 }, err => {
 this.loader = true;
 })
 }
 update() {
 this.loader = true;
 this.service.update(this.propriedade).subscribe(resp => {
 this.loader = false;
 }, err => {
 this.loader = true;
 })
 }
 delete(id: number) {
 this.loader = true;
 this.service.delete(id).subscribe(resp => {
 this.loader = false;
 }, err => {
 this.loader = true;
 })
 }
}
Endereço:
<div class="row">
 <div class="col-md-5 bg-dark"></div>
 <div class="col-md-7">
 <div class="content pt-6">
 <h1 class="title mb-4">{{action}} Endereço</h1>
 <form (ngSubmit)="submit()">
 
 <div class="row">
 <div class="col-md-4 mb-3">
 <div class="form-group">
 <label for="cpf">CEP</label>
 <input placeholder="00000-000" class="form-control" type="text" id="cpf" name="cpf" [(ngModel)]="endereco.cep">
 </div>
 </div>
 </div>
 <div class="row">
 <div class="col-md-10 mb-3">
 <div class="form-group">
 <label for="email">Rua</label>
 <input class="form-control" type="text" name="email" [(ngModel)]="endereco.logradouro">
 </div>
 </div>
 </div>
 <div class="row">
 <div class="col-md-8 mb-3">
 <div class="form-group">
 <label for="password">Cidade</label>
 <input class="form-control" type="password" name="password" [(ngModel)]="endereco.cidade"></div>
 </div>
 <div class="col-md-2 mb-3">
 <div class="form-group">
 <label for="confirmPassword">UF</label>
 <input placeholder="SP" class="form-control" type="password" name="confirmPassword" [(ngModel)]="endereco.estado">
 </div>
 </div>
 </div>
 <div class="row">
 <div class="col-md-2 mb-3">
 <div class="form-group">
 <label for="confirmPassword">Numero</label>
 <input class="form-control" type="password" name="confirmPassword" [(ngModel)]="endereco.numero">
 </div>
 </div>
 <div class="col-md-8 mb-3">
 <div class="form-group">
 <label for="confirmPassword">Complemento</label>
 <input class="form-control" type="password" name="confirmPassword" [(ngModel)]="endereco.complemento">
 </div>
 </div>
 </div>
 <div class="row">
 <div class="col-md-10 flex-center">
 <button class="btn btn-primary mt-4" [class.loading]="loader">Concluir</button>
 </div>
 </div>
 </form>
 </div>
 
 </div>
</div>
import { Component, OnInit } from '@angular/core';
import { EnderecoDTO } from 'src/app/propriedades/models/endereco-dto';
import { PropriedadeDTO } from 'src/app/propriedades/models/propriedade-dto';
import { EnderecoService } from '../../services/endereco.service';
@Component({
 selector: 'app-endereco-form',
 templateUrl: './endereco-form.component.html',
 styleUrls: ['./endereco-form.component.scss']
})
export class EnderecoFormComponent{
 action = 'Cadastrar';
 endereco: EnderecoDTO = {
 cep:'',
 cidade:'',
 logradouro:'',
 estado: '',
 complemento:'',
 bairro:'',
 numero:0,
 }
 loader = false;
 constructor(private service: EnderecoService) { }
 submit() {
 this.loader = true;
 this.service.update(this.endereco).subscribe(resp => {
 this.loader = false;
 }, err => {
 this.loader = true;
 })
 }
find(id: number) {
 this.loader = true;
 this.service.find(id).subscribe(resp => {
 this.loader = false;
 this.endereco = resp;
 }, err => {
 this.loader = true;
 })
}
update() {
 this.loader = true;
 this.service.update(this.endereco).subscribe(resp => {
 this.loader = false;
 }, err => {
 this.loader = true;
 })
}
delete(id: number) {
 this.loader = true;
 this.service.delete(id).subscribe(resp => {
 this.loader = false;
 }, err => {
 this.loader = true;
 })
}
}
3.2 Services
Proprietario:
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment';
import { UserNewDTO } from '../models/user-new-dto';
@Injectable({
 providedIn: 'root'
})
export class UserService {
 constructor(private http: HttpClient) { }
 insert(user: UserNewDTO){
 return this.http.post<UserNewDTO>(`${environment.api}/proprietarios`, user,
 {
 observe: 'response',
 });
 }
 update(user: UserNewDTO){
 return this.http.put<UserNewDTO>(`${environment.api}/proprietarios`, user,
 {
 observe: 'response',
 });
 }
 find(id: number){
 return this.http.get<UserNewDTO>(`${environment.api}/proprietarios/${id}`);
 }
 delete(id: number){
 return this.http.delete(`${environment.api}/proprietarios/${id}`);
 }
}
Propriedade:
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment';
import { PropriedadeDTO } from '../models/propriedade-dto';
@Injectable({
 providedIn: 'root'
})
export class PropriedadeService {
 constructor(private http: HttpClient) { }
 insert(propriedade: PropriedadeDTO){
 return this.http.post<PropriedadeDTO>(`${environment.api}/propriedades`, propriedade,
 {
 observe: 'response',
 });
 }
 update(propriedade: PropriedadeDTO){
 return this.http.put<PropriedadeDTO>(`${environment.api}/propriedades`, propriedade,
 {
 observe: 'response',
 });
 }
 find(id: number){
 return this.http.get<PropriedadeDTO>(`${environment.api}/propriedades/${id}`)
 }
 delete(id: number){
 return this.http.delete(`${environment.api}/propriedades/${id}`)}
}
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { EnderecoDTO } from 'src/app/propriedades/models/endereco-dto';
import { environment } from 'src/environments/environment';
@Injectable({
 providedIn: 'root'
})
export class EnderecoService {
 constructor(private http: HttpClient) { }
 update(endereco: EnderecoDTO){
 return this.http.put<EnderecoDTO>(`${environment.api}/enderecos`, endereco,
 {
 observe: 'response',
 });
 }
 find(id: number){
 return this.http.get<EnderecoDTO>(`${environment.api}/enderecos/${id}`)
 }
 delete(id: number){
 return this.http.delete(`${environment.api}/enderecos/${id}`)}
}
3.3 Rotas
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { EnderecoFormComponent } from './enderecos/components/endereco-form/endereco-form.component';
import { PropriedadeFormComponent } from './propriedades/components/propriedade-form/propriedade-form.component';
import { UserFormComponent } from './users/components/user-form/user-form.component';
const routes: Routes = [
 {
 path: '',
 component: UserFormComponent
 },
 {
 path: 'propriedades',
 component: PropriedadeFormComponent
 },
 {
 path: 'enderecos',
 component: EnderecoFormComponent
 }
];
@NgModule({
 imports: [RouterModule.forRoot(routes)],
 exports: [RouterModule]
})
export class AppRoutingModule { }
3.4 Estilização (scss)
@import "~flexboxgrid/dist/flexboxgrid.css";
@import "assets/scss/colors.scss";
@import "assets/scss/forms.scss";
@import "assets/scss/sizes.scss";
@import "assets/scss/buttons.scss";
@import "assets/scss/positions.scss";
@import "assets/scss/fonts.scss";
*{
 font-size: 14px;
 padding: 0;
 margin: 0;
 outline: unset;
 font-family: 'roboto-regular';
 background-color: $light-color;
 color: $dark-color;
}
.content {
 position: relative;
 left: 16.5%;
 width: 83.5%;
 min-width: 83.5%;
 max-width: 83.5%;
 height: 100vh;
 overflow: auto;
}
.row{
 margin: 0;
}
.title{
 font-family: 'roboto-light';
 font-size: 30px;
}
 
@import "./colors.scss";
.btn{
 border-radius: 7px;
 border: none;
 height: 40px;
 padding: 0 15px;
 width: fit-content;
 min-width: 100px;
 -moz-transition: all .5s ease-in;
 -o-transition: all .5s ease-in;
 -webkit-transition: all .5s ease-in;
 transition: all .5s ease-in;
 cursor: pointer;
 color: $light-color;
}
.btn-primary{
 background-color: $primary-color;
 &:hover{
 opacity: 0.8;
 }
}
.loading{
 border: none !important;
 background-color: $light-color !important;
 background-image: url('../img/img-loading.gif');
 background-position: center;
 background-size: contain;
 background-repeat: no-repeat;
 content-visibility: hidden;
}
$primary-color: #0071e3;
$light-color: #f5f5f5;
$dark-color: #1f1f1f;
.bg-primary{
 background-color: $primary-color; 
}
.bg-dark{
 background-color: $dark-color;
}
@font-face {
 font-family: 'roboto-light';
 src: url('../fonts/RobotoCondensed-Light-webfont.woff') format('woff');
 font-weight: normal;
 font-style: normal;
}
@font-face {
 font-family: 'roboto-regular';
 src: url('../fonts/Roboto-Regular-webfont.woff')format('woff');
 font-weight: normal;
 font-style:normal;
}
@import "./colors.scss";
.form-control {
 border-radius: 5px;
 border: 1px solid rgba(63, 63, 63, 0.247);
 padding: 10px 10px 6px 10px;
 width: 100%;
 max-width: 100%;
 -webkit-box-sizing: border-box;
 -moz-box-sizing: border-box;
 box-sizing: border-box;
 &:focus{
 border: 1px solid $primary-color; 
 }
}
.form-group {
 .form-control, select {
 margin-top: 5px;
 }
}
4 IMAGENS

Continue navegando