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

Feature/react query (KHO-262, KHO-263) #173

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8c83e72
add githubuser + user loading
ntietje1 Dec 13, 2024
485f6b5
improve link generation efficiency
ntietje1 Dec 13, 2024
41f6dff
add react query + better error & loading states
ntietje1 Dec 13, 2024
30462a3
replace old spinner
ntietje1 Dec 13, 2024
e8dee54
Merge branch 'main' into feature/react-query
ntietje1 Dec 13, 2024
9370417
add missing imports
ntietje1 Dec 13, 2024
c86979a
Merge branch 'main' into feature/react-query
ntietje1 Dec 13, 2024
a4aa3c8
merge fix
ntietje1 Dec 13, 2024
df59761
fix bad merge div
ntietje1 Dec 13, 2024
b83e24b
Merge branch 'main' into feature/react-query
ntietje1 Dec 16, 2024
aaee543
improve loading state appearence
ntietje1 Dec 16, 2024
bca24d1
fix orgID key
ntietje1 Dec 16, 2024
77dce96
add cacheing, loading, and error states to grading tab
ntietje1 Dec 16, 2024
68baef8
add empty banner to grading and rubric tabs
ntietje1 Dec 16, 2024
3c83a03
make create assignent button primary
ntietje1 Dec 16, 2024
a2a545a
use react query for auth calls
ntietje1 Dec 17, 2024
4afadad
reactquery for userlist
ntietje1 Dec 17, 2024
bb86c10
Merge branch 'main' into feature/react-query
ntietje1 Dec 17, 2024
f1b1deb
add disabled button
ntietje1 Dec 18, 2024
4e61f24
fix error case
ntietje1 Dec 18, 2024
d771b18
fix login issue
ntietje1 Dec 18, 2024
d50e3c5
Merge branch 'main' into feature/react-query
ntietje1 Dec 18, 2024
68d47c1
remove unused navigate
ntietje1 Dec 18, 2024
a5831a2
hotfix assignment template function
ntietje1 Dec 19, 2024
3edb3b2
Merge branch 'main' of https://github.com/NUSpecialProjects/khoury-cl…
ntietje1 Dec 19, 2024
4c6c96d
Merge branch 'main' into feature/react-query
ntietje1 Dec 19, 2024
1e1a98d
update metric call to use react query
ntietje1 Dec 19, 2024
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
12 changes: 10 additions & 2 deletions backend/internal/handlers/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,20 @@ func (service *AuthService) GetCurrentUser() fiber.Handler {
return errs.AuthenticationError()
}

user, err := client.GetCurrentUser(c.Context())
githubUser, err := client.GetCurrentUser(c.Context())
if err != nil {
return errs.AuthenticationError()
}

return c.Status(fiber.StatusOK).JSON(fiber.Map{"user": user})
user, err := service.store.GetUserByGitHubID(c.Context(), githubUser.ID)
if err != nil {
return errs.InternalServerError()
}

return c.Status(fiber.StatusOK).JSON(fiber.Map{
"github_user": githubUser,
"user": user,
})
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ func (s *AssignmentService) generateAssignmentToken() fiber.Handler {
return errs.BadRequest(err)
}

// if the link is permenant, use the existing permanent token
if body.Duration == nil {
assignmentToken, err := s.store.GetPermanentAssignmentTokenByAssignmentID(c.Context(), assignmentID)
if err == nil {
return c.Status(http.StatusOK).JSON(fiber.Map{"token": assignmentToken.Token})
}
}

