Skip to content

Commit

Permalink
Merge pull request #41 from team-inu/development
Browse files Browse the repository at this point in the history
assignment groups and ml
  • Loading branch information
XiaoXuxxxx committed May 3, 2024
2 parents b548177 + 36dd999 commit 4da16c1
Show file tree
Hide file tree
Showing 23 changed files with 1,281 additions and 145 deletions.
3 changes: 3 additions & 0 deletions cmd/auto_migration/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ func main() {
}

err = gormDB.AutoMigrate(
&entity.AssignmentGroup{},
&entity.Assignment{},
&entity.CourseLearningOutcome{},
&entity.CourseStream{},
&entity.Course{},
&entity.Department{},
&entity.Enrollment{},
&entity.Faculty{},
&entity.Grade{},
&entity.GraduatedStudent{},
&entity.User{},
&entity.Prediction{},
&entity.ProgramLearningOutcome{},
&entity.ProgramOutcome{},
&entity.Programme{},
Expand Down
78 changes: 60 additions & 18 deletions entity/assignment.go
Original file line number Diff line number Diff line change
@@ -1,41 +1,83 @@
package entity

type AssignmentGroup struct {
Id string `json:"id" gorm:"primaryKey;type:char(255)"`
Name string `json:"name"`
CourseId string `json:"courseId"`
Weight int `json:"weight"`

Assignments []Assignment `gorm:"foreignKey:AssignmentGroupId" json:"assignments,omitempty"`

Course *Course `json:",omitempty"`
}

type Assignment struct {
Id string `json:"id" gorm:"primaryKey;type:char(255)"`
Name string `json:"name"`
Description string `json:"description"`
MaxScore int `json:"maxScore"`
Weight int `json:"weight"`
ExpectedScorePercentage float64 `json:"expectedScorePercentage"`
ExpectedPassingStudentPercentage float64 `json:"expectedPassingStudentPercentage"`
IsIncludedInClo *bool `json:"isIncludedInClo"`

CourseId string `json:"courseId" gorm:"->;-:migration"`

CourseLearningOutcomes []*CourseLearningOutcome `gorm:"many2many:clo_assignment" json:"courseLearningOutcomes"`
Id string `json:"id" gorm:"primaryKey;type:char(255)"`
Name string `json:"name"`
Description string `json:"description"`
MaxScore int `json:"maxScore"`
ExpectedScorePercentage float64 `json:"expectedScorePercentage"`
ExpectedPassingStudentPercentage float64 `json:"expectedPassingStudentPercentage"`
IsIncludedInClo *bool `json:"isIncludedInClo"`
AssignmentGroupId string `json:"assignmentGroupId" gorm:"not null"`
CourseId string `json:"courseId" gorm:"->;-:migration"`
CourseLearningOutcomes []*CourseLearningOutcome `gorm:"many2many:clo_assignment" json:"courseLearningOutcomes"`
}

func GenerateGroupByAssignmentId(assignmentGroups []AssignmentGroup, assignments []Assignment) map[string]*AssignmentGroup {
weightByAssignmentGroupId := make(map[string]*AssignmentGroup, len(assignmentGroups))
for _, assignmentGroup := range assignmentGroups {
weightByAssignmentGroupId[assignmentGroup.Id] = &assignmentGroup
}

weightByAssignmentId := make(map[string]*AssignmentGroup, len(assignments))
for _, assignment := range assignments {
assignmentGroup, ok := weightByAssignmentGroupId[assignment.AssignmentGroupId]
if !ok {
continue
}

weightByAssignmentId[assignment.Id] = assignmentGroup
}

return weightByAssignmentId
}

type AssignmentRepository interface {
GetById(id string) (*Assignment, error)
GetByParams(params *Assignment, limit int, offset int) ([]Assignment, error)
GetByCourseId(courseId string) ([]Assignment, error)
GetByGroupId(groupId string) ([]Assignment, error)
GetPassingStudentPercentage(assignmentId string) (float64, error)
Create(assignment *Assignment) error
CreateMany(assignment []Assignment) error
CreateLinkCourseLearningOutcome(assignmentId string, courseLearningOutcomeId []string) error
Update(id string, assignment *Assignment) error
Delete(id string) error

CreateLinkCourseLearningOutcome(assignmentId string, courseLearningOutcomeId []string) error
DeleteLinkCourseLearningOutcome(assignmentId string, courseLearningOutcomeId string) error

GetGroupByQuery(query AssignmentGroup, withAssignment bool) ([]AssignmentGroup, error)
GetGroupByGroupId(assignmentGroupId string) (*AssignmentGroup, error)
CreateGroup(assignmentGroup *AssignmentGroup) error
UpdateGroup(assignmentGroupId string, assignmentGroup *AssignmentGroup) error
DeleteGroup(assignmentGroupId string) error
}

type AssignmentUseCase interface {
GetById(id string) (*Assignment, error)
GetByParams(params *Assignment, limit int, offset int) ([]Assignment, error)
GetByCourseId(courseId string) ([]Assignment, error)
GetByGroupId(assignmentGroupId string) ([]Assignment, error)
GetPassingStudentPercentage(assignmentId string) (float64, error)
Create(name string, description string, maxScore int, weight int, expectedScorePercentage float64, expectedPassingStudentPercentage float64, courseLearningOutcomeIds []string, isIncludedInClo bool) error
CreateLinkCourseLearningOutcome(assignmentId string, courseLearningOutcomeId []string) error
Update(id string, name string, description string, maxScore int, weight int, expectedScorePercentage float64, expectedPassingStudentPercentage float64, isIncludedInClo bool) error
Create(assignmentGroupId string, name string, description string, maxScore int, expectedScorePercentage float64, expectedPassingStudentPercentage float64, courseLearningOutcomeIds []string, isIncludedInClo bool) error
Update(id string, name string, description string, maxScore int, expectedScorePercentage float64, expectedPassingStudentPercentage float64, isIncludedInClo bool) error
Delete(id string) error

CreateLinkCourseLearningOutcome(assignmentId string, courseLearningOutcomeId []string) error
DeleteLinkCourseLearningOutcome(assignmentId string, courseLearningOutcomeId string) error

GetGroupByGroupId(assignmentGroupId string) (*AssignmentGroup, error)
GetGroupByCourseId(courseId string, withAssignment bool) ([]AssignmentGroup, error)
CreateGroup(name string, courseId string, weight int) error
UpdateGroup(assignmentGroupId string, name string, weight int) error
DeleteGroup(assignmentGroupId string) error
}
3 changes: 2 additions & 1 deletion entity/course.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type Course struct {
Curriculum string `json:"curriculum"`
Description string `json:"description"`
ExpectedPassingCloPercentage float64 `json:"expectedPassingCloPercentage"`
IsPortfolioCompleted *bool `json:"isPortfolioCompleted" gorm:"default:false"`

SemesterId string `json:"semesterId"`
UserId string `json:"userId"`
Expand All @@ -91,6 +92,6 @@ type CourseUseCase interface {
GetById(id string) (*Course, error)
GetByUserId(userId string) ([]Course, error)
Create(user User, semesterId string, userId string, name string, code string, curriculum string, description string, expectedPassingCloPercentage float64, criteriaGrade CriteriaGrade) error
Update(user User, id string, name string, code string, curriculum string, description string, expectedPassingCloPercentage float64, criteriaGrade CriteriaGrade) error
Update(user User, id string, name string, code string, curriculum string, description string, expectedPassingCloPercentage float64, criteriaGrade CriteriaGrade, isPortfolioCompleted bool) error
Delete(user User, id string) error
}
106 changes: 106 additions & 0 deletions entity/course_portfolio.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,120 @@ type CloPercentage struct {
CourseLearningOutcomeId string `gorm:"column:c_id"`
}

type StudentData struct {
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
StudentId string `json:"studentId"`
Pass bool `json:"pass"`
}

type CloPassingStudent struct {
CourseLearningOutcomeId string `json:"courseLearningOutcomeId"`
Students []StudentData `json:"students"`
}

type CloPassingStudentGorm struct {
FirstName string
LastName string
StudentId string
Pass bool
CourseLearningOutcomeId string `gorm:"column:clo_id"`
}

type PloData struct {
Id string `json:"id"`
Code string `json:"code"`
DescriptionThai string `json:"descriptionThai"`
ProgramYear int `json:"programYear"`
Pass bool `json:"pass"`
}

type PloPassingStudentGorm struct {
Code string
DescriptionThai string
ProgramYear int
StudentId string
Pass bool
ProgramLearningOutcomeId string `gorm:"column:plo_id"`
}

type PoData struct {
Id string `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
Pass bool `json:"pass"`
}

type PoPassingStudentGorm struct {
Code string
Name string
StudentId string
Pass bool
ProgramOutcomeId string `gorm:"column:p_id"`
}

type StudentOutcomeStatus struct {
StudentId string `json:"studentId"`
ProgramLearningOutcomes []PloData `json:"programLearningOutcomes"`
ProgramOutcomes []PoData `json:"programOutcomes"`
}

type CourseData struct {
Id string `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
PassingPercentage float64 `json:"passingPercentage"`
Year int `json:"year"`
SemesterSequence string `json:"semesterSequence"`
}

type PloCourses struct {
ProgramLearningOutcomeId string `json:"programLearningOutcomeId"`
Courses []CourseData `json:"courses"`
}

type PloCoursesGorm struct {
PassingPercentage float64
ProgramLearningOutcomeId string `gorm:"column:plo_id"`
CourseId string
Name string
Code string
Year int
SemesterSequence string
}

type PoCourses struct {
ProgramOutcomeId string `json:"programLearningOutcomeId"`
Courses []CourseData `json:"courses"`
}

type PoCoursesGorm struct {
PassingPercentage float64
ProgramOutcomeId string `gorm:"column:p_id"`
CourseId string
Name string
Code string
Year int
SemesterSequence string
}

type CoursePortfolioRepository interface {
EvaluatePassingAssignmentPercentage(courseId string) ([]AssignmentPercentage, error)
EvaluatePassingPoPercentage(courseId string) ([]PoPercentage, error)
EvaluatePassingCloPercentage(courseId string) ([]CloPercentage, error)
EvaluatePassingCloStudents(courseId string) ([]CloPassingStudentGorm, error)
EvaluatePassingPloStudents(courseId string) ([]PloPassingStudentGorm, error)
EvaluatePassingPoStudents(courseId string) ([]PoPassingStudentGorm, error)
EvaluateAllPloCourses() ([]PloCoursesGorm, error)
EvaluateAllPoCourses() ([]PoCoursesGorm, error)
}

type CoursePortfolioUseCase interface {
Generate(courseId string) (*CoursePortfolio, error)
CalculateGradeDistribution(courseId string) (*GradeDistribution, error)
EvaluateTabeeOutcomes(courseId string) ([]TabeeOutcome, error)
GetCloPassingStudentsByCourseId(courseId string) ([]CloPassingStudent, error)
GetStudentOutcomesStatusByCourseId(courseId string) ([]StudentOutcomeStatus, error)
GetAllProgramLearningOutcomeCourses() ([]PloCourses, error)
GetAllProgramOutcomeCourses() ([]PoCourses, error)
}
9 changes: 5 additions & 4 deletions entity/error/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ const (
ErrUpdatePrediction = 21702
ErrQueryPrediction = 21703

ErrCreateCourseStream = 21800
ErrDeleteCourseStream = 21801
ErrQueryCourseStream = 21802
ErrUpdateCourseStream = 21803
ErrCreateCourseStream = 21800
ErrDeleteCourseStream = 21801
ErrQueryCourseStream = 21802
ErrUpdateCourseStream = 21803
ErrCourseStreamNotFound = 21804
)
25 changes: 9 additions & 16 deletions infrastructure/fiber/controller/assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,14 @@ func (c assignmentController) GetById(ctx *fiber.Ctx) error {
return response.NewSuccessResponse(ctx, fiber.StatusOK, assignment)
}

func (c assignmentController) GetAssignments(ctx *fiber.Ctx) error {
var payload request.GetAssignmentsByParamsPayload
func (c assignmentController) GetByCourseId(ctx *fiber.Ctx) error {
var payload request.GetAssignmentsByCourseIdPayload

if ok, err := c.Validator.Validate(&payload, ctx); !ok {
return err
}

assignments, err := c.AssignmentUseCase.GetByParams(&entity.Assignment{
// CourseLearningOutcomeId: payload.CourseLearningOutcomeId,
}, -1, -1)
assignments, err := c.AssignmentUseCase.GetByCourseId(payload.CourseId)

if err != nil {
return err
Expand All @@ -54,20 +52,15 @@ func (c assignmentController) GetAssignments(ctx *fiber.Ctx) error {
return response.NewSuccessResponse(ctx, fiber.StatusOK, assignments)
}

func (c assignmentController) GetByCourseId(ctx *fiber.Ctx) error {
var payload request.GetAssignmentsByCourseIdPayload

if ok, err := c.Validator.Validate(&payload, ctx); !ok {
return err
}

assignments, err := c.AssignmentUseCase.GetByCourseId(payload.CourseId)
func (c assignmentController) GetByGroupId(ctx *fiber.Ctx) error {
assignmentGroupId := ctx.Params("assignmentGroupId")

assignmentGroups, err := c.AssignmentUseCase.GetByGroupId(assignmentGroupId)
if err != nil {
return err
}

return response.NewSuccessResponse(ctx, fiber.StatusOK, assignments)
return response.NewSuccessResponse(ctx, fiber.StatusOK, assignmentGroups)
}

func (c assignmentController) Create(ctx *fiber.Ctx) error {
Expand All @@ -78,10 +71,10 @@ func (c assignmentController) Create(ctx *fiber.Ctx) error {
}

err := c.AssignmentUseCase.Create(
payload.AssignmentGroupId,
payload.Name,
payload.Description,
*payload.MaxScore,
*payload.Weight,
*payload.ExpectedScorePercentage,
*payload.ExpectedPassingStudentPercentage,
payload.CourseLearningOutcomeIds,
Expand All @@ -102,7 +95,7 @@ func (c assignmentController) Update(ctx *fiber.Ctx) error {

id := ctx.Params("assignmentId")

err := c.AssignmentUseCase.Update(id, payload.Name, payload.Description, *payload.MaxScore, *payload.Weight, *payload.ExpectedScorePercentage, *payload.ExpectedPassingStudentPercentage, *payload.IsIncludedInClo)
err := c.AssignmentUseCase.Update(id, payload.Name, payload.Description, *payload.MaxScore, *payload.ExpectedScorePercentage, *payload.ExpectedPassingStudentPercentage, *payload.IsIncludedInClo)
if err != nil {
return err
}
Expand Down
59 changes: 59 additions & 0 deletions infrastructure/fiber/controller/assignment_group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package controller

import (
"github.com/gofiber/fiber/v2"
"github.com/team-inu/inu-backyard/infrastructure/fiber/request"
"github.com/team-inu/inu-backyard/infrastructure/fiber/response"
)

func (c assignmentController) GetGroupByCourseId(ctx *fiber.Ctx) error {
courseId := ctx.Params("courseId")

assignmentGroups, err := c.AssignmentUseCase.GetGroupByCourseId(courseId, false)
if err != nil {
return err
}

return response.NewSuccessResponse(ctx, fiber.StatusOK, assignmentGroups)
}

func (c assignmentController) CreateGroup(ctx *fiber.Ctx) error {
var payload request.CreateAssignmentGroupPayload
if ok, err := c.Validator.Validate(&payload, ctx); !ok {
return err
}

err := c.AssignmentUseCase.CreateGroup(payload.Name, payload.CourseId, payload.Weight)
if err != nil {
return err
}

return response.NewSuccessResponse(ctx, fiber.StatusCreated, nil)
}

func (c assignmentController) UpdateGroup(ctx *fiber.Ctx) error {
var payload request.UpdateAssignmentGroupPayload
if ok, err := c.Validator.Validate(&payload, ctx); !ok {
return err
}

id := ctx.Params("assignmentGroupId")

err := c.AssignmentUseCase.UpdateGroup(id, payload.Name, payload.Weight)
if err != nil {
return err
}

return response.NewSuccessResponse(ctx, fiber.StatusOK, nil)
}

func (c assignmentController) DeleteGroup(ctx *fiber.Ctx) error {
id := ctx.Params("assignmentGroupId")

err := c.AssignmentUseCase.DeleteGroup(id)
if err != nil {
return err
}

return response.NewSuccessResponse(ctx, fiber.StatusOK, nil)
}
Loading

0 comments on commit 4da16c1

Please sign in to comment.