Skip to content

Commit

Permalink
Merge pull request #23 from projeto-final-petshop/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
JulianeMaran32 authored May 29, 2024
2 parents 9728dd3 + 7eb3d99 commit 8a4efb4
Show file tree
Hide file tree
Showing 59 changed files with 1,450 additions and 680 deletions.
4 changes: 3 additions & 1 deletion petconnect/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

## Executando a aplicação

No terminal insira o comando: `mvn spring-boot:run`
* No terminal insira o comando: `mvn spring-boot:run`
* Executar a aplicação pulando os testes: `mvn spring-boot:run -DskipTests`


## Executando a migração do Flyway

Expand Down
2 changes: 1 addition & 1 deletion petconnect/documents/HISTORIA_DE_USUARIO.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Login: email e senha (POST)
* Recuperar senha: envio de email com link para redefinição (POST)
* Detalhes do Usuário (GET)
3. Pet - CUSTOMER OK
3. Pet - USER OK
* Cadastrar Pet (POST)
* Detalhes do Pet (GET)
* Atualizar dados do Pet (PUT)
Expand Down
35 changes: 35 additions & 0 deletions petconnect/documents/dashboard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Dashboard

## Agendamento

* Identificador do serviço/agendamento (ID)
* Tipo de serviço (banho e tosa, consulta veterinária, etc.)
* Data e hora do agendamento
* Cliente (nome, email, telefone, etc.)
* Informações adicionais (como tipo de animal, observações, etc.)

Appointment `/appointments`

- id
- serviceType
- dateTime
- client
- additionalInfo

ja fiz a tela inicial pra criar um novo agendamento também, onde o usuário vai escolher o pet, o serviço, e o horário de inicio do atendimento. apos isso, fiz um calculo automático pro horário de termino

(deixei a consulta de uma hora pra banho, uma hora pra tosa, duas horas pra banho e tosa, e meia hora pro veterinário)

aí o horário de termino é indisponível pra alteração, so mostra a visualização. e vou te mandar isso pra criar um novo agendamento, ou seja:
(token no headers)
-id do pet escolhido
-dia
-serviço
-horário de inicio
-horário de termino


Pet: selecionar o tipo de pet (gato, cachorro, outros)
Serviços: banho, tosa, banho e tosa, consulta veterinária
Horário de início
Horário de término
10 changes: 10 additions & 0 deletions petconnect/petconnect.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="FacetManager">
<facet type="jpa" name="JPA">
<configuration>
<setting name="validation-enabled" value="true" />
<setting name="provider-name" value="Hibernate" />
<datasource-mapping />
<naming-strategy-map />
</configuration>
</facet>
</component>
<component name="SonarLintModuleSettings">
<option name="uniqueId" value="1c5318fe-c622-4859-9e08-c9cf6e49c580" />
</component>
Expand Down
Binary file added petconnect/petconnect.log.2024-05-28.0.gz
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package br.com.finalproject.petconnect.appointment.controllers;

