-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from projeto-final-petshop/develop
Develop
- Loading branch information
Showing
59 changed files
with
1,450 additions
and
680 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
77 changes: 77 additions & 0 deletions
77
...in/java/br/com/finalproject/petconnect/appointment/controllers/AppointmentController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...nect/src/main/java/br/com/finalproject/petconnect/appointment/dto/AppointmentRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...ect/src/main/java/br/com/finalproject/petconnect/appointment/dto/AppointmentResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
...onnect/src/main/java/br/com/finalproject/petconnect/appointment/entities/Appointment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
.../src/main/java/br/com/finalproject/petconnect/appointment/entities/AppointmentStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
petconnect/src/main/java/br/com/finalproject/petconnect/appointment/entities/PetType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...onnect/src/main/java/br/com/finalproject/petconnect/appointment/entities/ServiceType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
...t/src/main/java/br/com/finalproject/petconnect/appointment/mapping/AppointmentMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
...n/java/br/com/finalproject/petconnect/appointment/repositories/AppointmentRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
Oops, something went wrong.