• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

classconnect-grupo3 / courses-service / 15231425007

24 May 2025 10:10PM UTC coverage: 55.598% (-12.2%) from 67.752%
15231425007

push

github

web-flow
Merge pull request #12 from classconnect-grupo3/feat/enrollments

Feat/enrollments

24 of 175 new or added lines in 4 files covered. (13.71%)

437 of 786 relevant lines covered (55.6%)

0.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

7.69
/src/controller/enrollment_controller.go
1
package controller
2

3
import (
4
        "log/slog"
5
        "net/http"
6

7
        "github.com/gin-gonic/gin"
8
)
9

10
type EnrollmentService interface {
11
        EnrollStudent(studentID, courseID string) error
12
        UnenrollStudent(studentID, courseID string) error
13
}
14

15
type EnrollmentController struct {
16
        enrollmentService EnrollmentService
17
}
18

19
func NewEnrollmentController(enrollmentService EnrollmentService) *EnrollmentController {
1✔
20
        return &EnrollmentController{enrollmentService: enrollmentService}
1✔
21
}
1✔
22

NEW
23
func (c *EnrollmentController) EnrollStudent(ctx *gin.Context) {
×
NEW
24
        slog.Debug("Enrolling student", "studentId", ctx.Param("studentId"), "courseId", ctx.Param("courseId"))
×
NEW
25
        courseID := ctx.Param("courseId")
×
NEW
26
        studentID := ctx.Param("studentId")
×
NEW
27

×
NEW
28
        if studentID == "" || courseID == "" {
×
NEW
29
                slog.Error("Invalid student ID or course ID")
×
NEW
30
                ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid student ID or course ID"})
×
NEW
31
                return
×
NEW
32
        }
×
33

NEW
34
        err := c.enrollmentService.EnrollStudent(studentID, courseID)
×
NEW
35
        if err != nil {
×
NEW
36
                slog.Error("Error enrolling student", "error", err)
×
NEW
37
                ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
×
NEW
38
                return
×
NEW
39
        }
×
40

NEW
41
        slog.Debug("Student enrolled in course", "studentId", studentID, "courseId", courseID)
×
NEW
42
        ctx.JSON(http.StatusOK, gin.H{"message": "Student successfully enrolled in course"})
×
43
}
44

NEW
45
func (c *EnrollmentController) UnenrollStudent(ctx *gin.Context) {
×
NEW
46
        slog.Debug("Unenrolling student", "studentId", ctx.Param("studentId"), "courseId", ctx.Param("courseId"))
×
NEW
47
        courseID := ctx.Param("courseId")
×
NEW
48
        studentID := ctx.Param("studentId")
×
NEW
49

×
NEW
50
        if studentID == "" || courseID == "" {
×
NEW
51
                slog.Error("Invalid student ID or course ID")
×
NEW
52
                ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid student ID or course ID"})
×
NEW
53
                return
×
NEW
54
        }
×
55

NEW
56
        err := c.enrollmentService.UnenrollStudent(studentID, courseID)
×
NEW
57
        if err != nil {
×
NEW
58
                slog.Error("Error unenrolling student", "error", err)
×
NEW
59
                ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
×
NEW
60
                return
×
NEW
61
        }
×
62

NEW
63
        slog.Debug("Student unenrolled from course", "studentId", studentID, "courseId", courseID)
×
NEW
64
        ctx.JSON(http.StatusOK, gin.H{"message": "Student successfully unenrolled from course"})
×
65
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc