Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add an API for submitting sketches to a class #72 #145

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions handler/class.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,32 @@ func JoinClass(cc echo.Context) error {

return c.JSON(http.StatusOK, class)
}

func SubmitAssignment(cc echo.Context) error {
req := struct {
submissionPID string `json:"submissionPID"`// PID of the program being submitted
assignmentPID string `json:"assignmentPID"` // PID of the program/assignment this is being submitted to. Potentially optional
uid string `json:"uid"` // UID of the submitting user
cid string `json:"cid"` // Class ID
}{}

c := cc.(*db.DBContext)

// read JSON from request body
if err := httpext.RequestBodyTo(c.Request(), &req); err != nil {
return c.String(http.StatusInternalServerError, err.Error())
}
if req.submissionPID.uid == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if req.submissionPID.uid == "" {
if req.submissionPID == "" {

return c.String(http.StatusBadRequest, "submission PID is required")
}
if req.assignmentPID.uid == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if req.assignmentPID.uid == "" {
if req.assignmentPID == "" {

return c.String(http.StatusBadRequest, "assignment PID is required")
}
if req.uid == "" {
return c.String(http.StatusBadRequest, "uid is required")
}
if req.cid == "" {
return c.String(http.StatusBadRequest, "cid is required")
}
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, if you just add return nil at the end of the function, it should work as expected

1 change: 1 addition & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func serve(c *cli.Context) error {
e.PUT("/class/join", handler.JoinClass)
e.PUT("/class/leave", d.LeaveClass)
e.POST("/class/members", d.GetClassMembers)
e.POST("/class/submit", handler.SubmitAssignment)

// collaborative coding management
e.POST("/collab/create", d.CreateCollab)
Expand Down