Skip to content

Commit

Permalink
pass mentor and secondary mentor name and username in mentor dashboard
Browse files Browse the repository at this point in the history
Signed-off-by: Rajiv Harlalka <[email protected]>
  • Loading branch information
rajivharlalka committed Nov 15, 2023
1 parent e5be917 commit 3e7d82a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
16 changes: 12 additions & 4 deletions controllers/mentor.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ type ProjectInfo struct {
LinesAdded uint `json:"lines_added"`
LinesRemoved uint `json:"lines_removed"`

Pulls []string `json:"pulls"`
Pulls []string `json:"pulls"`
MentorName string `json:"mentor_name"`
SecondaryMentorName string `json:"secondary_mentor_name"`
MentorUsername string `json:"mentor_username"`
SecondaryMentorUsername string `json:"secondary_mentor_username"`
}

type StudentInfo struct {
Expand Down Expand Up @@ -169,15 +173,15 @@ func CreateMentorDashboard(mentor models.Mentor, db *gorm.DB) MentorDashboard {
var projectsInfo []ProjectInfo = make([]ProjectInfo, 0)
var students []StudentInfo = make([]StudentInfo, 0)

db.Table("projects").
db.Preload("Mentor").Preload("SecondaryMentor").Table("projects").
Where("mentor_id = ? OR secondary_mentor_id = ?", mentor.ID, mentor.ID).
Select("name", "description", "repo_link", "commit_count", "pull_count", "lines_added", "lines_removed", "contributors", "pulls", "project_status").
Find(&projects)

studentMap := make(map[string]bool)
var studentUsernames []string
for _, project := range projects {
pulls := make([]string, 0)
fmt.Print(project.SecondaryMentor)
if len(project.Pulls) != 0 {
pulls = strings.Split(project.Pulls, ",")
}
Expand All @@ -193,7 +197,11 @@ func CreateMentorDashboard(mentor models.Mentor, db *gorm.DB) MentorDashboard {
LinesAdded: project.LinesAdded,
LinesRemoved: project.LinesRemoved,

Pulls: pulls,
Pulls: pulls,
MentorName: project.Mentor.Name,
SecondaryMentorName: project.SecondaryMentor.Name,
MentorUsername: project.Mentor.Username,
SecondaryMentorUsername: project.SecondaryMentor.Username,
}
projectsInfo = append(projectsInfo, projectInfo)

Expand Down
11 changes: 11 additions & 0 deletions controllers/project_reg.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ func RegisterProject(w http.ResponseWriter, r *http.Request) {
// Attempt to fetch secondary mentor from the database
secondaryMentor := models.Mentor{}
if reqFields.SecondaryMentorUsername != "" {
if reqFields.MentorUsername == reqFields.SecondaryMentorUsername {
utils.LogErrAndRespond(
r,
w,
err,
fmt.Sprintf("Error: Secondary mentor `%s` cannot be same as primary mentor.", reqFields.SecondaryMentorUsername),
http.StatusBadRequest,
)
return
}

tx = db.Table("mentors").Where("username = ?", reqFields.SecondaryMentorUsername).First(&secondaryMentor)

if tx.Error != nil && err != gorm.ErrRecordNotFound {
Expand Down

0 comments on commit 3e7d82a

Please sign in to comment.