-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from team-inu/development
assignment groups and ml
- Loading branch information
Showing
23 changed files
with
1,281 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.