import br.com.finalproject.petconnect.appointment.dto.AppointmentRequest;
import br.com.finalproject.petconnect.appointment.dto.AppointmentResponse;
import br.com.finalproject.petconnect.appointment.services.AppointmentService;
import br.com.finalproject.petconnect.exceptions.runtimes.PetNotFoundException;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/appointments")
@RequiredArgsConstructor
public class AppointmentController {

private final AppointmentService appointmentService;

// TODO: substituir 'null' por mensagens customizadas.

@PostMapping("/schedule")
public ResponseEntity<AppointmentResponse> scheduleAppointment(@RequestBody @Valid AppointmentRequest request,
@RequestHeader(name = HttpHeaders.AUTHORIZATION) String authorizationHeader) {
try {
log.info("Recebida solicitação de agendamento para o pet ID: {}", request.getPetId());
AppointmentResponse response = appointmentService.scheduleAppointment(request, authorizationHeader);
log.info("Agendamento criado com sucesso. Agendamento ID: {}", response.getId());
return ResponseEntity.status(HttpStatus.CREATED).body(response);
} catch (PetNotFoundException e) {
log.error("Erro ao criar agendamento: pet não encontrado. Pet ID: {}", request.getPetId());
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
} catch (Exception e) {
log.error("Erro interno ao criar agendamento", e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}

@PutMapping("/update/{id}")
public ResponseEntity<AppointmentResponse> updateAppointment(@PathVariable(name = "id") Long appointmentId,
@RequestBody @Valid AppointmentRequest request,
@RequestHeader(name = HttpHeaders.AUTHORIZATION) String authorizationHeader) {
try {
log.info("Recebida solicitação de atualização para o agendamento ID: {}", appointmentId);
AppointmentResponse response = appointmentService.updateAppointment(appointmentId, request, authorizationHeader);
log.info("Agendamento atualizado com sucesso. Agendamento ID: {}", response.getId());
return ResponseEntity.ok(response);
} catch (IllegalArgumentException e) {
log.error("Erro ao atualizar agendamento: {}", e.getMessage());
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
} catch (Exception e) {
log.error("Erro interno ao atualizar agendamento", e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}

@DeleteMapping("/cancel/{id}")
public ResponseEntity<String> cancelAppointment(@PathVariable(name = "id") Long appointmentId,
@RequestHeader(name = HttpHeaders.AUTHORIZATION) String authorizationHeader) {
try {
log.info("Recebida solicitação de cancelamento para o agendamento ID: {}", appointmentId);
appointmentService.cancelAppointment(appointmentId, authorizationHeader);
log.info("Agendamento cancelado com sucesso. Agendamento ID: {}", appointmentId);
return ResponseEntity.ok("Agendamento cancelado com sucesso.");
} catch (IllegalArgumentException e) {
log.error("Erro ao cancelar agendamento: {}", e.getMessage());
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Agendamento não encontrado ou não pertence ao usuário."); // Customize response as needed
} catch (Exception e) {
log.error("Erro interno ao cancelar agendamento", e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Erro interno ao cancelar o agendamento."); // Customize response as needed
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package br.com.finalproject.petconnect.appointment.dto;

import br.com.finalproject.petconnect.appointment.entities.PetType;
import br.com.finalproject.petconnect.appointment.entities.ServiceType;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;

import java.time.LocalDate;
import java.time.LocalTime;

@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class AppointmentRequest {

private Long petId;

private ServiceType serviceType;

private PetType petType;

@JsonFormat(pattern = "dd/MM/yyyy")
private LocalDate appointmentDate;

@JsonFormat(pattern = "HH:mm")
private LocalTime appointmentTime;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package br.com.finalproject.petconnect.appointment.dto;

import br.com.finalproject.petconnect.appointment.entities.AppointmentStatus;
import br.com.finalproject.petconnect.appointment.entities.PetType;
import br.com.finalproject.petconnect.appointment.entities.ServiceType;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;

import java.time.LocalDate;
import java.time.LocalTime;

@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class AppointmentResponse {

private Long id;

private Long petId;

private ServiceType serviceType;

private PetType petType;

@JsonFormat(pattern = "dd/MM/yyyy")
private LocalDate appointmentDate;

@JsonFormat(pattern = "HH:mm")
private LocalTime appointmentTime;

private Long userId;

private AppointmentStatus status;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package br.com.finalproject.petconnect.appointment.entities;

import br.com.finalproject.petconnect.pets.entities.Pet;
import br.com.finalproject.petconnect.user.entities.User;
import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.util.Date;

@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "appointments")
@Entity
public class Appointment implements Serializable {

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

@ManyToOne
@JoinColumn(nullable = false)
private Pet pet;

@Enumerated(EnumType.STRING)
private ServiceType serviceType;

@Enumerated(EnumType.STRING)
private PetType petType;

@JsonFormat(pattern = "dd/MM/yyyy")
@Temporal(TemporalType.DATE)
private LocalDate appointmentDate;

@JsonFormat(pattern = "HH:mm")
@Temporal(TemporalType.TIME)
private LocalTime appointmentTime;

@ManyToOne
@JoinColumn(nullable = false)
private User user;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private AppointmentStatus status;

@CreationTimestamp
@Column(updatable = false)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private OffsetDateTime createdAt;

@UpdateTimestamp
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private OffsetDateTime updatedAt;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package br.com.finalproject.petconnect.appointment.entities;

public enum AppointmentStatus {

AGENDADO,
CANCELADO,
CONCLUIDO,
PENDENTE,
CONFIRMADO

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package br.com.finalproject.petconnect.appointment.entities;

public enum PetType {

DOG,
CAT,
OTHER

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package br.com.finalproject.petconnect.appointment.entities;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum ServiceType {

BATH,
GROOMING,
BATH_AND_GROOMING,
VETERINARY_CONSULTATION

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package br.com.finalproject.petconnect.appointment.mapping;

import br.com.finalproject.petconnect.appointment.dto.AppointmentRequest;
import br.com.finalproject.petconnect.appointment.dto.AppointmentResponse;
import br.com.finalproject.petconnect.appointment.entities.Appointment;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper(componentModel = MappingConstants.ComponentModel.SPRING,
unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface AppointmentMapper {

AppointmentMapper INSTANCE = Mappers.getMapper(AppointmentMapper.class);

static AppointmentMapper petMapper() {
return INSTANCE;
}

@Mapping(target = "petType", source = "petType")
@Mapping(target = "serviceType", source = "serviceType")
@Mapping(target = "appointmentTime", dateFormat = "HH:mm")
@Mapping(target = "appointmentDate", dateFormat = "dd/MM/yyyy")
@Mapping(target = "id", ignore = true)
Appointment toEntity(AppointmentRequest appointmentRequest);

@Mapping(target = "status", source = "status")
@Mapping(target = "petType", source = "petType")
@Mapping(target = "serviceType", source = "serviceType")
@Mapping(target = "appointmentTime", dateFormat = "HH:mm")
@Mapping(target = "appointmentDate", dateFormat = "dd/MM/yyyy")
AppointmentResponse toResponse(Appointment appointment);

List<AppointmentResponse> toResponseList(List<Appointment> appointmentList);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package br.com.finalproject.petconnect.appointment.repositories;

import br.com.finalproject.petconnect.appointment.entities.Appointment;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface AppointmentRepository extends JpaRepository<Appointment, Long> {

Optional<Appointment> findByIdAndUserId(Long appointmentId, Long id);

}
Loading

0 comments on commit 8a4efb4

Please sign in to comment.