-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IGC: Grade Calculator (v1) #144
Changes from all commits
1d43a3d
bb58b72
42af1fd
1e4c5da
9e9c389
cf6cc61
1cf2769
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// | ||
// GetAssignmentGroupsRequest.swift | ||
// CanvasPlusPlayground | ||
// | ||
// Created by Rahul on 12/26/24. | ||
// | ||
|
||
import Foundation | ||
|
||
struct GetAssignmentGroupsRequest: ArrayAPIRequest { | ||
typealias Subject = AssignmentGroup | ||
|
||
let courseId: String | ||
|
||
// Path for the request | ||
var path: String { "courses/\(courseId)/assignment_groups" } | ||
|
||
// Query parameters | ||
var queryParameters: [QueryParameter] { | ||
[ | ||
("override_assignment_dates", overrideAssignmentDates), | ||
("grading_period_id", gradingPeriodId), | ||
("scope_assignments_to_student", scopeAssignmentsToStudent) | ||
] | ||
+ include.map { ("include[]", $0) } | ||
+ assignmentIds.map { ("assignment_ids[]", $0) } | ||
+ excludeAssignmentSubmissionTypes.map { ("exclude_assignment_submission_types[]", $0) } | ||
} | ||
|
||
// MARK: Query Params | ||
let include: [String] | ||
let assignmentIds: [String] | ||
let excludeAssignmentSubmissionTypes: [String] | ||
let overrideAssignmentDates: Bool? | ||
let gradingPeriodId: Int? | ||
let scopeAssignmentsToStudent: Bool? | ||
|
||
// Initializer | ||
init( | ||
courseId: String, | ||
include: [String] = [], | ||
assignmentIds: [String] = [], | ||
excludeAssignmentSubmissionTypes: [String] = [], | ||
overrideAssignmentDates: Bool? = nil, | ||
gradingPeriodId: Int? = nil, | ||
scopeAssignmentsToStudent: Bool? = nil | ||
) { | ||
self.courseId = courseId | ||
self.include = include | ||
self.assignmentIds = assignmentIds | ||
self.excludeAssignmentSubmissionTypes = excludeAssignmentSubmissionTypes | ||
self.overrideAssignmentDates = overrideAssignmentDates | ||
self.gradingPeriodId = gradingPeriodId | ||
self.scopeAssignmentsToStudent = scopeAssignmentsToStudent | ||
} | ||
|
||
/* MARK: Request Caching (Optional Implementation) | ||
var requestId: Int? { courseId.asInt } | ||
var requestIdKey: ParentKeyPath<AssignmentGroup, Int?> { .createReadable(\.courseId) } | ||
var idPredicate: Predicate<AssignmentGroup> { | ||
#Predicate<AssignmentGroup> { group in | ||
group.courseId == requestId | ||
} | ||
} | ||
|
||
var customPredicate: Predicate<AssignmentGroup> { | ||
let ids = assignmentIds.compactMap(\.?.asInt) | ||
let assignmentIdsPred = assignmentIds.isEmpty ? .true : #Predicate<AssignmentGroup> { group in | ||
ids.contains(group.id) | ||
} | ||
return assignmentIdsPred | ||
} | ||
*/ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,28 +10,39 @@ import SwiftUI | |
@Observable | ||
class CourseAssignmentManager { | ||
private let courseID: String? | ||
var assignments = [Assignment]() | ||
var assignmentGroups: [AssignmentGroup] = [] | ||
|
||
init(courseID: String?) { | ||
self.courseID = courseID | ||
} | ||
|
||
func fetchAssignments() async { | ||
guard let courseID = courseID, let (data, _) = try? await CanvasService.shared.fetchResponse(CanvasRequest.getAssignments(courseId: courseID)) else { | ||
print("Failed to fetch assignments.") | ||
func fetchAssignmentGroups() async { | ||
guard let courseID = courseID, let (data, _) = try? await CanvasService.shared.fetchResponse( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
CanvasRequest.getAssignmentGroups(courseId: courseID) | ||
) else { | ||
print("Failed to fetch assignment groups.") | ||
return | ||
} | ||
|
||
self.assignmentGroups = (try? JSONDecoder().decode([AssignmentGroup].self, from: data)) ?? [] | ||
} | ||
|
||
static func getAssignmentsForCourse(courseID: String) async -> [Assignment] { | ||
await CourseAssignmentManager.fetchAssignments(courseID: courseID) | ||
} | ||
|
||
private static func fetchAssignments(courseID: String) async -> [Assignment] { | ||
guard let (data, _) = try? await CanvasService.shared.fetchResponse(CanvasRequest.getAssignments(courseId: courseID)) else { | ||
print("Failed to fetch assignments.") | ||
return [] | ||
} | ||
|
||
Comment on lines
+30
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't the getAssignmentsForCourse redundant? Other than the name making more sense |
||
do { | ||
self.assignments = try JSONDecoder().decode([Assignment].self, from: data) | ||
return try JSONDecoder().decode([Assignment].self, from: data) | ||
} catch { | ||
print(error) | ||
} | ||
} | ||
|
||
static func getAssignmentsForCourse(courseID: String) async -> [Assignment] { | ||
let manager = CourseAssignmentManager(courseID: courseID) | ||
await manager.fetchAssignments() | ||
return manager.assignments | ||
|
||
return [] | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should note now, use
createWritable
when the property (courseId
in this case) doesn't come with fetch result. This allows the service layer to set that property before returning it. e.g. SincecourseId
isn't in assignment group by default, you probs wanna make itcreateWritable
.