Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ipk 237 appointment queries #60

Merged
merged 4 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
1 change: 1 addition & 0 deletions src/main/java/com/MeetMate/appointment/Appointment.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.MeetMate.enums.AppointmentStatus;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import java.time.LocalDateTime;
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/MeetMate/appointment/AppointmentConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//package com.MeetMate.appointment;
//
//import com.MeetMate.company.CompanyRepository;
//import org.springframework.boot.CommandLineRunner;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//@Configuration
//public class AppointmentConfig {
//
// @Bean
// public CommandLineRunner run(AppointmentRepository appointmentRepository) throws Exception {
// System.out.println("Yeehaaaa");
// return args -> {
// Appointment appointment = new Appointment();
// appointment.setId(1L);
// appointment.setCompanyID(1L);
//
// appointmentRepository.save(appointment);
// };
// }
//
//
//}
59 changes: 31 additions & 28 deletions src/main/java/com/MeetMate/appointment/AppointmentController.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
//package com.MeetMate.appointment;
package com.MeetMate.appointment;

import lombok.RequiredArgsConstructor;
import org.springframework.graphql.data.method.annotation.Argument;
import org.springframework.graphql.data.method.annotation.QueryMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping(path = "api/appointment")
@RequiredArgsConstructor
public class AppointmentController {
private final AppointmentService appointmentService;

@QueryMapping
public Appointment getAppointment(@Argument long id) {
try {
return appointmentService.getAppointment(id);

} catch (Throwable t) {
Class<? extends Throwable> tc = t.getClass();
return null;
// if (tc == EntityNotFoundException.class)
// return ResponseEntity.status(HttpStatus.NOT_FOUND).body("message: " + t.getMessage());
//
//import com.MeetMate.company.Company;
//import lombok.RequiredArgsConstructor;
//import org.springframework.graphql.data.method.annotation.Argument;
//import org.springframework.graphql.data.method.annotation.QueryMapping;
// if (tc == IllegalArgumentException.class)
// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("message: " + t.getMessage());
//
//@RequiredArgsConstructor
//public class AppointmentController {
// private final AppointmentService appointmentService;
//
// @QueryMapping
// public Company getAppointment(@Argument long id) {
// try {
// return appointmentService.getAppointment(id);
//
// } catch (Throwable t) {
// Class<? extends Throwable> tc = t.getClass();
// return null;
//// if (tc == EntityNotFoundException.class)
//// return ResponseEntity.status(HttpStatus.NOT_FOUND).body("message: " + t.getMessage());
////
//// if (tc == IllegalArgumentException.class)
//// return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("message: " + t.getMessage());
////
//// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("message: " + t.getMessage());
// }
// }
//
//}
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("message: " + t.getMessage());
}
}

}
24 changes: 12 additions & 12 deletions src/main/java/com/MeetMate/appointment/AppointmentRepository.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//package com.MeetMate.appointment;
//
//import org.springframework.data.mongodb.repository.MongoRepository;
//import org.springframework.stereotype.Repository;
//
//import java.util.Optional;
//
//@Repository
//public interface AppointmentRepository extends MongoRepository<Appointment, Long> {
//
//
//}
package com.MeetMate.appointment;

import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface AppointmentRepository extends MongoRepository<Appointment, Long> {

Optional<Appointment> findAppointmentById(long id);
}
21 changes: 17 additions & 4 deletions src/main/java/com/MeetMate/appointment/AppointmentService.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
//package com.MeetMate.appointment;
//
//public class AppointmentService {
//}
package com.MeetMate.appointment;

import jakarta.persistence.EntityNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class AppointmentService {

private final AppointmentRepository appointmentRepository;

public Appointment getAppointment(long id) {
return appointmentRepository.findAppointmentById(id)
.orElseThrow(() -> new EntityNotFoundException("Appointment not found"));
}
}
1 change: 1 addition & 0 deletions src/main/resources/graphql/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type Query {
getCompany(id: ID!): Company

#Appointment Queries
getAppointment(id: ID!): Appointment
}

type Mutation {
Expand Down
Loading