Skip to content

Commit

Permalink
Merge pull request #91 from McGill-ECSE321-Winter2021/dev
Browse files Browse the repository at this point in the history
Dev - Deliverable 3
  • Loading branch information
roeyb1 authored Apr 4, 2021
2 parents 0f4c7f6 + b285056 commit d256238
Show file tree
Hide file tree
Showing 64 changed files with 4,986 additions and 2,317 deletions.
25 changes: 25 additions & 0 deletions SCRS-Backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,28 @@ dependencies {
test {
useJUnitPlatform()
}

task integrationTests(type: Exec) {

dependsOn 'build'

group = "verification"

workingDir './src/test/javascript'

if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows'))
{
// for windows
commandLine 'cmd', '/c', 'node runTests.js'
}
else
{
commandLine 'node runTests.js'
}

standardOutput = new ByteArrayOutputStream();

ext.output = {
return standardOutput.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import ca.mcgill.ecse321.scrs.dao.AssistantRepository;
import ca.mcgill.ecse321.scrs.model.Assistant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -21,11 +21,6 @@ public class ScrsApplication
@Autowired
AssistantRepository assistantRepository;

@PostConstruct
public void init() {
staticAssistantRepository = assistantRepository;
}

public static void main(String[] args)
{
SpringApplication.run(ScrsApplication.class, args);
Expand All @@ -39,4 +34,10 @@ public static void main(String[] args)
}
}

@PostConstruct
public void init()
{
staticAssistantRepository = assistantRepository;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
import org.springframework.web.bind.annotation.*;

import java.sql.Date;
import java.sql.Time;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import static ca.mcgill.ecse321.scrs.controller.Helper.*;
import static ca.mcgill.ecse321.scrs.controller.Helper.convertToDto;

@RestController
@RequestMapping(path = "/api/appointment", produces = MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -36,29 +37,52 @@ public class AppointmentController


@GetMapping(path = {"/getall/{id}", "/getall/{id}/"})
public ResponseEntity<List<AppointmentDto>> getAllAppointments(@PathVariable String id) {
if(id == null)return new ResponseEntity<>(null, HttpStatus.NOT_ACCEPTABLE);
@CrossOrigin(origins = "*")
public ResponseEntity<List<AppointmentDto>> getAllAppointments(@PathVariable String id)
{
if (id == null) return new ResponseEntity<>(null, HttpStatus.NOT_ACCEPTABLE);
int ID = Integer.parseInt(id);

Customer customer = customerService.getCustomerByID(ID);
if(customer == null) return new ResponseEntity<>(null, HttpStatus.NOT_ACCEPTABLE);
if (customer == null) return new ResponseEntity<>(null, HttpStatus.NOT_ACCEPTABLE);

List<Appointment> list = appointmentService.getAppointmentsByCustomer(customer);
List<AppointmentDto> dtoList = new ArrayList<>();

if(list != null){
if (list != null)
{
for (Appointment appointment : list)
{
dtoList.add(convertToDto(appointment));
}
}
return new ResponseEntity<>(dtoList, HttpStatus.OK);

}

@GetMapping(path = {"/getallappointments", "/getallappointments/"})
@CrossOrigin(origins = "*")
public ResponseEntity<List<AppointmentDto>> getAllAppointments()
{
List<Appointment> list = appointmentService.getAllAppointments();
List<AppointmentDto> dtoList = new ArrayList<>();

if (list != null)
{
for (Appointment appointment : list)
{
dtoList.add(convertToDto(appointment));
}
}
return new ResponseEntity<>(dtoList, HttpStatus.OK);

}

@GetMapping(path = {"/getById/{id}", "/getById/{id}/"})
@CrossOrigin(origins = "*")
public ResponseEntity<AppointmentDto> getAppointmentById(@PathVariable String id)
{
if(id == null) return new ResponseEntity<>(null, HttpStatus.NOT_ACCEPTABLE);
if (id == null) return new ResponseEntity<>(null, HttpStatus.NOT_ACCEPTABLE);

Appointment appointment = appointmentService.getAppointmentById(Integer.parseInt(id));

Expand All @@ -71,16 +95,19 @@ public ResponseEntity<AppointmentDto> getAppointmentById(@PathVariable String id
}

@GetMapping(path = {"/notifications/{id}", "/notifications/{id}/"})
public ResponseEntity<List<AppointmentDto>> notifications(@PathVariable String id) {
if(id == null)return new ResponseEntity<>(null, HttpStatus.NOT_ACCEPTABLE);
@CrossOrigin(origins = "*")
public ResponseEntity<List<AppointmentDto>> notifications(@PathVariable String id)
{
if (id == null) return new ResponseEntity<>(null, HttpStatus.NOT_ACCEPTABLE);
int ID = Integer.parseInt(id);

Customer customer = customerService.getCustomerByID(ID);
if(customer == null) return new ResponseEntity<>(null, HttpStatus.NOT_ACCEPTABLE);
if (customer == null) return new ResponseEntity<>(null, HttpStatus.NOT_ACCEPTABLE);

List<Appointment> list = appointmentService.getAppointmentsByCustomer(customer);

if(list != null){
if (list != null)
{
//finding the same date next week
Date now = new Date(LocalDate.now().toEpochDay());
Calendar calendar = Calendar.getInstance();
Expand Down Expand Up @@ -108,17 +135,19 @@ public ResponseEntity<List<AppointmentDto>> notifications(@PathVariable String i
}

return new ResponseEntity<>(notificationList, HttpStatus.OK);
}else return new ResponseEntity<>(null, HttpStatus.OK);
} else return new ResponseEntity<>(null, HttpStatus.OK);
}

@PostMapping(value = {"/book", "/book/"})
@CrossOrigin(origins = "*")
public ResponseEntity<AppointmentDto> bookAppointment(@RequestBody AppointmentDto appointmentDto)
{
if (appointmentDto == null)
{
return new ResponseEntity<>(null, HttpStatus.EXPECTATION_FAILED);
}
try {
try
{
List<Timeslot> timeslots = timeslotService.getTimeslotsById(appointmentDto.getTimeslotsId());
if (timeslots == null)
{
Expand All @@ -129,37 +158,43 @@ public ResponseEntity<AppointmentDto> bookAppointment(@RequestBody AppointmentDt
appointmentDto.getService(), appointmentDto.getNote(), appointmentDto.getPaymentStatus(),
customer, timeslots.toArray(new Timeslot[0]));
return new ResponseEntity<>(convertToDto(appointment), HttpStatus.OK);
} catch (Exception e) {
} catch (Exception e)
{
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}

@PutMapping(value = {"/pay", "/pay/"})
@CrossOrigin(origins = "*")
public ResponseEntity<AppointmentDto> payAppointment(@RequestParam(name = "appointmentId") int appointmentId)
{
try
{
Appointment appointment = appointmentService.getAppointmentById(appointmentId);
if (appointment == null) {
if (appointment == null)
{
return new ResponseEntity<>(null, HttpStatus.EXPECTATION_FAILED);
}
appointment.setPaid(true);
appointment = appointmentService.modifyAppointment(convertToDto(appointment));
return new ResponseEntity<>(convertToDto(appointment), HttpStatus.OK);
} catch (Exception e) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
} catch (Exception e)
{
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}

@PutMapping(value = {"/rate", "/rate/"})
@CrossOrigin(origins = "*")
public ResponseEntity<AppointmentDto> rateAppointment(@RequestParam(name = "appointmentId") int appointmentId, @RequestParam(name = "rating") int rating)
{
if (rating > 10 || rating < 0)
{
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}

try {
try
{
Appointment appointment = appointmentService.rateAppointment(appointmentId, rating);
return new ResponseEntity<>(convertToDto(appointment), HttpStatus.OK);
} catch (Exception e)
Expand All @@ -169,18 +204,76 @@ public ResponseEntity<AppointmentDto> rateAppointment(@RequestParam(name = "appo
}

@PutMapping(value = {"/modifyAppointment", "/modifyAppointment/"})
@CrossOrigin(origins = "*")
public ResponseEntity<AppointmentDto> modifyAppointment(@RequestBody AppointmentDto appointmentDto)
{
if (appointmentDto == null)
{
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
try {
try
{
Appointment modifiedAppt = appointmentService.modifyAppointment(appointmentDto);
return new ResponseEntity<>(convertToDto(modifiedAppt), HttpStatus.OK);
} catch (Exception e)
{
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}

@GetMapping(value = {"/getStartAndEnd/{id}", "/getStartAndEnd/{id}/"})
@CrossOrigin(origins = "*")
public ResponseEntity<TimeslotDto> getAppointmentStartAndEnd(@PathVariable("id") int appointmentId)
{
try
{
Appointment appointment = appointmentService.getAppointmentById(appointmentId);

if (appointment == null)
{
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
ArrayList<Timeslot> timeslots = new ArrayList<>(appointmentService.getAppointmentById(appointmentId).getTimeslots());

if (timeslots.size() == 0)
{
return new ResponseEntity(null, HttpStatus.INTERNAL_SERVER_ERROR);
}

Date minD = timeslots.get(0).getStartDate();
Date maxD = timeslots.get(0).getEndDate();

Time minT = timeslots.get(0).getStartTime();
Time maxT = timeslots.get(0).getEndTime();

for (Timeslot t : timeslots)
{
if (t.getEndDate().after(maxD))
{
maxD = t.getEndDate();
maxT = t.getEndTime();

} else if (t.getEndDate().equals(maxD))
{
if (t.getEndTime().after(maxT)) maxT = t.getEndTime();
} else if (t.getStartDate().before(minD))
{
minD = t.getStartDate();
minT = t.getStartTime();
} else if (t.getStartDate().equals(minD))
{
if (t.getStartTime().before(minT)) minT = t.getStartTime();
}
}
TimeslotDto output = new TimeslotDto(-1, minD, maxD, minT, maxT, -1);

return new ResponseEntity<>(output, HttpStatus.OK);

} catch (Exception e)
{
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import static ca.mcgill.ecse321.scrs.controller.Helper.*;
import static ca.mcgill.ecse321.scrs.controller.Helper.convertToDto;
import static ca.mcgill.ecse321.scrs.controller.Helper.hash;

@RestController
@RequestMapping(path = "/api/assistant")
Expand Down Expand Up @@ -40,26 +41,13 @@ public ResponseEntity<AssistantDto> createAssistant(@RequestBody Assistant assis

@PutMapping(value = {"/update", "/update/"})
@CrossOrigin(origins = "*")
public ResponseEntity<AssistantDto> updateAssistant(@RequestBody Assistant assistant, @CookieValue(value = "id", defaultValue = "-1") String ID)
public ResponseEntity<AssistantDto> updateAssistant(@RequestBody Assistant assistant)
{
int id = Integer.parseInt(ID);
if (id == -1)
{
// TODO handle no login error with cookies (uncomment next line)
//return new ResponseEntity<AssistantDto>(new AssistantDto(), HttpStatus.UNAUTHORIZED);
// Please login to modify an assistant account.
}
if (assistant == null)
{
return new ResponseEntity<AssistantDto>(new AssistantDto(), HttpStatus.EXPECTATION_FAILED);
// Invalid assistant
}
if (!isAdmin(scrsUserService.getSCRSUserByID(id))) //does not have permission to edit.
{
// TODO handle bad login error with cookies (uncomment next line)
//return new ResponseEntity<AssistantDto>(new AssistantDto(), HttpStatus.UNAUTHORIZED);
// You do not have permission to edit an admin account.
}
if (assistantService.getAssistantByID(assistant.getScrsUserId()) == null)
{
return new ResponseEntity<AssistantDto>(new AssistantDto(), HttpStatus.NOT_ACCEPTABLE);
Expand All @@ -76,28 +64,15 @@ public ResponseEntity<AssistantDto> updateAssistant(@RequestBody Assistant assis

@DeleteMapping(value = {"/delete/{id}", "/delete/{id}/"})
@CrossOrigin(origins = "*")
public ResponseEntity<AssistantDto> deleteAssistant(@PathVariable String id, @CookieValue(value = "id", defaultValue = "-1") String ID)
public ResponseEntity<AssistantDto> deleteAssistant(@PathVariable String id)
{
int assistantID = Integer.parseInt(id);
int idCookie = Integer.parseInt(ID);
if (idCookie == -1)
{
// TODO handle no login error with cookies (uncomment next line)
//return new ResponseEntity<AssistantDto>(new AssistantDto(), HttpStatus.UNAUTHORIZED);
//Please login to delete an assistant account.
}
Assistant assistant = assistantService.getAssistantByID(assistantID);
if (assistant == null)
{
return new ResponseEntity<AssistantDto>(new AssistantDto(), HttpStatus.NOT_ACCEPTABLE);
// Invalid assistant. Please submit a valid assistant account to be deleted.
}
if (!isAdmin(scrsUserService.getSCRSUserByID(idCookie))) //does not have permission to edit.
{
// TODO handle bad login error with cookies (uncomment next line)
//return new ResponseEntity<AssistantDto>(new AssistantDto(), HttpStatus.UNAUTHORIZED);
// You do not have permission to edit this account.
}
return new ResponseEntity<>(convertToDto(assistantService.deleteAssistant(assistant)), HttpStatus.OK);
}

Expand Down

This file was deleted.

Loading

0 comments on commit d256238

Please sign in to comment.