token, err := utils.GenerateToken(16)
if err != nil {
return errs.InternalServerError()
Expand Down
10 changes: 9 additions & 1 deletion backend/internal/handlers/classrooms/classrooms.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ func (s *ClassroomService) getClassroomUsers() fiber.Handler {

usersInClassroom, err := s.store.GetUsersInClassroom(c.Context(), classroomID)
if err != nil {

return errs.InternalServerError()
}

Expand All @@ -213,6 +212,7 @@ func (s *ClassroomService) getClassroomUsers() fiber.Handler {
return c.Status(http.StatusOK).JSON(fiber.Map{"users": updatedUsersInClassroom})
}
}

func (s *ClassroomService) getRubricsInClassroom() fiber.Handler {
return func(c *fiber.Ctx) error {
classroomID, err := strconv.ParseInt(c.Params("classroom_id"), 10, 64)
Expand Down Expand Up @@ -321,6 +321,14 @@ func (s *ClassroomService) generateClassroomToken() fiber.Handler {
return err
}

// if the link is permenant, use the existing permanent token
if body.Duration == nil {
classroomToken, err := s.store.GetPermanentClassroomTokenByClassroomIDAndRole(c.Context(), classroomID, classroomRole)
if err == nil {
return c.Status(http.StatusOK).JSON(fiber.Map{"token": classroomToken.Token})
}
}

token, err := utils.GenerateToken(16)
if err != nil {
return errs.InternalServerError()
Expand Down
10 changes: 8 additions & 2 deletions backend/internal/handlers/users/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ func (s *UserService) GetUser() fiber.Handler {
return errs.BadRequest(err)
}

user, err := client.GetUser(c.Context(), userName)
githubUser, err := client.GetUser(c.Context(), userName)
if err != nil {
return errs.AuthenticationError()
}

user, err := s.store.GetUserByGitHubID(c.Context(), *githubUser.ID)
if err != nil {
return errs.AuthenticationError()
}

return c.Status(http.StatusOK).JSON(fiber.Map{
"user": user,
"user": user,
"github_user": githubUser,
})
}
}
20 changes: 20 additions & 0 deletions backend/internal/storage/postgres/assignment_outlines.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ func (db *DB) GetAssignmentByToken(ctx context.Context, token string) (models.As
return assignmentOutline, nil
}

func (db *DB) GetPermanentAssignmentTokenByAssignmentID(ctx context.Context, assignmentID int64) (models.AssignmentToken, error) {
var tokenData models.AssignmentToken
err := db.connPool.QueryRow(ctx, `
SELECT assignment_outline_id, token, created_at, expires_at
FROM assignment_outline_tokens
WHERE assignment_outline_id = $1 AND expires_at IS NULL
`, assignmentID).Scan(
&tokenData.AssignmentID,
&tokenData.Token,
&tokenData.CreatedAt,
&tokenData.ExpiresAt,
)

if err != nil {
return models.AssignmentToken{}, errs.NewDBError(err)
}

return tokenData, nil
}

func (db *DB) GetAssignmentsInClassroom(ctx context.Context, classroomID int64) ([]models.AssignmentOutline, error) {
rows, err := db.connPool.Query(ctx, "SELECT * FROM assignment_outlines WHERE classroom_id = $1", classroomID)
if err != nil {
Expand Down
21 changes: 21 additions & 0 deletions backend/internal/storage/postgres/classrooms.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,27 @@ func (db *DB) GetClassroomToken(ctx context.Context, token string) (models.Class
return tokenData, nil
}

func (db *DB) GetPermanentClassroomTokenByClassroomIDAndRole(ctx context.Context, classroomID int64, classroomRole models.ClassroomRole) (models.ClassroomToken, error) {
var tokenData models.ClassroomToken
err := db.connPool.QueryRow(ctx, `
SELECT classroom_id, classroom_role, token, created_at, expires_at
FROM classroom_tokens
WHERE classroom_id = $1 AND classroom_role = $2 AND expires_at IS NULL
`, classroomID, classroomRole).Scan(
&tokenData.ClassroomID,
&tokenData.ClassroomRole,
&tokenData.Token,
&tokenData.CreatedAt,
&tokenData.ExpiresAt,
)

if err != nil {
return models.ClassroomToken{}, errs.NewDBError(err)
}

return tokenData, nil
}

func (db *DB) GetNumberOfStudentsInClassroom(ctx context.Context, classroomID int64) (int, error) {
var count int
err := db.connPool.QueryRow(ctx, `
Expand Down
2 changes: 2 additions & 0 deletions backend/internal/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type Classroom interface {
GetUserClassroomsInOrg(ctx context.Context, orgID int64, userID int64) ([]models.ClassroomUser, error)
CreateClassroomToken(ctx context.Context, tokenData models.ClassroomToken) (models.ClassroomToken, error)
GetClassroomToken(ctx context.Context, token string) (models.ClassroomToken, error)
GetPermanentClassroomTokenByClassroomIDAndRole(ctx context.Context, classroomID int64, classroomRole models.ClassroomRole) (models.ClassroomToken, error)
GetNumberOfStudentsInClassroom(ctx context.Context, classroomID int64) (int, error)
}

Expand All @@ -80,6 +81,7 @@ type AssignmentOutline interface {
GetTotalWorkCommits(ctx context.Context, assignmentID int) (int, error)
GetAssignmentByToken(ctx context.Context, token string) (models.AssignmentOutline, error)
CreateAssignmentToken(ctx context.Context, tokenData models.AssignmentToken) (models.AssignmentToken, error)
GetPermanentAssignmentTokenByAssignmentID(ctx context.Context, assignmentID int64) (models.AssignmentToken, error)
}

type AssignmentTemplate interface {
Expand Down
Loading