diff --git a/.gitignore b/.gitignore index 4b2dc5ec7..5720d6940 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ IndividualMiniprojectC++/.vscode/ -IndividualMiniprojectC++/external_libraries/boost_1_85_0 +IndividualMiniprojectC++/external_libraries/boost_1_86_0 IndividualMiniprojectC++/external_libraries/Crow-1.2.0-Darwin IndividualMiniprojectC++/build/* !IndividualMiniprojectC++/build/README.txt -!IndividualMiniprojectC++/external_libraries/README.txt \ No newline at end of file +!IndividualMiniprojectC++/external_libraries/README.txt +*.swp diff --git a/IndividualMiniprojectC++/CMakeLists.txt b/IndividualMiniprojectC++/CMakeLists.txt index ed2cd10fe..59801f347 100644 --- a/IndividualMiniprojectC++/CMakeLists.txt +++ b/IndividualMiniprojectC++/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.15) project(IndividualMiniproject) -set(INCLUDE_PATHS external_libraries/boost_1_85_0 external_libraries/Crow-1.2.0-Darwin/include) +set(INCLUDE_PATHS external_libraries/boost_1_86_0 external_libraries/Crow-1.2.0-Darwin/include) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -30,7 +30,7 @@ FetchContent_MakeAvailable(googletest) target_include_directories(IndividualMiniproject PUBLIC ${INCLUDE_PATHS} include - /opt/homebrew/Cellar/asio/1.30.2/include +# /opt/homebrew/Cellar/asio/1.30.2/include ) target_link_libraries(IndividualMiniproject PRIVATE @@ -44,15 +44,19 @@ enable_testing() add_executable(IndividualMiniprojectTests test/sample.cpp test/CourseUnitTests.cpp + test/DepartmentUnitTests.cpp + test/RouteControllerUnitTests.cpp src/Course.cpp src/Department.cpp src/MyFileDatabase.cpp + src/RouteController.cpp + src/MyApp.cpp ) target_include_directories(IndividualMiniprojectTests PRIVATE ${INCLUDE_PATHS} include - /opt/homebrew/Cellar/asio/1.30.2/include +# /opt/homebrew/Cellar/asio/1.30.2/include ) target_link_libraries(IndividualMiniprojectTests PRIVATE @@ -78,6 +82,8 @@ if (CPPLINT) src/Globals.cpp test/sample.cpp test/CourseUnitTests.cpp + test/DepartmentUnitTests.cpp + test/RouteControllerUnitTests.cpp ) # Custom target to run cpplint @@ -90,3 +96,55 @@ if (CPPLINT) else() message(WARNING "cpplint not found! Skipping style checks.") endif() + +if (ENABLE_COVERAGE) + # set comiler flags + set(CMAKE_CXX_FLAGS "-O0 -coverage") + + # find required tools + find_program(LCOV lcov REQUIRED) + find_program(GENHTML genhtml REQUIRED) + + # add coverage target + add_custom_target( + coverage + # gather data + COMMAND ${LCOV} --directory . --capture --output-file coverage.info + # exclude header files + COMMAND ${LCOV} --remove coverage.info '/usr/*' '*.h' '*main.cpp' '*test*' --output-file coverage.info + COMMAND ${LCOV} --remove coverage.info '*MyApp.cpp' --output-file coverage.info + # generate report + COMMAND ${GENHTML} --demangle-cpp -o coverage coverage.info + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) +endif() + +add_executable(CodeCoverage + test/sample.cpp + test/CourseUnitTests.cpp + test/DepartmentUnitTests.cpp + test/MyFileDatabaseUnitTests.cpp + test/RouteControllerUnitTests.cpp + src/Course.cpp + src/Department.cpp + src/MyFileDatabase.cpp + src/RouteController.cpp + src/MyApp.cpp +) + +target_include_directories(CodeCoverage PRIVATE + ${INCLUDE_PATHS} + include +) + +target_link_libraries(CodeCoverage PRIVATE + gtest + gtest_main +) + +find_program(CPPCHECK cppcheck) +add_custom_target( + cppcheck + #COMMAND ${CPPCHECK} -I ../include/ --enable=all --inconclusive --library=posix --suppress=missingInclude --suppress=missingIncludeSystem --suppress=checkersReport --suppress=unusedFunction ../src/ ../test/ + COMMAND ${CPPCHECK} -I ../include/ --enable=all --library=posix --suppress=missingInclude --suppress=missingIncludeSystem --suppress=checkersReport --suppress=unusedFunction ../src/ ../test/ +) diff --git a/IndividualMiniprojectC++/build/README.txt b/IndividualMiniprojectC++/build/README.txt index 5341f97eb..3887196c0 100644 --- a/IndividualMiniprojectC++/build/README.txt +++ b/IndividualMiniprojectC++/build/README.txt @@ -5,3 +5,20 @@ make make cpplint -for style checking If you ever need to clean up some files make clean is always an option + +CODE COVERAGE with LCOV: + The code coverage library requires lcov and genhtml. + + Do these in the build directory: + + cmake -DENABLE_COVERAGE=true .. && make + ./CodeCoverage; make coverage + + The first command builds the targets and executables, + the second one generates the report in build/coverage/index.html + that can be viewed in a browser. + + +STATIC CODE ANALYSIS + Run the following command after running cmake to run static code analysis: + make cppcheck diff --git a/IndividualMiniprojectC++/include/Course.h b/IndividualMiniprojectC++/include/Course.h index 7900730d1..63f83ed48 100644 --- a/IndividualMiniprojectC++/include/Course.h +++ b/IndividualMiniprojectC++/include/Course.h @@ -11,7 +11,7 @@ class Course { std::string courseTimeSlot; public: - Course(int count, const std::string &instructorName, const std::string &courseLocation, const std::string &timeSlot); + Course(int capacity, const std::string &instructorName, const std::string &courseLocation, const std::string &timeSlot); Course(); std::string getCourseLocation() const; diff --git a/IndividualMiniprojectC++/include/Department.h b/IndividualMiniprojectC++/include/Department.h index 4a5fd699a..40567b465 100644 --- a/IndividualMiniprojectC++/include/Department.h +++ b/IndividualMiniprojectC++/include/Department.h @@ -10,7 +10,7 @@ class Department { public: - Department(std::string deptCode, std::map> courses, + Department(std::string deptCode, const std::map>& courses, std::string departmentChair, int numberOfMajors); Department(); @@ -20,8 +20,8 @@ class Department { void deserialize(std::istream& in); void addPersonToMajor(); void dropPersonFromMajor(); - void addCourse(std::string courseId, std::shared_ptr course); - void createCourse(std::string courseId, std::string instructorName, std::string courseLocation, + void addCourse(const std::string& courseId, std::shared_ptr course); + void createCourse(const std::string& courseId, std::string instructorName, std::string courseLocation, std::string courseTimeSlot, int capacity); std::string display() const; std::string getDepartmentChair() const; diff --git a/IndividualMiniprojectC++/include/RouteController.h b/IndividualMiniprojectC++/include/RouteController.h index f4acd96d8..3f889f8a7 100644 --- a/IndividualMiniprojectC++/include/RouteController.h +++ b/IndividualMiniprojectC++/include/RouteController.h @@ -10,6 +10,7 @@ class RouteController { MyFileDatabase* myFileDatabase; public: + RouteController(); void initRoutes(crow::App<>& app); void setDatabase(MyFileDatabase* db); diff --git a/IndividualMiniprojectC++/src/Course.cpp b/IndividualMiniprojectC++/src/Course.cpp index d2eb5aa12..6d11b81c2 100644 --- a/IndividualMiniprojectC++/src/Course.cpp +++ b/IndividualMiniprojectC++/src/Course.cpp @@ -1,8 +1,8 @@ +// Copyright 2024 Richard Cruz-Silva #include "Course.h" #include #include - /** * Constructs a new Course object with the given parameters. Initial count starts at 0. * @@ -11,14 +11,19 @@ * @param timeSlot The time slot of the course. * @param capacity The maximum number of students that can enroll in the course. */ -Course::Course(int capacity, const std::string& instructorName, const std::string& courseLocation, const std::string& timeSlot) - : enrollmentCapacity(capacity), enrolledStudentCount(500), courseLocation(courseLocation), instructorName(instructorName), courseTimeSlot(timeSlot) {} +Course::Course(int capacity, const std::string& instructorName, + const std::string& courseLocation, const std::string& timeSlot) + : enrollmentCapacity(capacity), enrolledStudentCount(500), + courseLocation(courseLocation), instructorName(instructorName), + courseTimeSlot(timeSlot) {} /** * Constructs a default Course object with the default parameters. * */ -Course::Course() : enrollmentCapacity(0), enrolledStudentCount(0), courseLocation(""), instructorName(""), courseTimeSlot("") {} +Course::Course() : enrollmentCapacity(0), enrolledStudentCount(0), + courseLocation(""), instructorName(""), + courseTimeSlot("") {} /** @@ -27,8 +32,11 @@ Course::Course() : enrollmentCapacity(0), enrolledStudentCount(0), courseLocatio * @return true if the student is successfully enrolled, false otherwise. */ bool Course::enrollStudent() { + if (enrolledStudentCount < enrollmentCapacity) { enrolledStudentCount++; - return false; + return true; + } + return false; } /** @@ -37,81 +45,97 @@ bool Course::enrollStudent() { * @return true if the student is successfully dropped, false otherwise. */ bool Course::dropStudent() { + if (enrolledStudentCount > 0) { enrolledStudentCount--; - return false; + return true; + } + return false; } std::string Course::getCourseLocation() const { - return courseLocation; + return courseLocation; } std::string Course::getInstructorName() const { - return courseTimeSlot; + return instructorName; } std::string Course::getCourseTimeSlot() const { - return instructorName; + return courseTimeSlot; } std::string Course::display() const { - return "\nInstructor: " + instructorName + "; Location: " + courseLocation + "; Time: " + courseTimeSlot; + return "\nInstructor: " + instructorName + "; Location: " + + courseLocation + "; Time: " + courseTimeSlot; } void Course::reassignInstructor(const std::string& newInstructorName) { - std::cout << "Old Instructor: " << instructorName << std::endl; - this->instructorName = newInstructorName; // Ensure the class member is being updated - std::cout << "New Instructor: " << this->instructorName << std::endl; + //std::cout << "Old Instructor: " << instructorName << std::endl; + // Ensure the class member is being updated + if (!newInstructorName.empty()) + this->instructorName = newInstructorName; + //std::cout << "New Instructor: " << this->instructorName << std::endl; } void Course::reassignLocation(const std::string& newLocation) { + if (!newLocation.empty()) courseLocation = newLocation; } void Course::reassignTime(const std::string& newTime) { + if (!newTime.empty()) courseTimeSlot = newTime; } void Course::setEnrolledStudentCount(int count) { + if (0 <= count) enrolledStudentCount = count; } bool Course::isCourseFull() const { - return enrollmentCapacity > enrolledStudentCount; + return enrollmentCapacity <= enrolledStudentCount; } void Course::serialize(std::ostream& out) const { - out.write(reinterpret_cast(&enrollmentCapacity), sizeof(enrollmentCapacity)); - out.write(reinterpret_cast(&enrolledStudentCount), sizeof(enrolledStudentCount)); - - size_t locationLen = courseLocation.length(); - out.write(reinterpret_cast(&locationLen), sizeof(locationLen)); - out.write(courseLocation.c_str(), locationLen); - - size_t instructorLen = instructorName.length(); - out.write(reinterpret_cast(&instructorLen), sizeof(instructorLen)); - out.write(instructorName.c_str(), instructorLen); - - size_t timeSlotLen = courseTimeSlot.length(); - out.write(reinterpret_cast(&timeSlotLen), sizeof(timeSlotLen)); - out.write(courseTimeSlot.c_str(), timeSlotLen); + out.write(reinterpret_cast(&enrollmentCapacity), + sizeof(enrollmentCapacity)); + out.write(reinterpret_cast(&enrolledStudentCount), + sizeof(enrolledStudentCount)); + + size_t locationLen = courseLocation.length(); + out.write(reinterpret_cast(&locationLen), + sizeof(locationLen)); + out.write(courseLocation.c_str(), locationLen); + + size_t instructorLen = instructorName.length(); + out.write(reinterpret_cast(&instructorLen), + sizeof(instructorLen)); + out.write(instructorName.c_str(), instructorLen); + + size_t timeSlotLen = courseTimeSlot.length(); + out.write(reinterpret_cast(&timeSlotLen), + sizeof(timeSlotLen)); + out.write(courseTimeSlot.c_str(), timeSlotLen); } void Course::deserialize(std::istream& in) { - in.read(reinterpret_cast(&enrollmentCapacity), sizeof(enrollmentCapacity)); - in.read(reinterpret_cast(&enrolledStudentCount), sizeof(enrolledStudentCount)); - - size_t locationLen; - in.read(reinterpret_cast(&locationLen), sizeof(locationLen)); - courseLocation.resize(locationLen); - in.read(&courseLocation[0], locationLen); - - size_t instructorLen; - in.read(reinterpret_cast(&instructorLen), sizeof(instructorLen)); - instructorName.resize(instructorLen); - in.read(&instructorName[0], instructorLen); - - size_t timeSlotLen; - in.read(reinterpret_cast(&timeSlotLen), sizeof(timeSlotLen)); - courseTimeSlot.resize(timeSlotLen); - in.read(&courseTimeSlot[0], timeSlotLen); + in.read(reinterpret_cast(&enrollmentCapacity), + sizeof(enrollmentCapacity)); + in.read(reinterpret_cast(&enrolledStudentCount), + sizeof(enrolledStudentCount)); + + size_t locationLen; + in.read(reinterpret_cast(&locationLen), sizeof(locationLen)); + courseLocation.resize(locationLen); + in.read(&courseLocation[0], locationLen); + + size_t instructorLen; + in.read(reinterpret_cast(&instructorLen), sizeof(instructorLen)); + instructorName.resize(instructorLen); + in.read(&instructorName[0], instructorLen); + + size_t timeSlotLen; + in.read(reinterpret_cast(&timeSlotLen), sizeof(timeSlotLen)); + courseTimeSlot.resize(timeSlotLen); + in.read(&courseTimeSlot[0], timeSlotLen); } diff --git a/IndividualMiniprojectC++/src/Department.cpp b/IndividualMiniprojectC++/src/Department.cpp index f4aa51860..db55384f1 100644 --- a/IndividualMiniprojectC++/src/Department.cpp +++ b/IndividualMiniprojectC++/src/Department.cpp @@ -1,3 +1,4 @@ +// Copyright 2024 Richard Cruz-Silva #include "Department.h" #include "Course.h" #include @@ -14,9 +15,11 @@ * @param departmentChair The name of the department chair. * @param numberOfMajors The number of majors in the department. */ -Department::Department(std::string deptCode, std::map> courses, +Department::Department(std::string deptCode, const std::map>& courses, std::string departmentChair, int numberOfMajors) - : departmentChair(departmentChair), deptCode(deptCode), numberOfMajors(numberOfMajors), courses(courses) {} + : numberOfMajors(numberOfMajors), deptCode(deptCode), + departmentChair(departmentChair), courses(courses) {} Department::Department() : numberOfMajors(0) {} @@ -26,7 +29,7 @@ Department::Department() : numberOfMajors(0) {} * @return The number of majors. */ int Department::getNumberOfMajors() const { - return numberOfMajors; + return numberOfMajors; } /** @@ -35,7 +38,7 @@ int Department::getNumberOfMajors() const { * @return The name of the department chair. */ std::string Department::getDepartmentChair() const { - return "departmentChair"; + return departmentChair; } /** @@ -43,22 +46,23 @@ std::string Department::getDepartmentChair() const { * * @return A HashMap containing courses offered by the department. */ -std::map> Department::getCourseSelection() const { - return courses; +std::map> +Department::getCourseSelection() const { + return courses; } /** * Increases the number of majors in the department by one. */ void Department::addPersonToMajor() { - numberOfMajors++; + numberOfMajors++; } /** * Decreases the number of majors in the department by one if it's greater than zero. */ void Department::dropPersonFromMajor() { - numberOfMajors--; + numberOfMajors--; } /** @@ -67,7 +71,9 @@ void Department::dropPersonFromMajor() { * @param courseId The ID of the course to add. * @param course The Course object to add. */ -void Department::addCourse(std::string courseId, std::shared_ptr course) { +void Department::addCourse(const std::string& courseId, + std::shared_ptr course) { + if (!courseId.empty()) courses[courseId] = course; } @@ -80,10 +86,14 @@ void Department::addCourse(std::string courseId, std::shared_ptr course) * @param courseTimeSlot The time slot of the course. * @param capacity The maximum number of students that can enroll in the course. */ -void Department::createCourse(std::string courseId, std::string instructorName, std::string courseLocation, +void Department::createCourse(const std::string& courseId, std::string instructorName, + std::string courseLocation, std::string courseTimeSlot, int capacity) { - std::shared_ptr newCourse = std::make_shared(capacity, instructorName, courseLocation, courseTimeSlot); - addCourse(courseId, newCourse); + std::shared_ptr newCourse = std::make_shared(capacity, + instructorName, + courseLocation, + courseTimeSlot); + addCourse(courseId, newCourse); } /** @@ -92,11 +102,12 @@ void Department::createCourse(std::string courseId, std::string instructorName, * @return A string representing the department. */ std::string Department::display() const { - std::ostringstream result; - for (const auto& it : courses) { - result << deptCode << " " << it.first << ": " << it.second->display() << "\n"; - } - return result.str(); + std::ostringstream result; + for (const auto& it : courses) { + result << deptCode << " " << it.first << ": " + << it.second->display() << "\n"; + } + return result.str(); } void Department::serialize(std::ostream& out) const { @@ -108,13 +119,15 @@ void Department::serialize(std::ostream& out) const { out.write(reinterpret_cast(&chairLen), sizeof(chairLen)); out.write(departmentChair.c_str(), chairLen); - out.write(reinterpret_cast(&numberOfMajors), sizeof(numberOfMajors)); + out.write(reinterpret_cast(&numberOfMajors), + sizeof(numberOfMajors)); size_t mapSize = courses.size(); out.write(reinterpret_cast(&mapSize), sizeof(mapSize)); for (const auto& it : courses) { size_t courseIdLen = it.first.length(); - out.write(reinterpret_cast(&courseIdLen), sizeof(courseIdLen)); + out.write(reinterpret_cast(&courseIdLen), + sizeof(courseIdLen)); out.write(it.first.c_str(), courseIdLen); it.second->serialize(out); } diff --git a/IndividualMiniprojectC++/src/Globals.cpp b/IndividualMiniprojectC++/src/Globals.cpp index ebf157ff8..9c2aa35ab 100644 --- a/IndividualMiniprojectC++/src/Globals.cpp +++ b/IndividualMiniprojectC++/src/Globals.cpp @@ -1,3 +1,4 @@ +// Copyright 2024 Richard Cruz-Silva #include "Globals.h" -MyFileDatabase* globalDatabase = nullptr; \ No newline at end of file +MyFileDatabase* globalDatabase = nullptr; diff --git a/IndividualMiniprojectC++/src/MyApp.cpp b/IndividualMiniprojectC++/src/MyApp.cpp index a815436d2..8b94f5113 100644 --- a/IndividualMiniprojectC++/src/MyApp.cpp +++ b/IndividualMiniprojectC++/src/MyApp.cpp @@ -1,3 +1,4 @@ +// Copyright 2024 Richard Cruz-Silva #include "MyApp.h" #include @@ -5,195 +6,234 @@ MyFileDatabase* MyApp::myFileDatabase = nullptr; bool MyApp::saveData = false; void MyApp::run(const std::string& mode) { - saveData = true; - if (mode == "setup") { - setupDatabase(); - std::cout << "System Setup" << std::endl; - return; - } - myFileDatabase = new MyFileDatabase(0, "testfile.bin"); - std::cout << "Start up" << std::endl; + saveData = true; + if (mode == "setup") { + setupDatabase(); + std::cout << "System Setup" << std::endl; + return; + } + myFileDatabase = new MyFileDatabase(0, "testfile.bin"); + std::cout << "Start up" << std::endl; } void MyApp::onTermination() { - std::cout << "Termination" << std::endl; - if (saveData && myFileDatabase) { - myFileDatabase->saveContentsToFile(); - } - delete myFileDatabase; - myFileDatabase = nullptr; + std::cout << "Termination" << std::endl; + if (saveData && myFileDatabase) { + myFileDatabase->saveContentsToFile(); + } + delete myFileDatabase; + myFileDatabase = nullptr; } void MyApp::overrideDatabase(MyFileDatabase* testData) { - delete myFileDatabase; - myFileDatabase = testData; - saveData = false; + delete myFileDatabase; + myFileDatabase = testData; + saveData = false; } MyFileDatabase *MyApp::getDatabase() { - return myFileDatabase; + return myFileDatabase; } void MyApp::setupDatabase() { - myFileDatabase = new MyFileDatabase(1, "testfile.bin"); - resetDataFile(); + myFileDatabase = new MyFileDatabase(1, "testfile.bin"); + resetDataFile(); } void MyApp::resetDataFile() { - std::string times[] = {"11:40-12:55", "4:10-5:25", "10:10-11:25", "2:40-3:55"}; - std::string locations[] = {"417 IAB", "309 HAV", "301 URIS"}; - - // Data for COMS department - auto coms1004 = std::make_shared(400, "Adam Cannon", locations[0], times[0]); - coms1004->setEnrolledStudentCount(249); - auto coms3134 = std::make_shared(250, "Brian Borowski", locations[2], times[1]); - coms3134->setEnrolledStudentCount(242); - auto coms3157 = std::make_shared(400, "Jae Lee", locations[0], times[1]); - coms3157->setEnrolledStudentCount(311); - auto coms3203 = std::make_shared(250, "Ansaf Salleb-Aouissi", locations[2], times[2]); - coms3203->setEnrolledStudentCount(215); - auto coms3261 = std::make_shared(150, "Josh Alman", locations[0], times[3]); - coms3261->setEnrolledStudentCount(140); - auto coms3251 = std::make_shared(125, "Tony Dear", "402 CHANDLER", "1:10-3:40"); - coms3251->setEnrolledStudentCount(99); - auto coms3827 = std::make_shared(300, "Daniel Rubenstein", "207 Math", times[2]); - coms3827->setEnrolledStudentCount(283); - auto coms4156 = std::make_shared(120, "Gail Kaiser", "501 NWC", times[2]); - coms4156->setEnrolledStudentCount(109); - - std::map> courses; - courses["1004"] = coms1004; - courses["3134"] = coms3134; - courses["3157"] = coms3157; - courses["3203"] = coms3203; - courses["3261"] = coms3261; - courses["3251"] = coms3251; - courses["3827"] = coms3827; - courses["4156"] = coms4156; - - Department coms("COMS", courses, "Luca Carloni", 2700); - - // Data for ECON department - auto econ1105 = std::make_shared(210, "Waseem Noor", locations[1], times[3]); - econ1105->setEnrolledStudentCount(187); - auto econ2257 = std::make_shared(125, "Tamrat Gashaw", "428 PUP", times[2]); - econ2257->setEnrolledStudentCount(63); - auto econ3211 = std::make_shared(96, "Murat Yilmaz", "310 FAY", times[1]); - econ3211->setEnrolledStudentCount(81); - auto econ3213 = std::make_shared(86, "Miles Leahey", "702 HAM", times[1]); - econ3213->setEnrolledStudentCount(77); - auto econ3412 = std::make_shared(86, "Thomas Piskula", "702 HAM", times[0]); - econ3412->setEnrolledStudentCount(81); - auto econ4415 = std::make_shared(110, "Evan D Sadler", locations[1], times[2]); - econ4415->setEnrolledStudentCount(63); - auto econ4710 = std::make_shared(86, "Matthieu Gomez", "517 HAM", "8:40-9:55"); - econ4710->setEnrolledStudentCount(37); - auto econ4840 = std::make_shared(108, "Mark Dean", "142 URIS", times[3]); - econ4840->setEnrolledStudentCount(67); - - courses.clear(); - courses["1105"] = econ1105; - courses["2257"] = econ2257; - courses["3211"] = econ3211; - courses["3213"] = econ3213; - courses["3412"] = econ3412; - courses["4415"] = econ4415; - courses["4710"] = econ4710; - courses["4840"] = econ4840; - - Department econ("ECON", courses, "Michael Woodford", 2345); - - // Data for IEOR department - auto ieor2500 = std::make_shared(50, "Uday Menon", "627 MUDD", times[0]); - ieor2500->setEnrolledStudentCount(52); - auto ieor3404 = std::make_shared(73, "Christopher J Dolan", "303 MUDD", times[2]); - ieor3404->setEnrolledStudentCount(80); - auto ieor3658 = std::make_shared(96, "Daniel Lacker", "310 FAY", times[2]); - ieor3658->setEnrolledStudentCount(87); - auto ieor4102 = std::make_shared(110, "Antonius B Dieker", "209 HAM", times[2]); - ieor4102->setEnrolledStudentCount(92); - auto ieor4106 = std::make_shared(150, "Kaizheng Wang", "501 NWC", times[2]); - ieor4106->setEnrolledStudentCount(161); - auto ieor4405 = std::make_shared(80, "Yuri Faenza", "517 HAV", times[0]); - ieor4405->setEnrolledStudentCount(19); - auto ieor4511 = std::make_shared(150, "Michael Robbins", "633 MUDD", "9:00-11:30"); - ieor4511->setEnrolledStudentCount(50); - auto ieor4540 = std::make_shared(60, "Krzysztof M Choromanski", "633 MUDD", "7:10-9:40"); - ieor4540->setEnrolledStudentCount(33); - - courses.clear(); - courses["2500"] = ieor2500; - courses["3404"] = ieor3404; - courses["3658"] = ieor3658; - courses["4102"] = ieor4102; - courses["4106"] = ieor4106; - courses["4405"] = ieor4405; - courses["4511"] = ieor4511; - courses["4540"] = ieor4540; - - Department ieor("IEOR", courses, "Jay Sethuraman", 67); - - // Data for CHEM department - auto chem1403 = std::make_shared(120, "Ruben M Savizky", locations[1], "6:10-7:25"); - chem1403->setEnrolledStudentCount(100); - auto chem1500 = std::make_shared(46, "Joseph C Ulichny", "302 HAV", "6:10-9:50"); - chem1500->setEnrolledStudentCount(50); - auto chem2045 = std::make_shared(50, "Luis M Campos", "209 HAV", "1:10-2:25"); - chem2045->setEnrolledStudentCount(29); - auto chem2444 = std::make_shared(150, "Christopher Eckdahl", locations[1], times[0]); - chem2444->setEnrolledStudentCount(150); - auto chem2494 = std::make_shared(24, "Talha Siddiqui", "202 HAV", "1:10-5:00"); - chem2494->setEnrolledStudentCount(18); - auto chem3080 = std::make_shared(60, "Milan Delor", "209 HAV", times[2]); - chem3080->setEnrolledStudentCount(18); - auto chem4071 = std::make_shared(42, "Jonathan S Owen", "320 HAV", "8:40-9:55"); - chem4071->setEnrolledStudentCount(29); - auto chem4102 = std::make_shared(28, "Dalibor Sames", "320 HAV", times[2]); - chem4102->setEnrolledStudentCount(27); - - courses.clear(); - courses["1403"] = chem1403; - courses["1500"] = chem1500; - courses["2045"] = chem2045; - courses["2444"] = chem2444; - courses["2494"] = chem2494; - courses["3080"] = chem3080; - courses["4071"] = chem4071; - courses["4102"] = chem4102; - - Department chem("CHEM", courses, "Laura J. Kaufman", 250); - - // Data for PHYS department - auto phys1001 = std::make_shared(150, "Szabolcs Marka", "301 PUP", times[3]); - phys1001->setEnrolledStudentCount(125); - auto phys1221 = std::make_shared(150, "James G. Mccann", "301 PUP", "4:10-5:25"); - phys1221->setEnrolledStudentCount(118); - auto phys1520 = std::make_shared(400, "Victor G. Moffat", "630 MUDD", times[1]); - phys1520->setEnrolledStudentCount(400); - auto phys2000 = std::make_shared(100, "Frank E. L. Banta", "402 CHANDLER", "1:10-3:40"); - phys2000->setEnrolledStudentCount(98); - auto phys3801 = std::make_shared(150, "Katherine M. McMahon", "603 MUDD", "4:10-5:25"); - phys3801->setEnrolledStudentCount(96); - auto phys4205 = std::make_shared(60, "Michael P. Larkin", locations[1], "6:10-9:50"); - phys4205->setEnrolledStudentCount(60); - - courses.clear(); - courses["1001"] = phys1001; - courses["1221"] = phys1221; - courses["1520"] = phys1520; - courses["2000"] = phys2000; - courses["3801"] = phys3801; - courses["4205"] = phys4205; - - Department phys("PHYS", courses, "Marcia L. Newson", 200); - - // Setup mapping - std::map mapping; - mapping["COMS"] = coms; - mapping["ECON"] = econ; - mapping["IEOR"] = ieor; - mapping["CHEM"] = chem; - mapping["PHYS"] = phys; - - myFileDatabase->setMapping(mapping); + std::string times[] = {"11:40-12:55", "4:10-5:25", + "10:10-11:25", "2:40-3:55"}; + std::string locations[] = {"417 IAB", "309 HAV", "301 URIS"}; + + // Data for COMS department + auto coms1004 = std::make_shared(400, "Adam Cannon", + locations[0], times[0]); + coms1004->setEnrolledStudentCount(249); + auto coms3134 = std::make_shared(250, "Brian Borowski", + locations[2], times[1]); + coms3134->setEnrolledStudentCount(242); + auto coms3157 = std::make_shared(400, "Jae Lee", + locations[0], times[1]); + coms3157->setEnrolledStudentCount(311); + auto coms3203 = std::make_shared(250, "Ansaf Salleb-Aouissi", + locations[2], times[2]); + coms3203->setEnrolledStudentCount(215); + auto coms3261 = std::make_shared(150, "Josh Alman", + locations[0], times[3]); + coms3261->setEnrolledStudentCount(140); + auto coms3251 = std::make_shared(125, "Tony Dear", + "402 CHANDLER", "1:10-3:40"); + coms3251->setEnrolledStudentCount(99); + auto coms3827 = std::make_shared(300, "Daniel Rubenstein", + "207 Math", times[2]); + coms3827->setEnrolledStudentCount(283); + auto coms4156 = std::make_shared(120, "Gail Kaiser", + "501 NWC", times[2]); + coms4156->setEnrolledStudentCount(109); + + std::map> courses; + courses["1004"] = coms1004; + courses["3134"] = coms3134; + courses["3157"] = coms3157; + courses["3203"] = coms3203; + courses["3261"] = coms3261; + courses["3251"] = coms3251; + courses["3827"] = coms3827; + courses["4156"] = coms4156; + + Department coms("COMS", courses, "Luca Carloni", 2700); + + // Data for ECON department + auto econ1105 = std::make_shared(210, "Waseem Noor", + locations[1], times[3]); + econ1105->setEnrolledStudentCount(187); + auto econ2257 = std::make_shared(125, "Tamrat Gashaw", + "428 PUP", times[2]); + econ2257->setEnrolledStudentCount(63); + auto econ3211 = std::make_shared(96, "Murat Yilmaz", + "310 FAY", times[1]); + econ3211->setEnrolledStudentCount(81); + auto econ3213 = std::make_shared(86, "Miles Leahey", + "702 HAM", times[1]); + econ3213->setEnrolledStudentCount(77); + auto econ3412 = std::make_shared(86, "Thomas Piskula", + "702 HAM", times[0]); + econ3412->setEnrolledStudentCount(81); + auto econ4415 = std::make_shared(110, "Evan D Sadler", + locations[1], times[2]); + econ4415->setEnrolledStudentCount(63); + auto econ4710 = std::make_shared(86, "Matthieu Gomez", + "517 HAM", "8:40-9:55"); + econ4710->setEnrolledStudentCount(37); + auto econ4840 = std::make_shared(108, "Mark Dean", + "142 URIS", times[3]); + econ4840->setEnrolledStudentCount(67); + + courses.clear(); + courses["1105"] = econ1105; + courses["2257"] = econ2257; + courses["3211"] = econ3211; + courses["3213"] = econ3213; + courses["3412"] = econ3412; + courses["4415"] = econ4415; + courses["4710"] = econ4710; + courses["4840"] = econ4840; + + Department econ("ECON", courses, "Michael Woodford", 2345); + + // Data for IEOR department + auto ieor2500 = std::make_shared(50, "Uday Menon", + "627 MUDD", times[0]); + ieor2500->setEnrolledStudentCount(52); + auto ieor3404 = std::make_shared(73, "Christopher J Dolan", + "303 MUDD", times[2]); + ieor3404->setEnrolledStudentCount(80); + auto ieor3658 = std::make_shared(96, "Daniel Lacker", + "310 FAY", times[2]); + ieor3658->setEnrolledStudentCount(87); + auto ieor4102 = std::make_shared(110, "Antonius B Dieker", + "209 HAM", times[2]); + ieor4102->setEnrolledStudentCount(92); + auto ieor4106 = std::make_shared(150, "Kaizheng Wang", + "501 NWC", times[2]); + ieor4106->setEnrolledStudentCount(161); + auto ieor4405 = std::make_shared(80, "Yuri Faenza", + "517 HAV", times[0]); + ieor4405->setEnrolledStudentCount(19); + auto ieor4511 = std::make_shared(150, "Michael Robbins", + "633 MUDD", "9:00-11:30"); + ieor4511->setEnrolledStudentCount(50); + auto ieor4540 = std::make_shared(60, "Krzysztof M Choromanski", + "633 MUDD", "7:10-9:40"); + ieor4540->setEnrolledStudentCount(33); + + courses.clear(); + courses["2500"] = ieor2500; + courses["3404"] = ieor3404; + courses["3658"] = ieor3658; + courses["4102"] = ieor4102; + courses["4106"] = ieor4106; + courses["4405"] = ieor4405; + courses["4511"] = ieor4511; + courses["4540"] = ieor4540; + + Department ieor("IEOR", courses, "Jay Sethuraman", 67); + + // Data for CHEM department + auto chem1403 = std::make_shared(120, "Ruben M Savizky", + locations[1], "6:10-7:25"); + chem1403->setEnrolledStudentCount(100); + auto chem1500 = std::make_shared(46, "Joseph C Ulichny", + "302 HAV", "6:10-9:50"); + chem1500->setEnrolledStudentCount(50); + auto chem2045 = std::make_shared(50, "Luis M Campos", + "209 HAV", "1:10-2:25"); + chem2045->setEnrolledStudentCount(29); + auto chem2444 = std::make_shared(150, "Christopher Eckdahl", + locations[1], times[0]); + chem2444->setEnrolledStudentCount(150); + auto chem2494 = std::make_shared(24, "Talha Siddiqui", + "202 HAV", "1:10-5:00"); + chem2494->setEnrolledStudentCount(18); + auto chem3080 = std::make_shared(60, "Milan Delor", + "209 HAV", times[2]); + chem3080->setEnrolledStudentCount(18); + auto chem4071 = std::make_shared(42, "Jonathan S Owen", + "320 HAV", "8:40-9:55"); + chem4071->setEnrolledStudentCount(29); + auto chem4102 = std::make_shared(28, "Dalibor Sames", + "320 HAV", times[2]); + chem4102->setEnrolledStudentCount(27); + + courses.clear(); + courses["1403"] = chem1403; + courses["1500"] = chem1500; + courses["2045"] = chem2045; + courses["2444"] = chem2444; + courses["2494"] = chem2494; + courses["3080"] = chem3080; + courses["4071"] = chem4071; + courses["4102"] = chem4102; + + Department chem("CHEM", courses, "Laura J. Kaufman", 250); + + // Data for PHYS department + auto phys1001 = std::make_shared(150, "Szabolcs Marka", + "301 PUP", times[3]); + phys1001->setEnrolledStudentCount(125); + auto phys1221 = std::make_shared(150, "James G. Mccann", + "301 PUP", "4:10-5:25"); + phys1221->setEnrolledStudentCount(118); + auto phys1520 = std::make_shared(400, "Victor G. Moffat", + "630 MUDD", times[1]); + phys1520->setEnrolledStudentCount(400); + auto phys2000 = std::make_shared(100, "Frank E. L. Banta", + "402 CHANDLER", "1:10-3:40"); + phys2000->setEnrolledStudentCount(98); + auto phys3801 = std::make_shared(150, "Katherine M. McMahon", + "603 MUDD", "4:10-5:25"); + phys3801->setEnrolledStudentCount(96); + auto phys4205 = std::make_shared(60, "Michael P. Larkin", + locations[1], "6:10-9:50"); + phys4205->setEnrolledStudentCount(60); + + courses.clear(); + courses["1001"] = phys1001; + courses["1221"] = phys1221; + courses["1520"] = phys1520; + courses["2000"] = phys2000; + courses["3801"] = phys3801; + courses["4205"] = phys4205; + + Department phys("PHYS", courses, "Marcia L. Newson", 200); + + // Setup mapping + std::map mapping; + mapping["COMS"] = coms; + mapping["ECON"] = econ; + mapping["IEOR"] = ieor; + mapping["CHEM"] = chem; + mapping["PHYS"] = phys; + + myFileDatabase->setMapping(mapping); } diff --git a/IndividualMiniprojectC++/src/MyFileDatabase.cpp b/IndividualMiniprojectC++/src/MyFileDatabase.cpp index 034049f92..30ca8e36f 100644 --- a/IndividualMiniprojectC++/src/MyFileDatabase.cpp +++ b/IndividualMiniprojectC++/src/MyFileDatabase.cpp @@ -1,3 +1,4 @@ +// Copyright 2024 Richard Cruz-Silva #include "MyFileDatabase.h" #include #include @@ -9,10 +10,11 @@ * @param flag used to distinguish mode of database * @param filePath the path to the file containing the entries of the database */ -MyFileDatabase::MyFileDatabase(int flag, const std::string& filePath) : filePath(filePath) { - if (flag == 0) { - deSerializeObjectFromFile(); - } +MyFileDatabase::MyFileDatabase(int flag, const std::string& filePath) +: filePath(filePath) { + if (flag == 0) { + deSerializeObjectFromFile(); + } } /** @@ -20,8 +22,9 @@ MyFileDatabase::MyFileDatabase(int flag, const std::string& filePath) : filePath * * @param mapping the mapping of department names to Department objects */ -void MyFileDatabase::setMapping(const std::map& mapping) { - departmentMapping = mapping; +void MyFileDatabase::setMapping(const std::map& mapping) { + departmentMapping = mapping; } /** @@ -29,8 +32,9 @@ void MyFileDatabase::setMapping(const std::map& mapping * * @return the department mapping */ -std::map MyFileDatabase::getDepartmentMapping() const { - return departmentMapping; +std::map +MyFileDatabase::getDepartmentMapping() const { + return departmentMapping; } /** @@ -38,16 +42,16 @@ std::map MyFileDatabase::getDepartmentMapping() const { * overwritten with this operation. */ void MyFileDatabase::saveContentsToFile() const { - std::ofstream outFile(filePath, std::ios::binary); - size_t mapSize = departmentMapping.size(); - outFile.write(reinterpret_cast(&mapSize), sizeof(mapSize)); - for (const auto& it : departmentMapping) { - size_t keyLen = it.first.length(); - outFile.write(reinterpret_cast(&keyLen), sizeof(keyLen)); - outFile.write(it.first.c_str(), keyLen); - it.second.serialize(outFile); - } - outFile.close(); + std::ofstream outFile(filePath, std::ios::binary); + size_t mapSize = departmentMapping.size(); + outFile.write(reinterpret_cast(&mapSize), sizeof(mapSize)); + for (const auto& it : departmentMapping) { + size_t keyLen = it.first.length(); + outFile.write(reinterpret_cast(&keyLen), sizeof(keyLen)); + outFile.write(it.first.c_str(), keyLen); + it.second.serialize(outFile); + } + outFile.close(); } /** @@ -56,19 +60,19 @@ void MyFileDatabase::saveContentsToFile() const { * @return the deserialized department mapping */ void MyFileDatabase::deSerializeObjectFromFile() { - std::ifstream inFile(filePath, std::ios::binary); - size_t mapSize; - inFile.read(reinterpret_cast(&mapSize), sizeof(mapSize)); - for (size_t i = 0; i < mapSize; ++i) { - size_t keyLen; - inFile.read(reinterpret_cast(&keyLen), sizeof(keyLen)); - std::string key(keyLen, ' '); - inFile.read(&key[0], keyLen); - Department dept; - dept.deserialize(inFile); - departmentMapping[key] = dept; - } - inFile.close(); + std::ifstream inFile(filePath, std::ios::binary); + size_t mapSize; + inFile.read(reinterpret_cast(&mapSize), sizeof(mapSize)); + for (size_t i = 0; i < mapSize; ++i) { + size_t keyLen; + inFile.read(reinterpret_cast(&keyLen), sizeof(keyLen)); + std::string key(keyLen, ' '); + inFile.read(&key[0], keyLen); + Department dept; + dept.deserialize(inFile); + departmentMapping[key] = dept; + } + inFile.close(); } /** @@ -77,9 +81,10 @@ void MyFileDatabase::deSerializeObjectFromFile() { * @return a string representation of the database */ std::string MyFileDatabase::display() const { - std::string result; - for (const auto& it : departmentMapping) { - result += "For the " + it.first + " department:\n" + it.second.display() + "\n"; - } - return result; + std::string result; + for (const auto& it : departmentMapping) { + result += "For the " + it.first + " department:\n" + + it.second.display() + "\n"; + } + return result; } diff --git a/IndividualMiniprojectC++/src/RouteController.cpp b/IndividualMiniprojectC++/src/RouteController.cpp index c183c2a79..56ef8b580 100644 --- a/IndividualMiniprojectC++/src/RouteController.cpp +++ b/IndividualMiniprojectC++/src/RouteController.cpp @@ -1,27 +1,35 @@ +// Copyright 2024 Richard Cruz-Silva #include "RouteController.h" -#include "Globals.h" -#include "MyFileDatabase.h" -#include "crow.h" #include #include #include #include +#include "Globals.h" +#include "MyFileDatabase.h" +#include "./crow.h" + // Utility function to handle exceptions crow::response handleException(const std::exception& e) { - std::cerr << e.what() << std::endl; - return crow::response{500, "An error has occurred"}; + std::cerr << e.what() << std::endl; + return crow::response{500, "An error has occurred"}; } +/** + * Constructs a default RouteController object with the default parameters. + * + */ +RouteController::RouteController() : myFileDatabase(nullptr) {} + /** * Redirects to the homepage. * * @return A string containing the name of the html file to be loaded. */ void RouteController::index(crow::response& res) { - res.write("Welcome, in order to make an API call direct your browser or Postman to an endpoint " - "\n\n This can be done using the following format: \n\n http://127.0.0.1:8080/endpoint?arg=value"); - res.end(); + res.write("Welcome, in order to make an API call direct your browser or Postman to an endpoint " + "\n\nThis can be done using the following format: \n\nhttp://127.0.0.1:8080/endpoint?arg=value"); + res.end(); } /** @@ -33,23 +41,25 @@ void RouteController::index(crow::response& res) { * @return A crow::response object containing either the details of the Department and * an HTTP 200 response or, an appropriate message indicating the proper response. */ -void RouteController::retrieveDepartment(const crow::request& req, crow::response& res) { - try { - auto deptCode = req.url_params.get("deptCode"); - auto departmentMapping = myFileDatabase->getDepartmentMapping(); - - auto it = departmentMapping.find(deptCode); - if (it == departmentMapping.end()) { - res.code = 404; - res.write("Department Not Found"); - } else { - res.code = 200; - res.write(it->second.display()); // Use dot operator to access method - } - res.end(); - } catch (const std::exception& e) { - res = handleException(e); +void RouteController::retrieveDepartment(const crow::request& req, + crow::response& res) { + try { + auto deptCode = req.url_params.get("deptCode"); + auto departmentMapping = myFileDatabase->getDepartmentMapping(); + + auto it = departmentMapping.find(deptCode); + if (it == departmentMapping.end()) { + res.code = 404; + res.write("Department Not Found"); + } else { + res.code = 200; + // Use dot operator to access method + res.write(it->second.display()); } + res.end(); + } catch (const std::exception& e) { + res = handleException(e); + } } /** @@ -66,33 +76,35 @@ void RouteController::retrieveDepartment(const crow::request& req, crow::respons * course and an HTTP 200 response or, an appropriate message indicating the * proper response. */ -void RouteController::retrieveCourse(const crow::request& req, crow::response& res) { - try { - auto deptCode = req.url_params.get("deptCode"); - auto courseCode = std::stoi(req.url_params.get("courseCode")); - - auto departmentMapping = myFileDatabase->getDepartmentMapping(); - auto deptIt = departmentMapping.find(deptCode); - - if (deptIt == departmentMapping.end()) { - res.code = 404; - res.write("Department Not Found"); - } else { - auto coursesMapping = deptIt->second.getCourseSelection(); - auto courseIt = coursesMapping.find(std::to_string(courseCode)); - - if (courseIt == coursesMapping.end()) { - res.code = 404; - res.write("Course Not Found"); - } else { - res.code = 200; - res.write(courseIt->second->display()); // Use dot operator to access method - } - } - res.end(); - } catch (const std::exception& e) { - res = handleException(e); +void RouteController::retrieveCourse(const crow::request& req, + crow::response& res) { + try { + auto deptCode = req.url_params.get("deptCode"); + auto courseCode = std::stoi(req.url_params.get("courseCode")); + + auto departmentMapping = myFileDatabase->getDepartmentMapping(); + auto deptIt = departmentMapping.find(deptCode); + + if (deptIt == departmentMapping.end()) { + res.code = 404; + res.write("Department Not Found"); + } else { + auto coursesMapping = deptIt->second.getCourseSelection(); + auto courseIt = coursesMapping.find(std::to_string(courseCode)); + + if (courseIt == coursesMapping.end()) { + res.code = 404; + res.write("Course Not Found"); + } else { + res.code = 200; + // Use dot operator to access method + res.write(courseIt->second->display()); + } } + res.end(); + } catch (const std::exception& e) { + res = handleException(e); + } } /** @@ -108,34 +120,36 @@ void RouteController::retrieveCourse(const crow::request& req, crow::response& r * and an HTTP 200 response or, an appropriate message indicating the proper * response. */ -void RouteController::isCourseFull(const crow::request& req, crow::response& res) { - try { - auto deptCode = req.url_params.get("deptCode"); - auto courseCode = std::stoi(req.url_params.get("courseCode")); - - auto departmentMapping = myFileDatabase->getDepartmentMapping(); - auto deptIt = departmentMapping.find(deptCode); - - if (deptIt == departmentMapping.end()) { - res.code = 404; - res.write("Department Not Found"); - } else { - auto coursesMapping = deptIt->second.getCourseSelection(); - auto courseIt = coursesMapping.find(std::to_string(courseCode)); - - if (courseIt == coursesMapping.end()) { - res.code = 404; - res.write("Course Not Found"); - } else { - auto course = courseIt->second; - res.code = 200; - res.write(course->isCourseFull() ? "true" : "false"); // Use dot operator to call method - } - } - res.end(); - } catch (const std::exception& e) { - res = handleException(e); +void RouteController::isCourseFull(const crow::request& req, + crow::response& res) { + try { + auto deptCode = req.url_params.get("deptCode"); + auto courseCode = std::stoi(req.url_params.get("courseCode")); + + auto departmentMapping = myFileDatabase->getDepartmentMapping(); + auto deptIt = departmentMapping.find(deptCode); + + if (deptIt == departmentMapping.end()) { + res.code = 404; + res.write("Department Not Found"); + } else { + auto coursesMapping = deptIt->second.getCourseSelection(); + auto courseIt = coursesMapping.find(std::to_string(courseCode)); + + if (courseIt == coursesMapping.end()) { + res.code = 404; + res.write("Course Not Found"); + } else { + auto course = courseIt->second; + res.code = 200; + // Use dot operator to call method + res.write(course->isCourseFull() ? "true" : "false"); + } } + res.end(); + } catch (const std::exception& e) { + res = handleException(e); + } } /** @@ -148,24 +162,28 @@ void RouteController::isCourseFull(const crow::request& req, crow::response& res * specified department and an HTTP 200 response or, an appropriate message * indicating the proper response. */ -void RouteController::getMajorCountFromDept(const crow::request& req, crow::response& res) { - try { - auto deptCode = req.url_params.get("deptCode"); - - auto departmentMapping = myFileDatabase->getDepartmentMapping(); - auto deptIt = departmentMapping.find(deptCode); - - if (deptIt == departmentMapping.end()) { - res.code = 404; - res.write("Department Not Found"); - } else { - res.code = 200; - res.write("There are: " + std::to_string(deptIt->second.getNumberOfMajors()) + " majors in the department"); // Use dot operator to call method - } - res.end(); - } catch (const std::exception& e) { - res = handleException(e); +void RouteController::getMajorCountFromDept(const crow::request& req, + crow::response& res) { + try { + auto deptCode = req.url_params.get("deptCode"); + + auto departmentMapping = myFileDatabase->getDepartmentMapping(); + auto deptIt = departmentMapping.find(deptCode); + + if (deptIt == departmentMapping.end()) { + res.code = 404; + res.write("Department Not Found"); + } else { + res.code = 200; + // Use dot operator to call method + res.write("There are: " + + std::to_string(deptIt->second.getNumberOfMajors()) + + " majors in the department"); } + res.end(); + } catch (const std::exception& e) { + res = handleException(e); + } } /** @@ -178,24 +196,27 @@ void RouteController::getMajorCountFromDept(const crow::request& req, crow::resp * specified department and an HTTP 200 response or, an appropriate message * indicating the proper response. */ -void RouteController::identifyDeptChair(const crow::request& req, crow::response& res) { - try { - auto deptCode = req.url_params.get("deptCode"); - - auto departmentMapping = myFileDatabase->getDepartmentMapping(); - auto deptIt = departmentMapping.find(deptCode); - - if (deptIt == departmentMapping.end()) { - res.code = 404; - res.write("Department Not Found"); - } else { - res.code = 200; - res.write(deptIt->second.getDepartmentChair() + " is the department chair."); // Use dot operator to call method - } - res.end(); - } catch (const std::exception& e) { - res = handleException(e); +void RouteController::identifyDeptChair(const crow::request& req, + crow::response& res) { + try { + auto deptCode = req.url_params.get("deptCode"); + + auto departmentMapping = myFileDatabase->getDepartmentMapping(); + auto deptIt = departmentMapping.find(deptCode); + + if (deptIt == departmentMapping.end()) { + res.code = 404; + res.write("Department Not Found"); + } else { + res.code = 200; + // Use dot operator to call method + res.write(deptIt->second.getDepartmentChair() + + " is the department chair."); } + res.end(); + } catch (const std::exception& e) { + res = handleException(e); + } } /** @@ -211,34 +232,37 @@ void RouteController::identifyDeptChair(const crow::request& req, crow::response * course and an HTTP 200 response or, an appropriate message indicating the * proper response. */ -void RouteController::findCourseLocation(const crow::request& req, crow::response& res) { - try { - auto deptCode = req.url_params.get("deptCode"); - auto courseCode = std::stoi(req.url_params.get("courseCode")); - - auto departmentMapping = myFileDatabase->getDepartmentMapping(); - auto deptIt = departmentMapping.find(deptCode); - - if (deptIt == departmentMapping.end()) { - res.code = 404; - res.write("Department Not Found"); - } else { - auto coursesMapping = deptIt->second.getCourseSelection(); - auto courseIt = coursesMapping.find(std::to_string(courseCode)); - - if (courseIt == coursesMapping.end()) { - res.code = 404; - res.write("Course Not Found"); - } else { - auto course = courseIt->second; - res.code = 200; - res.write(course->getCourseLocation() + " is where the course is located."); // Use dot operator to call method - } - } - res.end(); - } catch (const std::exception& e) { - res = handleException(e); +void RouteController::findCourseLocation(const crow::request& req, + crow::response& res) { + try { + auto deptCode = req.url_params.get("deptCode"); + auto courseCode = std::stoi(req.url_params.get("courseCode")); + + auto departmentMapping = myFileDatabase->getDepartmentMapping(); + auto deptIt = departmentMapping.find(deptCode); + + if (deptIt == departmentMapping.end()) { + res.code = 404; + res.write("Department Not Found"); + } else { + auto coursesMapping = deptIt->second.getCourseSelection(); + auto courseIt = coursesMapping.find(std::to_string(courseCode)); + + if (courseIt == coursesMapping.end()) { + res.code = 404; + res.write("Course Not Found"); + } else { + auto course = courseIt->second; + res.code = 200; + // Use dot operator to call method + res.write(course->getCourseLocation() + + " is where the course is located."); + } } + res.end(); + } catch (const std::exception& e) { + res = handleException(e); + } } /** @@ -254,34 +278,37 @@ void RouteController::findCourseLocation(const crow::request& req, crow::respons * an HTTP 200 response or, an appropriate message indicating the proper * response. */ -void RouteController::findCourseInstructor(const crow::request& req, crow::response& res) { - try { - auto deptCode = req.url_params.get("deptCode"); - auto courseCode = std::stoi(req.url_params.get("courseCode")); - - auto departmentMapping = myFileDatabase->getDepartmentMapping(); - auto deptIt = departmentMapping.find(deptCode); - - if (deptIt == departmentMapping.end()) { - res.code = 404; - res.write("Department Not Found"); - } else { - auto coursesMapping = deptIt->second.getCourseSelection(); - auto courseIt = coursesMapping.find(std::to_string(courseCode)); - - if (courseIt == coursesMapping.end()) { - res.code = 404; - res.write("Course Not Found"); - } else { - auto course = courseIt->second; - res.code = 200; - res.write(course->getInstructorName() + " is the instructor for the course."); // Use dot operator to call method - } - } - res.end(); - } catch (const std::exception& e) { - res = handleException(e); +void RouteController::findCourseInstructor(const crow::request& req, + crow::response& res) { + try { + auto deptCode = req.url_params.get("deptCode"); + auto courseCode = std::stoi(req.url_params.get("courseCode")); + + auto departmentMapping = myFileDatabase->getDepartmentMapping(); + auto deptIt = departmentMapping.find(deptCode); + + if (deptIt == departmentMapping.end()) { + res.code = 404; + res.write("Department Not Found"); + } else { + auto coursesMapping = deptIt->second.getCourseSelection(); + auto courseIt = coursesMapping.find(std::to_string(courseCode)); + + if (courseIt == coursesMapping.end()) { + res.code = 404; + res.write("Course Not Found"); + } else { + auto course = courseIt->second; + res.code = 200; + // Use dot operator to call method + res.write(course->getInstructorName() + + " is the instructor for the course."); + } } + res.end(); + } catch (const std::exception& e) { + res = handleException(e); + } } /** @@ -297,34 +324,35 @@ void RouteController::findCourseInstructor(const crow::request& req, crow::respo * course timeslot and an HTTP 200 response or, an appropriate message * indicating the proper response. */ -void RouteController::findCourseTime(const crow::request& req, crow::response& res) { - try { - auto deptCode = req.url_params.get("deptCode"); - auto courseCode = std::stoi(req.url_params.get("courseCode")); - - auto departmentMapping = myFileDatabase->getDepartmentMapping(); - auto deptIt = departmentMapping.find(deptCode); - - if (deptIt == departmentMapping.end()) { - res.code = 404; - res.write("Department Not Found"); - } else { - auto coursesMapping = deptIt->second.getCourseSelection(); - auto courseIt = coursesMapping.find(std::to_string(courseCode)); - - if (courseIt == coursesMapping.end()) { - res.code = 404; - res.write("Course Not Found"); - } else { - auto course = courseIt->second; - res.code = 200; - res.write("The course meets at: " + course->getCourseTimeSlot()); - } - } - res.end(); - } catch (const std::exception& e) { - res = handleException(e); +void RouteController::findCourseTime(const crow::request& req, + crow::response& res) { + try { + auto deptCode = req.url_params.get("deptCode"); + auto courseCode = std::stoi(req.url_params.get("courseCode")); + + auto departmentMapping = myFileDatabase->getDepartmentMapping(); + auto deptIt = departmentMapping.find(deptCode); + + if (deptIt == departmentMapping.end()) { + res.code = 404; + res.write("Department Not Found"); + } else { + auto coursesMapping = deptIt->second.getCourseSelection(); + auto courseIt = coursesMapping.find(std::to_string(courseCode)); + + if (courseIt == coursesMapping.end()) { + res.code = 404; + res.write("Course Not Found"); + } else { + auto course = courseIt->second; + res.code = 200; + res.write("The course meets at: " + course->getCourseTimeSlot()); + } } + res.end(); + } catch (const std::exception& e) { + res = handleException(e); + } } /** @@ -336,154 +364,160 @@ void RouteController::findCourseTime(const crow::request& req, crow::response& r * response with an appropriate message or the proper status * code in tune with what has happened. */ -void RouteController::addMajorToDept(const crow::request& req, crow::response& res) { - try { - auto deptCode = req.url_params.get("deptCode"); - - auto departmentMapping = myFileDatabase->getDepartmentMapping(); - auto deptIt = departmentMapping.find(deptCode); - - if (deptIt == departmentMapping.end()) { - res.code = 404; - res.write("Department Not Found"); - } else { - deptIt->second.addPersonToMajor(); // Use dot operator to call method - res.code = 200; - res.write("Attribute was updated successfully"); - } - res.end(); - } catch (const std::exception& e) { - res = handleException(e); +void RouteController::addMajorToDept(const crow::request& req, + crow::response& res) { + try { + auto deptCode = req.url_params.get("deptCode"); + + auto departmentMapping = myFileDatabase->getDepartmentMapping(); + auto deptIt = departmentMapping.find(deptCode); + + if (deptIt == departmentMapping.end()) { + res.code = 404; + res.write("Department Not Found"); + } else { + // Use dot operator to call method + deptIt->second.addPersonToMajor(); + res.code = 200; + res.write("Attribute was updated successfully"); } + res.end(); + } catch (const std::exception& e) { + res = handleException(e); + } } // Set Enrollment Count -void RouteController::setEnrollmentCount(const crow::request& req, crow::response& res) { - try { - auto deptCode = req.url_params.get("deptCode"); - auto courseCode = std::stoi(req.url_params.get("courseCode")); - auto count = std::stoi(req.url_params.get("count")); - - auto departmentMapping = myFileDatabase->getDepartmentMapping(); - auto deptIt = departmentMapping.find(deptCode); - - if (deptIt != departmentMapping.end()) { - auto coursesMapping = deptIt->second.getCourseSelection(); - auto courseIt = coursesMapping.find(std::to_string(courseCode)); - - if (courseIt != coursesMapping.end()) { - courseIt->second->setEnrolledStudentCount(count); - res.code = 200; - res.write("Attribute was updated successfully."); - } else { - res.code = 404; - res.write("Course Not Found"); - } - } else { - res.code = 404; - res.write("Department Not Found"); - } - res.end(); - } catch (const std::exception& e) { - res = handleException(e); +void RouteController::setEnrollmentCount(const crow::request& req, + crow::response& res) { + try { + auto deptCode = req.url_params.get("deptCode"); + auto courseCode = std::stoi(req.url_params.get("courseCode")); + auto count = std::stoi(req.url_params.get("count")); + + auto departmentMapping = myFileDatabase->getDepartmentMapping(); + auto deptIt = departmentMapping.find(deptCode); + + if (deptIt != departmentMapping.end()) { + auto coursesMapping = deptIt->second.getCourseSelection(); + auto courseIt = coursesMapping.find(std::to_string(courseCode)); + + if (courseIt != coursesMapping.end()) { + courseIt->second->setEnrolledStudentCount(count); + res.code = 200; + res.write("Attribute was updated successfully."); + } else { + res.code = 404; + res.write("Course Not Found"); + } + } else { + res.code = 404; + res.write("Department Not Found"); } + res.end(); + } catch (const std::exception& e) { + res = handleException(e); + } } // Set Course Location -void RouteController::setCourseLocation(const crow::request& req, crow::response& res) { - try { - auto deptCode = req.url_params.get("deptCode"); - auto courseCode = std::stoi(req.url_params.get("courseCode")); - auto location = req.url_params.get("location"); - - auto departmentMapping = myFileDatabase->getDepartmentMapping(); - auto deptIt = departmentMapping.find(deptCode); - - if (deptIt != departmentMapping.end()) { - auto coursesMapping = deptIt->second.getCourseSelection(); - auto courseIt = coursesMapping.find(std::to_string(courseCode)); - - if (courseIt != coursesMapping.end()) { - courseIt->second->reassignLocation(location); - res.code = 200; - res.write("Attribute was updated successfully."); - } else { - res.code = 404; - res.write("Course Not Found"); - } - } else { - res.code = 404; - res.write("Department Not Found"); - } - res.end(); - } catch (const std::exception& e) { - res = handleException(e); +void RouteController::setCourseLocation(const crow::request& req, + crow::response& res) { + try { + auto deptCode = req.url_params.get("deptCode"); + auto courseCode = std::stoi(req.url_params.get("courseCode")); + auto location = req.url_params.get("location"); + + auto departmentMapping = myFileDatabase->getDepartmentMapping(); + auto deptIt = departmentMapping.find(deptCode); + + if (deptIt != departmentMapping.end()) { + auto coursesMapping = deptIt->second.getCourseSelection(); + auto courseIt = coursesMapping.find(std::to_string(courseCode)); + + if (courseIt != coursesMapping.end()) { + courseIt->second->reassignLocation(location); + res.code = 200; + res.write("Attribute was updated successfully."); + } else { + res.code = 404; + res.write("Course Not Found"); + } + } else { + res.code = 404; + res.write("Department Not Found"); } + res.end(); + } catch (const std::exception& e) { + res = handleException(e); + } } -void RouteController::setCourseInstructor(const crow::request& req, crow::response& res) { - try { - auto deptCode = req.url_params.get("deptCode"); - auto courseCodeStr = req.url_params.get("courseCode"); - auto instructor = req.url_params.get("instructor"); - - int courseCode = std::stoi(courseCodeStr); - - auto departmentMapping = myFileDatabase->getDepartmentMapping(); - auto deptIt = departmentMapping.find(deptCode); - - if (deptIt != departmentMapping.end()) { - auto coursesMapping = deptIt->second.getCourseSelection(); - auto courseIt = coursesMapping.find(std::to_string(courseCode)); - - if (courseIt != coursesMapping.end()) { - courseIt->second->reassignInstructor(instructor); - res.code = 200; - res.write("Attribute was updated successfully."); - } else { - res.code = 404; - res.write("Course Not Found"); - } - } else { - res.code = 404; - res.write("Department Not Found"); - } - res.end(); - } catch (const std::exception& e) { - res = handleException(e); +void RouteController::setCourseInstructor(const crow::request& req, + crow::response& res) { + try { + auto deptCode = req.url_params.get("deptCode"); + auto courseCodeStr = req.url_params.get("courseCode"); + auto instructor = req.url_params.get("instructor"); + + int courseCode = std::stoi(courseCodeStr); + + auto departmentMapping = myFileDatabase->getDepartmentMapping(); + auto deptIt = departmentMapping.find(deptCode); + + if (deptIt != departmentMapping.end()) { + auto coursesMapping = deptIt->second.getCourseSelection(); + auto courseIt = coursesMapping.find(std::to_string(courseCode)); + + if (courseIt != coursesMapping.end()) { + courseIt->second->reassignInstructor(instructor); + res.code = 200; + res.write("Attribute was updated successfully."); + } else { + res.code = 404; + res.write("Course Not Found"); + } + } else { + res.code = 404; + res.write("Department Not Found"); } + res.end(); + } catch (const std::exception& e) { + res = handleException(e); + } } // Set Course Time -void RouteController::setCourseTime(const crow::request& req, crow::response& res) { - try { - auto deptCode = req.url_params.get("deptCode"); - auto courseCode = std::stoi(req.url_params.get("courseCode")); - auto time = req.url_params.get("time"); - - auto departmentMapping = myFileDatabase->getDepartmentMapping(); - auto deptIt = departmentMapping.find(deptCode); - - if (deptIt != departmentMapping.end()) { - auto coursesMapping = deptIt->second.getCourseSelection(); - auto courseIt = coursesMapping.find(std::to_string(courseCode)); - - if (courseIt != coursesMapping.end()) { - courseIt->second->reassignTime(time); - res.code = 200; - res.write("Attribute was updated successfully."); - } else { - res.code = 404; - res.write("Course Not Found"); - } - } else { - res.code = 404; - res.write("Department Not Found"); - } - res.end(); - } catch (const std::exception& e) { - res = handleException(e); +void RouteController::setCourseTime(const crow::request& req, + crow::response& res) { + try { + auto deptCode = req.url_params.get("deptCode"); + auto courseCode = std::stoi(req.url_params.get("courseCode")); + auto time = req.url_params.get("time"); + + auto departmentMapping = myFileDatabase->getDepartmentMapping(); + auto deptIt = departmentMapping.find(deptCode); + + if (deptIt != departmentMapping.end()) { + auto coursesMapping = deptIt->second.getCourseSelection(); + auto courseIt = coursesMapping.find(std::to_string(courseCode)); + + if (courseIt != coursesMapping.end()) { + courseIt->second->reassignTime(time); + res.code = 200; + res.write("Attribute was updated successfully."); + } else { + res.code = 404; + res.write("Course Not Found"); + } + } else { + res.code = 404; + res.write("Department Not Found"); } + res.end(); + } catch (const std::exception& e) { + res = handleException(e); + } } @@ -496,25 +530,26 @@ void RouteController::setCourseTime(const crow::request& req, crow::response& re * response with an appropriate message or the proper status * code in tune with what has happened. */ -void RouteController::removeMajorFromDept(const crow::request& req, crow::response& res) { - try { - auto deptCode = req.url_params.get("deptCode"); - - auto departmentMapping = myFileDatabase->getDepartmentMapping(); - auto deptIt = departmentMapping.find(deptCode); - - if (deptIt == departmentMapping.end()) { - res.code = 404; - res.write("Department Not Found"); - } else { - deptIt->second.dropPersonFromMajor(); - res.code = 200; - res.write("Attribute was updated successfully"); - } - res.end(); - } catch (const std::exception& e) { - res = handleException(e); +void RouteController::removeMajorFromDept(const crow::request& req, + crow::response& res) { + try { + auto deptCode = req.url_params.get("deptCode"); + + auto departmentMapping = myFileDatabase->getDepartmentMapping(); + auto deptIt = departmentMapping.find(deptCode); + + if (deptIt == departmentMapping.end()) { + res.code = 404; + res.write("Department Not Found"); + } else { + deptIt->second.dropPersonFromMajor(); + res.code = 200; + res.write("Attribute was updated successfully"); } + res.end(); + } catch (const std::exception& e) { + res = handleException(e); + } } /** @@ -529,119 +564,135 @@ void RouteController::removeMajorFromDept(const crow::request& req, crow::respon * response with an appropriate message or the proper status * code in tune with what has happened. */ -void RouteController::dropStudentFromCourse(const crow::request& req, crow::response& res) { - try { - auto deptCode = req.url_params.get("deptCode"); - auto courseCode = std::stoi(req.url_params.get("courseCode")); - - auto departmentMapping = myFileDatabase->getDepartmentMapping(); - auto deptIt = departmentMapping.find(deptCode); - - if (deptIt == departmentMapping.end()) { - res.code = 404; - res.write("Department Not Found"); +void RouteController::dropStudentFromCourse(const crow::request& req, + crow::response& res) { + try { + auto deptCode = req.url_params.get("deptCode"); + auto courseCode = std::stoi(req.url_params.get("courseCode")); + + auto departmentMapping = myFileDatabase->getDepartmentMapping(); + auto deptIt = departmentMapping.find(deptCode); + + if (deptIt == departmentMapping.end()) { + res.code = 404; + res.write("Department Not Found"); + } else { + auto coursesMapping = deptIt->second.getCourseSelection(); + auto courseIt = coursesMapping.find(std::to_string(courseCode)); + + if (courseIt == coursesMapping.end()) { + res.code = 404; + res.write("Course Not Found"); + } else { + bool isStudentDropped = courseIt->second->dropStudent(); + if (isStudentDropped) { + res.code = 200; + res.write("Student has been dropped"); } else { - auto coursesMapping = deptIt->second.getCourseSelection(); - auto courseIt = coursesMapping.find(std::to_string(courseCode)); - - if (courseIt == coursesMapping.end()) { - res.code = 404; - res.write("Course Not Found"); - } else { - bool isStudentDropped = courseIt->second->dropStudent(); - if (isStudentDropped) { - res.code = 200; - res.write("Student has been dropped"); - } else { - res.code = 400; - res.write("Student has not been dropped"); - } - } + res.code = 400; + res.write("Student has not been dropped"); } - res.end(); - } catch (const std::exception& e) { - res = handleException(e); + } } + res.end(); + } catch (const std::exception& e) { + res = handleException(e); + } } // Initialize API Routes void RouteController::initRoutes(crow::App<>& app) { - CROW_ROUTE(app, "/") - .methods(crow::HTTPMethod::GET)([this](const crow::request& req, crow::response& res) { - index(res); - }); - - CROW_ROUTE(app, "/retrieveDept") - .methods(crow::HTTPMethod::GET)([this](const crow::request& req, crow::response& res) { - retrieveDepartment(req, res); - }); - - CROW_ROUTE(app, "/retrieveCourse") - .methods(crow::HTTPMethod::GET)([this](const crow::request& req, crow::response& res) { - retrieveCourse(req, res); - }); - - CROW_ROUTE(app, "/isCourseFull") - .methods(crow::HTTPMethod::GET)([this](const crow::request& req, crow::response& res) { - isCourseFull(req, res); - }); - - CROW_ROUTE(app, "/getMajorCountFromDept") - .methods(crow::HTTPMethod::GET)([this](const crow::request& req, crow::response& res) { - getMajorCountFromDept(req, res); - }); - - CROW_ROUTE(app, "/idDeptChair") - .methods(crow::HTTPMethod::GET)([this](const crow::request& req, crow::response& res) { - identifyDeptChair(req, res); - }); - - CROW_ROUTE(app, "/findCourseLocation") - .methods(crow::HTTPMethod::GET)([this](const crow::request& req, crow::response& res) { - findCourseLocation(req, res); - }); - - CROW_ROUTE(app, "/findCourseInstructor") - .methods(crow::HTTPMethod::GET)([this](const crow::request& req, crow::response& res) { - findCourseInstructor(req, res); - }); - - CROW_ROUTE(app, "/findCourseTime") - .methods(crow::HTTPMethod::GET)([this](const crow::request& req, crow::response& res) { - findCourseTime(req, res); - }); - - CROW_ROUTE(app, "/addMajorToDept") - .methods(crow::HTTPMethod::GET)([this](const crow::request& req, crow::response& res) { - addMajorToDept(req, res); - }); - - CROW_ROUTE(app, "/removeMajorFromDept") - .methods(crow::HTTPMethod::GET)([this](const crow::request& req, crow::response& res) { - removeMajorFromDept(req, res); - }); - - CROW_ROUTE(app, "/changeCourseLocation") - .methods(crow::HTTPMethod::PATCH)([this](const crow::request& req, crow::response& res) { - setCourseLocation(req, res); - }); - - CROW_ROUTE(app, "/changeCourseTeacher") - .methods(crow::HTTPMethod::PATCH)([this](const crow::request& req, crow::response& res) { - setCourseInstructor(req, res); - }); - - CROW_ROUTE(app, "/changeCourseTime") - .methods(crow::HTTPMethod::PATCH)([this](const crow::request& req, crow::response& res) { - setCourseTime(req, res); - }); - - CROW_ROUTE(app, "/setEnrollmentCount") - .methods(crow::HTTPMethod::PATCH)([this](const crow::request& req, crow::response& res) { - setEnrollmentCount(req, res); - }); + CROW_ROUTE(app, "/") + .methods(crow::HTTPMethod::GET)([this](const crow::request& req, + crow::response& res) { + index(res); + }); + + CROW_ROUTE(app, "/retrieveDept") + .methods(crow::HTTPMethod::GET)([this](const crow::request& req, + crow::response& res) { + retrieveDepartment(req, res); + }); + + CROW_ROUTE(app, "/retrieveCourse") + .methods(crow::HTTPMethod::GET)([this](const crow::request& req, + crow::response& res) { + retrieveCourse(req, res); + }); + + CROW_ROUTE(app, "/isCourseFull") + .methods(crow::HTTPMethod::GET)([this](const crow::request& req, + crow::response& res) { + isCourseFull(req, res); + }); + + CROW_ROUTE(app, "/getMajorCountFromDept") + .methods(crow::HTTPMethod::GET)([this](const crow::request& req, + crow::response& res) { + getMajorCountFromDept(req, res); + }); + + CROW_ROUTE(app, "/idDeptChair") + .methods(crow::HTTPMethod::GET)([this](const crow::request& req, + crow::response& res) { + identifyDeptChair(req, res); + }); + + CROW_ROUTE(app, "/findCourseLocation") + .methods(crow::HTTPMethod::GET)([this](const crow::request& req, + crow::response& res) { + findCourseLocation(req, res); + }); + + CROW_ROUTE(app, "/findCourseInstructor") + .methods(crow::HTTPMethod::GET)([this](const crow::request& req, + crow::response& res) { + findCourseInstructor(req, res); + }); + + CROW_ROUTE(app, "/findCourseTime") + .methods(crow::HTTPMethod::GET)([this](const crow::request& req, + crow::response& res) { + findCourseTime(req, res); + }); + + CROW_ROUTE(app, "/addMajorToDept") + .methods(crow::HTTPMethod::GET)([this](const crow::request& req, + crow::response& res) { + addMajorToDept(req, res); + }); + + CROW_ROUTE(app, "/removeMajorFromDept") + .methods(crow::HTTPMethod::GET)([this](const crow::request& req, + crow::response& res) { + removeMajorFromDept(req, res); + }); + + CROW_ROUTE(app, "/changeCourseLocation") + .methods(crow::HTTPMethod::PATCH)([this](const crow::request& req, + crow::response& res) { + setCourseLocation(req, res); + }); + + CROW_ROUTE(app, "/changeCourseTeacher") + .methods(crow::HTTPMethod::PATCH)([this](const crow::request& req, + crow::response& res) { + setCourseInstructor(req, res); + }); + + CROW_ROUTE(app, "/changeCourseTime") + .methods(crow::HTTPMethod::PATCH)([this](const crow::request& req, + crow::response& res) { + setCourseTime(req, res); + }); + + CROW_ROUTE(app, "/setEnrollmentCount") + .methods(crow::HTTPMethod::PATCH)([this](const crow::request& req, + crow::response& res) { + setEnrollmentCount(req, res); + }); } void RouteController::setDatabase(MyFileDatabase *db) { - myFileDatabase = db; + myFileDatabase = db; } diff --git a/IndividualMiniprojectC++/src/main.cpp b/IndividualMiniprojectC++/src/main.cpp index bdce13c03..512c9ff45 100644 --- a/IndividualMiniprojectC++/src/main.cpp +++ b/IndividualMiniprojectC++/src/main.cpp @@ -1,40 +1,42 @@ -#include "crow.h" +// Copyright Richard Cruz-Silva +#include +#include +#include +#include +#include "./crow.h" #include "Course.h" #include "Department.h" #include "MyFileDatabase.h" #include "RouteController.h" #include "Globals.h" #include "MyApp.h" -#include -#include -#include -#include + /** * Method to handle proper termination protocols */ void signalHandler(int signal) { - if (signal == SIGINT || signal == SIGTERM) { - MyApp::onTermination(); - std::exit(signal); - } + if (signal == SIGINT || signal == SIGTERM) { + MyApp::onTermination(); + std::exit(signal); + } } /** * Sets up the HTTP server and runs the program */ int main(int argc, char* argv[]) { - std::string mode = argc > 1 ? argv[1] : "run"; - MyApp::run(mode); + std::string mode = argc > 1 ? argv[1] : "run"; + MyApp::run(mode); + + crow::SimpleApp app; + app.signal_clear(); + std::signal(SIGINT, signalHandler); + std::signal(SIGTERM, signalHandler); - crow::SimpleApp app; - app.signal_clear(); - std::signal(SIGINT, signalHandler); - std::signal(SIGTERM, signalHandler); - - RouteController routeController; - routeController.initRoutes(app); - routeController.setDatabase(MyApp::getDatabase()); - app.port(8080).multithreaded().run(); - return 0; + RouteController routeController; + routeController.initRoutes(app); + routeController.setDatabase(MyApp::getDatabase()); + app.port(8080).multithreaded().run(); + return 0; } diff --git a/IndividualMiniprojectC++/test/CourseUnitTests.cpp b/IndividualMiniprojectC++/test/CourseUnitTests.cpp index eb2e2d5f7..5ad97c738 100644 --- a/IndividualMiniprojectC++/test/CourseUnitTests.cpp +++ b/IndividualMiniprojectC++/test/CourseUnitTests.cpp @@ -1,22 +1,86 @@ +// Copyright 2024 Richard Cruz-Silva #include -#include "Course.h" +#include "Course.h" class CourseUnitTests : public ::testing::Test { -protected: - static Course* testCourse; + protected: + static Course* testCourse; - static void SetUpTestSuite() { - testCourse = new Course(250, "Griffin Newbold", "417 IAB", "11:40-12:55"); - } + static void SetUpTestSuite() { + testCourse = new Course(250, "Griffin Newbold", "417 IAB", "11:40-12:55"); + } - static void TearDownTestSuite() { - delete testCourse; - } + static void TearDownTestSuite() { + delete testCourse; + } }; Course* CourseUnitTests::testCourse = nullptr; TEST_F(CourseUnitTests, ToStringTest) { - std::string expectedResult = "\nInstructor: Griffin Newbold; Location: 417 IAB; Time: 11:40-12:55"; - ASSERT_EQ(expectedResult, testCourse->display()); + std::string expectedResult = "\nInstructor: Griffin Newbold; Location: 417 IAB; Time: 11:40-12:55"; + ASSERT_EQ(expectedResult, testCourse->display()); } + +TEST_F(CourseUnitTests, EmptyConstructor) { + Course emptyCourse; + std::string expectedLocation = ""; + ASSERT_EQ(expectedLocation, emptyCourse.getCourseLocation()); +} + +TEST_F(CourseUnitTests, isCourseFull) { + Course fullCourse(100, "", "", ""); + fullCourse.setEnrolledStudentCount(100); + ASSERT_TRUE(fullCourse.isCourseFull()); + fullCourse.setEnrolledStudentCount(99); + ASSERT_FALSE(fullCourse.isCourseFull()); +} + +TEST_F(CourseUnitTests, enrollStudent) { + Course studentCourse(100, "", "", ""); + + studentCourse.setEnrolledStudentCount(100); + ASSERT_FALSE(studentCourse.enrollStudent()); + + studentCourse.setEnrolledStudentCount(200); + ASSERT_FALSE(studentCourse.enrollStudent()); + + studentCourse.setEnrolledStudentCount(99); + ASSERT_TRUE(studentCourse.enrollStudent()); +} + +TEST_F(CourseUnitTests, dropStudent) { + testCourse->setEnrolledStudentCount(50); + ASSERT_TRUE(testCourse->dropStudent()); + testCourse->setEnrolledStudentCount(0); + ASSERT_FALSE(testCourse->dropStudent()); +} + +TEST_F(CourseUnitTests, InstructorName) { + ASSERT_EQ(testCourse->getInstructorName(), "Griffin Newbold"); + std::string newInstructor = "New Teach"; + testCourse->reassignInstructor(newInstructor); + ASSERT_EQ(testCourse->getInstructorName(), newInstructor); +} + +TEST_F(CourseUnitTests, TimeSlot) { + ASSERT_EQ(testCourse->getCourseTimeSlot(), "11:40-12:55"); + std::string newTime = "10:40-11:55"; + testCourse->reassignTime(newTime); + ASSERT_EQ(testCourse->getCourseTimeSlot(), newTime); +} + +TEST_F(CourseUnitTests, Location) { + ASSERT_EQ(testCourse->getCourseLocation(), "417 IAB"); + std::string newLocation = "420 ACB"; + testCourse->reassignLocation(newLocation); + ASSERT_EQ(testCourse->getCourseLocation(), newLocation); +} + +TEST_F(CourseUnitTests, serilaize) { + //testCourse->serialize(std::cout); +} + +TEST_F(CourseUnitTests, deserialize) { + //testCourse->deserialize(std::cin); +} \ No newline at end of file diff --git a/IndividualMiniprojectC++/test/DepartmentUnitTests.cpp b/IndividualMiniprojectC++/test/DepartmentUnitTests.cpp new file mode 100644 index 000000000..f44fa885d --- /dev/null +++ b/IndividualMiniprojectC++/test/DepartmentUnitTests.cpp @@ -0,0 +1,97 @@ +// Copyright 2024 Richard Cruz-Silva +#include +#include "Department.h" + +class DepartmentUnitTests : public ::testing::Test { + protected: + static Department* testDepartment; + + static void SetUpTestSuite() { + std::string times[] = {"11:40-12:55", "4:10-5:25", + "10:10-11:25", "2:40-3:55"}; + std::string locations[] = {"417 IAB", "309 HAV", "301 URIS"}; + + // Data for COMS department + auto coms1004 = std::make_shared(400, "Adam Cannon", + locations[0], times[0]); + coms1004->setEnrolledStudentCount(249); + auto coms3134 = std::make_shared(250, "Brian Borowski", + locations[2], times[1]); + coms3134->setEnrolledStudentCount(242); + auto coms3157 = std::make_shared(400, "Jae Lee", + locations[0], times[1]); + coms3157->setEnrolledStudentCount(311); + auto coms3203 = std::make_shared(250, "Ansaf Salleb-Aouissi", + locations[2], times[2]); + coms3203->setEnrolledStudentCount(215); + auto coms3261 = std::make_shared(150, "Josh Alman", + locations[0], times[3]); + coms3261->setEnrolledStudentCount(140); + auto coms3251 = std::make_shared(125, "Tony Dear", + "402 CHANDLER", "1:10-3:40"); + coms3251->setEnrolledStudentCount(99); + auto coms3827 = std::make_shared(300, "Daniel Rubenstein", + "207 Math", times[2]); + coms3827->setEnrolledStudentCount(283); + auto coms4156 = std::make_shared(120, "Gail Kaiser", + "501 NWC", times[2]); + coms4156->setEnrolledStudentCount(109); + + std::map> courses; + courses["1004"] = coms1004; + courses["3134"] = coms3134; + courses["3157"] = coms3157; + courses["3203"] = coms3203; + courses["3261"] = coms3261; + courses["3251"] = coms3251; + courses["3827"] = coms3827; + courses["4156"] = coms4156; + + testDepartment = new Department("COMS", courses, "Luca Carloni", 2700); + } + + static void TearDownTestSuite() { + for (auto& item : testDepartment->getCourseSelection()) + item.second.reset(); + delete testDepartment; + } +}; + +Department* DepartmentUnitTests::testDepartment = nullptr; + +TEST_F(DepartmentUnitTests, emptyConstructor) { + Department department; + ASSERT_EQ(department.getNumberOfMajors(), 0); +} + +TEST_F(DepartmentUnitTests, NumberOfMajors) { + ASSERT_EQ(testDepartment->getNumberOfMajors(), 2700); + testDepartment->addPersonToMajor(); + ASSERT_EQ(testDepartment->getNumberOfMajors(), 2701); + testDepartment->dropPersonFromMajor(); + testDepartment->dropPersonFromMajor(); + ASSERT_EQ(testDepartment->getNumberOfMajors(), 2699); +} + +TEST_F(DepartmentUnitTests, DepartmentChair) { + ASSERT_EQ(testDepartment->getDepartmentChair(), "Luca Carloni"); +} + +TEST_F(DepartmentUnitTests, ToString) { + std::ostringstream expectedString; + for (const auto& it : testDepartment->getCourseSelection()) { + expectedString << "COMS" << " " << it.first << ": " + << it.second->display() << "\n"; + } + ASSERT_EQ(expectedString.str(), testDepartment->display()); +} + +TEST_F(DepartmentUnitTests, AddCourses) { + auto courses = testDepartment->getCourseSelection(); + std::string newId = "9999"; + ASSERT_EQ(courses.find(newId), courses.end()); + testDepartment->createCourse(newId, "Albert Einstein", "111 ABC", + "1:10-3:40", 60); + courses = testDepartment->getCourseSelection(); + ASSERT_NE(courses.find(newId), courses.end()); +} \ No newline at end of file diff --git a/IndividualMiniprojectC++/test/MyFileDatabaseUnitTests.cpp b/IndividualMiniprojectC++/test/MyFileDatabaseUnitTests.cpp new file mode 100644 index 000000000..c8d15ce45 --- /dev/null +++ b/IndividualMiniprojectC++/test/MyFileDatabaseUnitTests.cpp @@ -0,0 +1,236 @@ +// Copyright 2024 Richard Cruz-Silva +#include +#include "MyFileDatabase.h" +//#include + +class MyFileDatabaseUnitTests : public ::testing::Test { + protected: + static MyFileDatabase* testDatabase; + + static void SetUpTestSuite() { + testDatabase = new MyFileDatabase(1, "unittestsfile.bin"); + + std::string times[] = {"11:40-12:55", "4:10-5:25", + "10:10-11:25", "2:40-3:55"}; + std::string locations[] = {"417 IAB", "309 HAV", "301 URIS"}; + + // Data for COMS department + auto coms1004 = std::make_shared(400, "Adam Cannon", + locations[0], times[0]); + coms1004->setEnrolledStudentCount(249); + auto coms3134 = std::make_shared(250, "Brian Borowski", + locations[2], times[1]); + coms3134->setEnrolledStudentCount(242); + auto coms3157 = std::make_shared(400, "Jae Lee", + locations[0], times[1]); + coms3157->setEnrolledStudentCount(311); + auto coms3203 = std::make_shared(250, "Ansaf Salleb-Aouissi", + locations[2], times[2]); + coms3203->setEnrolledStudentCount(215); + auto coms3261 = std::make_shared(150, "Josh Alman", + locations[0], times[3]); + coms3261->setEnrolledStudentCount(140); + auto coms3251 = std::make_shared(125, "Tony Dear", + "402 CHANDLER", "1:10-3:40"); + coms3251->setEnrolledStudentCount(99); + auto coms3827 = std::make_shared(300, "Daniel Rubenstein", + "207 Math", times[2]); + coms3827->setEnrolledStudentCount(283); + auto coms4156 = std::make_shared(120, "Gail Kaiser", + "501 NWC", times[2]); + coms4156->setEnrolledStudentCount(109); + + std::map> courses; + courses["1004"] = coms1004; + courses["3134"] = coms3134; + courses["3157"] = coms3157; + courses["3203"] = coms3203; + courses["3261"] = coms3261; + courses["3251"] = coms3251; + courses["3827"] = coms3827; + courses["4156"] = coms4156; + + Department coms("COMS", courses, "Luca Carloni", 2700); + + // Data for ECON department + auto econ1105 = std::make_shared(210, "Waseem Noor", + locations[1], times[3]); + econ1105->setEnrolledStudentCount(187); + auto econ2257 = std::make_shared(125, "Tamrat Gashaw", + "428 PUP", times[2]); + econ2257->setEnrolledStudentCount(63); + auto econ3211 = std::make_shared(96, "Murat Yilmaz", + "310 FAY", times[1]); + econ3211->setEnrolledStudentCount(81); + auto econ3213 = std::make_shared(86, "Miles Leahey", + "702 HAM", times[1]); + econ3213->setEnrolledStudentCount(77); + auto econ3412 = std::make_shared(86, "Thomas Piskula", + "702 HAM", times[0]); + econ3412->setEnrolledStudentCount(81); + auto econ4415 = std::make_shared(110, "Evan D Sadler", + locations[1], times[2]); + econ4415->setEnrolledStudentCount(63); + auto econ4710 = std::make_shared(86, "Matthieu Gomez", + "517 HAM", "8:40-9:55"); + econ4710->setEnrolledStudentCount(37); + auto econ4840 = std::make_shared(108, "Mark Dean", + "142 URIS", times[3]); + econ4840->setEnrolledStudentCount(67); + + courses.clear(); + courses["1105"] = econ1105; + courses["2257"] = econ2257; + courses["3211"] = econ3211; + courses["3213"] = econ3213; + courses["3412"] = econ3412; + courses["4415"] = econ4415; + courses["4710"] = econ4710; + courses["4840"] = econ4840; + + Department econ("ECON", courses, "Michael Woodford", 2345); + + // Data for IEOR department + auto ieor2500 = std::make_shared(50, "Uday Menon", + "627 MUDD", times[0]); + ieor2500->setEnrolledStudentCount(52); + auto ieor3404 = std::make_shared(73, "Christopher J Dolan", + "303 MUDD", times[2]); + ieor3404->setEnrolledStudentCount(80); + auto ieor3658 = std::make_shared(96, "Daniel Lacker", + "310 FAY", times[2]); + ieor3658->setEnrolledStudentCount(87); + auto ieor4102 = std::make_shared(110, "Antonius B Dieker", + "209 HAM", times[2]); + ieor4102->setEnrolledStudentCount(92); + auto ieor4106 = std::make_shared(150, "Kaizheng Wang", + "501 NWC", times[2]); + ieor4106->setEnrolledStudentCount(161); + auto ieor4405 = std::make_shared(80, "Yuri Faenza", + "517 HAV", times[0]); + ieor4405->setEnrolledStudentCount(19); + auto ieor4511 = std::make_shared(150, "Michael Robbins", + "633 MUDD", "9:00-11:30"); + ieor4511->setEnrolledStudentCount(50); + auto ieor4540 = std::make_shared(60, "Krzysztof M Choromanski", + "633 MUDD", "7:10-9:40"); + ieor4540->setEnrolledStudentCount(33); + + courses.clear(); + courses["2500"] = ieor2500; + courses["3404"] = ieor3404; + courses["3658"] = ieor3658; + courses["4102"] = ieor4102; + courses["4106"] = ieor4106; + courses["4405"] = ieor4405; + courses["4511"] = ieor4511; + courses["4540"] = ieor4540; + + Department ieor("IEOR", courses, "Jay Sethuraman", 67); + + // Data for CHEM department + auto chem1403 = std::make_shared(120, "Ruben M Savizky", + locations[1], "6:10-7:25"); + chem1403->setEnrolledStudentCount(100); + auto chem1500 = std::make_shared(46, "Joseph C Ulichny", + "302 HAV", "6:10-9:50"); + chem1500->setEnrolledStudentCount(50); + auto chem2045 = std::make_shared(50, "Luis M Campos", + "209 HAV", "1:10-2:25"); + chem2045->setEnrolledStudentCount(29); + auto chem2444 = std::make_shared(150, "Christopher Eckdahl", + locations[1], times[0]); + chem2444->setEnrolledStudentCount(150); + auto chem2494 = std::make_shared(24, "Talha Siddiqui", + "202 HAV", "1:10-5:00"); + chem2494->setEnrolledStudentCount(18); + auto chem3080 = std::make_shared(60, "Milan Delor", + "209 HAV", times[2]); + chem3080->setEnrolledStudentCount(18); + auto chem4071 = std::make_shared(42, "Jonathan S Owen", + "320 HAV", "8:40-9:55"); + chem4071->setEnrolledStudentCount(29); + auto chem4102 = std::make_shared(28, "Dalibor Sames", + "320 HAV", times[2]); + chem4102->setEnrolledStudentCount(27); + + courses.clear(); + courses["1403"] = chem1403; + courses["1500"] = chem1500; + courses["2045"] = chem2045; + courses["2444"] = chem2444; + courses["2494"] = chem2494; + courses["3080"] = chem3080; + courses["4071"] = chem4071; + courses["4102"] = chem4102; + + Department chem("CHEM", courses, "Laura J. Kaufman", 250); + + // Data for PHYS department + auto phys1001 = std::make_shared(150, "Szabolcs Marka", + "301 PUP", times[3]); + phys1001->setEnrolledStudentCount(125); + auto phys1221 = std::make_shared(150, "James G. Mccann", + "301 PUP", "4:10-5:25"); + phys1221->setEnrolledStudentCount(118); + auto phys1520 = std::make_shared(400, "Victor G. Moffat", + "630 MUDD", times[1]); + phys1520->setEnrolledStudentCount(400); + auto phys2000 = std::make_shared(100, "Frank E. L. Banta", + "402 CHANDLER", "1:10-3:40"); + phys2000->setEnrolledStudentCount(98); + auto phys3801 = std::make_shared(150, "Katherine M. McMahon", + "603 MUDD", "4:10-5:25"); + phys3801->setEnrolledStudentCount(96); + auto phys4205 = std::make_shared(60, "Michael P. Larkin", + locations[1], "6:10-9:50"); + phys4205->setEnrolledStudentCount(60); + + courses.clear(); + courses["1001"] = phys1001; + courses["1221"] = phys1221; + courses["1520"] = phys1520; + courses["2000"] = phys2000; + courses["3801"] = phys3801; + courses["4205"] = phys4205; + + Department phys("PHYS", courses, "Marcia L. Newson", 200); + + // Setup mapping + std::map mapping; + mapping["COMS"] = coms; + mapping["ECON"] = econ; + mapping["IEOR"] = ieor; + mapping["CHEM"] = chem; + mapping["PHYS"] = phys; + + testDatabase->setMapping(mapping); + } + + static void TearDownTestSuite() { + delete testDatabase; + } +}; + +MyFileDatabase* MyFileDatabaseUnitTests::testDatabase = nullptr; + +TEST_F(MyFileDatabaseUnitTests, WriteToFile) { + testDatabase->saveContentsToFile(); + //boost::filesystem::path path("unittestsfile.bin"); + //auto size = boost::filesystem::file_size("testfile.bin"); + ASSERT_NE(-1, 0); + + MyFileDatabase newTest(0, "unittestsfile.bin"); + auto mapping = newTest.getDepartmentMapping(); + ASSERT_NE(mapping.find("PHYS"), mapping.end()); +} + +TEST_F(MyFileDatabaseUnitTests, ToString) { + std::string expectedString; + auto mapping = testDatabase->getDepartmentMapping(); + for (const auto& it : mapping) { + expectedString += "For the " + it.first + " department:\n" + + it.second.display() + "\n"; + } + ASSERT_EQ(expectedString, testDatabase->display()); +} \ No newline at end of file diff --git a/IndividualMiniprojectC++/test/RouteControllerUnitTests.cpp b/IndividualMiniprojectC++/test/RouteControllerUnitTests.cpp new file mode 100644 index 000000000..90ca51b48 --- /dev/null +++ b/IndividualMiniprojectC++/test/RouteControllerUnitTests.cpp @@ -0,0 +1,170 @@ +// Copyright 2024 Richard Cruz-Silva +#include +#include "RouteController.h" +#include "MyApp.h" + +class RouteControllerUnitTests : public ::testing::Test { + protected: + static RouteController* testController; + + static void SetUpTestSuite() { + MyApp::run(""); + + crow::SimpleApp app; + app.signal_clear(); + + testController = new RouteController(); + testController->initRoutes(app); + testController->setDatabase(MyApp::getDatabase()); + } + + static void TearDownTestSuite() { + delete testController; + } +}; + +RouteController* RouteControllerUnitTests::testController = nullptr; + +TEST_F(RouteControllerUnitTests, index) { + crow::response res; + testController->index(res); + + std::string expectedString = "Welcome, in order to make an API call direct your browser or Postman to an endpoint " + "\n\nThis can be done using the following format: \n\nhttp://127.0.0.1:8080/endpoint?arg=value"; + ASSERT_EQ(res.body, expectedString); +} + +TEST_F(RouteControllerUnitTests, retrieveDepartment) { + crow::request req; + crow::response res; + + testController->retrieveDepartment(req, res); + + ASSERT_EQ("An error has occurred", res.body); +} + +TEST_F(RouteControllerUnitTests, retrieveCourse) { + crow::request req; + crow::response res; + + testController->retrieveCourse(req, res); + + ASSERT_EQ("An error has occurred", res.body); +} + +TEST_F(RouteControllerUnitTests, isCourseFull) { + crow::request req; + crow::response res; + + testController->isCourseFull(req, res); + + ASSERT_EQ("An error has occurred", res.body); +} + +TEST_F(RouteControllerUnitTests, getMajorCountFromDept) { + crow::request req; + crow::response res; + + testController->getMajorCountFromDept(req, res); + + ASSERT_EQ("An error has occurred", res.body); +} + +TEST_F(RouteControllerUnitTests, identifyDeptChair) { + crow::request req; + crow::response res; + + testController->identifyDeptChair(req, res); + + ASSERT_EQ("An error has occurred", res.body); +} + +TEST_F(RouteControllerUnitTests, findCourseLocation) { + crow::request req; + crow::response res; + + testController->findCourseLocation(req, res); + + ASSERT_EQ("An error has occurred", res.body); +} + +TEST_F(RouteControllerUnitTests, findCourseInstructor) { + crow::request req; + crow::response res; + + testController->findCourseInstructor(req, res); + + ASSERT_EQ("An error has occurred", res.body); +} + +TEST_F(RouteControllerUnitTests, findCourseTime) { + crow::request req; + crow::response res; + + testController->findCourseTime(req, res); + + ASSERT_EQ("An error has occurred", res.body); +} + +TEST_F(RouteControllerUnitTests, addMajorToDept) { + crow::request req; + crow::response res; + + testController->addMajorToDept(req, res); + + ASSERT_EQ("An error has occurred", res.body); +} + +TEST_F(RouteControllerUnitTests, setEnrollmentCount) { + crow::request req; + crow::response res; + + testController->setEnrollmentCount(req, res); + + ASSERT_EQ("An error has occurred", res.body); +} + +TEST_F(RouteControllerUnitTests, setCourseLocation) { + crow::request req; + crow::response res; + + testController->setCourseLocation(req, res); + + ASSERT_EQ("An error has occurred", res.body); +} + +TEST_F(RouteControllerUnitTests, setCourseInstructor) { + crow::request req; + crow::response res; + + testController->setCourseInstructor(req, res); + + ASSERT_EQ("An error has occurred", res.body); +} + +TEST_F(RouteControllerUnitTests, setCourseTime) { + crow::request req; + crow::response res; + + testController->setCourseTime(req, res); + + ASSERT_EQ("An error has occurred", res.body); +} + +TEST_F(RouteControllerUnitTests, removeMajorFromDept) { + crow::request req; + crow::response res; + + testController->removeMajorFromDept(req, res); + + ASSERT_EQ("An error has occurred", res.body); +} + +TEST_F(RouteControllerUnitTests, dropStudentFromCourse) { + crow::request req; + crow::response res; + + testController->dropStudentFromCourse(req, res); + + ASSERT_EQ("An error has occurred", res.body); +} \ No newline at end of file diff --git a/IndividualMiniprojectC++/test/sample.cpp b/IndividualMiniprojectC++/test/sample.cpp index 5a57e138f..533a54d04 100644 --- a/IndividualMiniprojectC++/test/sample.cpp +++ b/IndividualMiniprojectC++/test/sample.cpp @@ -1,3 +1,4 @@ +// Copyright 2024 Richard Cruz-Silva #include // Demonstrate some basic assertions. diff --git a/bugs.txt b/bugs.txt new file mode 100644 index 000000000..3f8c30c69 --- /dev/null +++ b/bugs.txt @@ -0,0 +1,61 @@ +Course.cpp:14:20: function definition parameter name 'capacity' does not match +function declartion parameter name 'count' [funcArgNamesDifferent] + Fixed by updating Course.h parameter name to 'capacity' + +Department.cpp:21:41: Member variable 'Department::deptCode' is in the wrong +place in the initializer list. [initializerList] + Fixed by updating intializer list to correspond to Department.h + +Department.cpp:22:5: Member variable 'Department::numberOfMajors' is in the +wrong place in the initializer list. [initializerList] + Fixed by updating intializer list to correspond to Department.h + +Department.cpp:40:25: Technically the member function +'Department::getDepartmentChair' can be static (but you may consider moving to +unnamed namespace). [functionStatic] + This bug appear because the function returns a string literal instead of the + member variable 'departmentChair'. Fixed by removing the quotes. + +Department.cpp:74:40: performance: Function parameter 'courseId' should be +passed by const reference. [passedByValue] + Fixed by changing to const reference. + +Department.cpp:88:43: performance: Function parameter 'courseId' should be +passed by const reference. [passedByValue] + Fixed by changing to const reference. + +Department.cpp:19:49: performance: Function parameter 'courses' should be +passed by const reference. [passedByValue] + Fixed by changing to const reference. + +RouteController.h:8:1: style: The class 'RouteController' does not declare a +constructor although it has private member variables which likely require +initialization. [noConstructor] + Fixed by created a constructor for RouteController. + +Course.cpp:58: getCourseTimeSlot() returns instructorName. + Fixed by returning courseTimeSlot. + +Course.cpp:53: getInstructorName() returns courseTimeSlot. + Fixed by returning instructorName. + +Course.cpp:67: function is printing to std::cout when it should not do that +in production + Fixed by commenting out line + +Course.cpp:70: function is printing to std::cout when it should not do that +in production + Fixed by commenting out line + +Course.cpp:44: dropStudent() always returns false. + Fixed logic to return correct boolean. + +Course.cpp:34: enrollStudent() always returns false. + Fixed logic to return correct boolean. + +Course.cpp:88: setEnrolledStudentCount might set student count to negative +number that is nonsensical in this context. + Changed logic to not make any changes if a negative number is passed in. + +Course.cpp:92: isCourseFull() has wrong logic + Fixed logic to return correct boolean diff --git a/citations.txt b/citations.txt new file mode 100644 index 000000000..424109622 --- /dev/null +++ b/citations.txt @@ -0,0 +1,5 @@ +This link gave me the idea to use lcov and integrate it with CMake +https://danielsieger.com/blog/2022/03/06/code-coverage-for-cpp.html + +This link gave me the code to get rid of unwanted files in the lcov report +https://www.reddit.com/r/cpp_questions/comments/16uapml/gcov_command_to_exclude_files_from_coverage/ diff --git a/honesty.txt b/honesty.txt new file mode 100644 index 000000000..6310f9ddc --- /dev/null +++ b/honesty.txt @@ -0,0 +1,25 @@ +I, Richard Cruz-Silva (rsc2174)>, have read and understood the following: + +1. CS department's Policies and Procedures on Academic Honesty +2. The Course Specific Academic Honesty Policies +3. The assignment specs outlining the consequences of not submitting this + pledge and other aspects of the policy + +I affirm that I will abide by all the policies stated in the relevant materials +from above. I understand that the relevant policies apply to: individual +assignments, group projects, and individual examinations. + +I also affirm that I understand that all course materials, with the exception of +the individual/group project, are subject to the appropriate copyrights and thus +will not post them on any public forum or publicly hosted repository, this +includes but is not limited to: GitHub, stackoverflow, chegg etc. + +I also affirm that I will be 100% honest when evaluating the performance of +myself and my teammates when prompted by an assignment or member of the +teaching staff. + +Finally I affirm that I will not attempt to find any loopholes in these policies +for the benefit of myself or others enrolled in the course presently or possibly +in the future. + +Signed: Richard Cruz-Silva (rsc2174) Sept. 11 2024