Skip to content

Commit

Permalink
feat(meeting): ✨ notif on new meeting
Browse files Browse the repository at this point in the history
  • Loading branch information
anirudhgray committed Oct 23, 2023
1 parent f184db8 commit 1e69a46
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions routers/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,4 @@ func RegisterRoutes(route *gin.Engine) {
// TODO controller-service-repo pattern
// TODO unit of work pattern
// For google oauth, make slight change. Instead of redirecting to the callback on backend directly, redirect to frontend url (or app uri), and have a route which accepts the auth code that frontend sends and does wht my callback is doing rn.
// TODO maybe some event broker like kafka for notifs
29 changes: 29 additions & 0 deletions services/meeting.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/GDGVIT/attendance-app-backend/infra/logger"
"github.com/GDGVIT/attendance-app-backend/models"
"github.com/GDGVIT/attendance-app-backend/repository"
"github.com/GDGVIT/attendance-app-backend/utils/email"
)

// MeetingService handles business logic related to meetings.
Expand Down Expand Up @@ -52,6 +53,34 @@ func (ms *MeetingService) CreateMeeting(teamID uint, title, description, venue s
return models.Meeting{}, err
}

// get name of team
teamRepo := repository.NewTeamRepository()
team, err := teamRepo.GetTeamByID(teamID)
if err != nil {
return models.Meeting{}, err
}

// get members of team and send email to each member
teamMemberRepo := repository.NewTeamMemberRepository()
teamMembers, err := teamMemberRepo.GetTeamMembersByTeamID(teamID)
if err != nil {
return models.Meeting{}, err
}

teamMemberEmails := []string{}
userRepo := repository.NewUserRepository()
for _, teamMember := range teamMembers {
user, err := userRepo.GetUserByID(teamMember.UserID)
if err != nil {
return models.Meeting{}, err
}
// add user email to teamMemberEmails
teamMemberEmails = append(teamMemberEmails, user.Email)
}

// send email to each team member
email.SendMeetingNotifToTeamMembers(teamMemberEmails, team.Name, meeting.Title, meeting.StartTime)

return createdMeeting, nil
}

Expand Down
14 changes: 14 additions & 0 deletions utils/email/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,17 @@ func SendKickNotifToUser(toEmail string, userName string, teamName string) error
}
return nil
}

// send email to all team members about a new meeting
func SendMeetingNotifToTeamMembers(toEmail []string, teamName string, meetingName string, meetingTime time.Time) error {
content := "A new meeting " + meetingName + " has been scheduled for the team " + teamName + " at " + meetingTime.String() + "."
subject := "New Meeting."

for _, email := range toEmail {
err := GenericSendMail(subject, content, email, teamName+" Team")
if err != nil {
return err
}
}
return nil
}

0 comments on commit 1e69a46

Please sign in to comment.