Skip to content

Commit

Permalink
Merge pull request #35 from team-inu/development
Browse files Browse the repository at this point in the history
Course portfolio and permission
  • Loading branch information
Porping committed Mar 17, 2024
2 parents 73a1657 + 47304e6 commit 7833cb3
Show file tree
Hide file tree
Showing 29 changed files with 1,091 additions and 101 deletions.
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/http_server/main.go",
"cwd": "${workspaceFolder}"
}
]
}
2 changes: 2 additions & 0 deletions entity/assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type AssignmentRepository interface {
GetById(id string) (*Assignment, error)
GetByParams(params *Assignment, limit int, offset int) ([]Assignment, error)
GetByCourseId(courseId string) ([]Assignment, error)
GetPassingStudentPercentage(assignmentId string) (float64, error)
Create(assignment *Assignment) error
CreateMany(assignment []Assignment) error
CreateLinkCourseLearningOutcome(assignmentId string, courseLearningOutcomeId []string) error
Expand All @@ -30,6 +31,7 @@ type AssignmentUseCase interface {
GetById(id string) (*Assignment, error)
GetByParams(params *Assignment, limit int, offset int) ([]Assignment, error)
GetByCourseId(courseId string) ([]Assignment, error)
GetPassingStudentPercentage(assignmentId string) (float64, error)
Create(name string, description string, maxScore int, weight int, expectedScorePercentage float64, expectedPassingStudentPercentage float64, courseLearningOutcomeIds []string) error
CreateLinkCourseLearningOutcome(assignmentId string, courseLearningOutcomeId []string) error
Update(id string, name string, description string, maxScore int, weight int, expectedScorePercentage float64, expectedPassingStudentPercentage float64) error
Expand Down
70 changes: 58 additions & 12 deletions entity/course.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,64 @@ type CriteriaGrade struct {
}

func (c CriteriaGrade) IsValid() bool {
return c.A >= 0 && c.BP >= 0 && c.B >= 0 && c.CP >= 0 && c.C >= 0 && c.DP >= 0 && c.D >= 0 && c.F >= 0
return c.A >= c.BP &&
c.BP >= c.B &&
c.B >= c.CP &&
c.CP >= c.C &&
c.C >= c.DP &&
c.DP >= c.D &&
c.D >= c.F &&
c.F >= 0
}

func (c CriteriaGrade) CalculateCriteriaWeight(maxScore float64) CriteriaGrade {
percentage := maxScore / 100

criteriaGrade := CriteriaGrade{
A: c.A * percentage,
BP: c.BP * percentage,
B: c.B * percentage,
CP: c.CP * percentage,
C: c.C * percentage,
DP: c.DP * percentage,
D: c.D * percentage,
F: c.F * percentage,
}
return criteriaGrade
}

func (c CriteriaGrade) GradeToGPA(grade string) float64 {
switch grade {
case "A":
return 4.0
case "BP":
return 3.5
case "B":
return 3.0
case "CP":
return 2.5
case "C":
return 2.0
case "DP":
return 1.5
case "D":
return 1.0
case "F":
return 0
default:
return 0
}
}

// TODO: Add academic year and graduated year
type Course struct {
Id string `json:"id" gorm:"primaryKey;type:char(255)"`
Name string `json:"name"`
Code string `json:"code"`
Curriculum string `json:"curriculum"`
Description string `json:"description"`
// TODO: Add academic year and graduated year
// AcademicYear string `json:"academicYear"`
// GraduatedYear string `json:"graduatedYear"`
Id string `json:"id" gorm:"primaryKey;type:char(255)"`
Name string `json:"name"`
Code string `json:"code"`
Curriculum string `json:"curriculum"`
Description string `json:"description"`
ExpectedPassingCloPercentage float64 `json:"expectedPassingCloPercentage"`

SemesterId string `json:"semesterId"`
UserId string `json:"userId"`
CriteriaGrade
Expand All @@ -44,7 +90,7 @@ type CourseUseCase interface {
GetAll() ([]Course, error)
GetById(id string) (*Course, error)
GetByUserId(userId string) ([]Course, error)
Create(semesterId string, userId string, name string, code string, curriculum string, description string, criteriaGrade CriteriaGrade) error
Update(id string, course *Course) error
Delete(id string) 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
Delete(user User, id string) error
}
12 changes: 7 additions & 5 deletions entity/course_learning_outcome.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ type CourseLearningOutcome struct {
Code string `json:"code"`
Description string `json:"description"`
ExpectedPassingAssignmentPercentage float64 `json:"expectedPassingAssignmentPercentage"`
ExpectedScorePercentage float64 `json:"expectedScorePercentage"`
ExpectedPassingStudentPercentage float64 `json:"expectedPassingStudentPercentage"`
Status string `json:"status"`
ProgramOutcomeId string `json:"programOutcomeId"`
Expand All @@ -17,11 +16,15 @@ type CourseLearningOutcome struct {
Course Course `json:"-"`
}

type CourseLearningOutcomeWithPO struct {
CourseLearningOutcome
ProgramOutcomeName string `json:"programOutcomeName"`
}

type CreateCourseLearningOutcomeDto struct {
Code string
Description string
ExpectedPassingAssignmentPercentage float64
ExpectedScorePercentage float64
ExpectedPassingStudentPercentage float64
Status string
SubProgramLearningOutcomeIds []string
Expand All @@ -33,7 +36,6 @@ type UpdateCourseLeaningOutcomeDto struct {
Code string
Description string
ExpectedPassingAssignmentPercentage float64
ExpectedScorePercentage float64
ExpectedPassingStudentPercentage float64
Status string
ProgramOutcomeId string
Expand All @@ -42,7 +44,7 @@ type UpdateCourseLeaningOutcomeDto struct {
type CourseLearningOutcomeRepository interface {
GetAll() ([]CourseLearningOutcome, error)
GetById(id string) (*CourseLearningOutcome, error)
GetByCourseId(courseId string) ([]CourseLearningOutcome, error)
GetByCourseId(courseId string) ([]CourseLearningOutcomeWithPO, error)
Create(courseLearningOutcome *CourseLearningOutcome) error
CreateLinkSubProgramLearningOutcome(id string, subProgramLearningOutcomeId []string) error
Update(id string, courseLearningOutcome *CourseLearningOutcome) error
Expand All @@ -54,7 +56,7 @@ type CourseLearningOutcomeRepository interface {
type CourseLearningOutcomeUseCase interface {
GetAll() ([]CourseLearningOutcome, error)
GetById(id string) (*CourseLearningOutcome, error)
GetByCourseId(courseId string) ([]CourseLearningOutcome, error)
GetByCourseId(courseId string) ([]CourseLearningOutcomeWithPO, error)
Create(dto CreateCourseLearningOutcomeDto) error
CreateLinkSubProgramLearningOutcome(id string, subProgramLearningOutcomeId []string) error
Update(id string, dto UpdateCourseLeaningOutcomeDto) error
Expand Down
117 changes: 117 additions & 0 deletions entity/course_portfolio.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package entity

// [1] Info
type CourseInfo struct {
Name string `json:"courseName"`
Code string `json:"courseCode"`
Lecturers []string `json:"lecturers"`
}

// [2] Summary
type CourseSummary struct {
TeachingMethods []string `json:"teachingMethod"`
OnlineTool string `json:"onlineTool"`
Objectives []string `json:"objectives"`
}

// [3.1] Tabee Outcome
type Assessment struct {
AssessmentTask string `json:"assessmentTask"`
PassingCriteria float64 `json:"passingCriteria"`
StudentPassPercentage float64 `json:"studentPassPercentage"`
}

type CourseOutcome struct {
Name string `json:"name"`
Assessments []Assessment `json:"assessments"`
}

type TabeeOutcome struct {
Name string `json:"name"`
CourseOutcomes []CourseOutcome `json:"courseOutcomes"`
MinimumPercentage float64 `json:"minimumPercentage"`
}

// [3.2] Grade Distribution
type GradeFrequency struct {
Name string `json:"name"`
GradeScore float64 `json:"gradeScore"`
Frequency int `json:"frequency"`
}

type ScoreFrequency struct {
Score int `json:"score"`
Frequency int `json:"frequency"`
}

type GradeDistribution struct {
StudentAmount int `json:"studentAmount"`
GPA float64 `json:"GPA"`
GradeFrequencies []GradeFrequency `json:"gradeFrequencies"`
ScoreFrequencies []ScoreFrequency `json:"scoreFrequencies"`
}

// [3] Result
type CourseResult struct {
TabeeOutcomes []TabeeOutcome `json:"tabeeOutcomes"`
GradeDistribution GradeDistribution `json:"gradeDistribution"`
}

// [4.1] SubjectComments
type Subject struct {
CourseName string `json:"courseName"`
Comment string `json:"comments"`
}

type SubjectComments struct {
UpstreamSubjects []Subject `json:"upstreamSubjects"`
DownstreamSubjects []Subject `json:"downstreamSubjects"`
Other string `json:"other"`
}

// [4] Development
type CourseDevelopment struct {
Plans []string `json:"plans"`
DoAndChecks []string `json:"doAndChecks"`
Acts []string `json:"acts"`
SubjectComments SubjectComments `json:"subjectComments"`
OtherComment string `json:"otherComment"`
}

// Course Portfolio
type CoursePortfolio struct {
CourseInfo CourseInfo `json:"info"`
CourseSummary CourseSummary `json:"summary"`
CourseResult CourseResult `json:"result"`
CourseDevelopment CourseDevelopment `json:"development"`
}

type AssignmentPercentage struct {
AssignmentId string `gorm:"column:a_id"`
Name string
ExpectedScorePercentage float64
PassingPercentage float64
CourseLearningOutcomeId string `gorm:"column:c_id"`
}

type PoPercentage struct {
PassingPercentage float64
ProgramOutcomeId string `gorm:"column:p_id"`
}

type CloPercentage struct {
PassingPercentage float64
CourseLearningOutcomeId string `gorm:"column:c_id"`
}

type CoursePortfolioRepository interface {
EvaluatePassingAssignmentPercentage(courseId string) ([]AssignmentPercentage, error)
EvaluatePassingPoPercentage(courseId string) ([]PoPercentage, error)
EvaluatePassingCloPercentage(courseId string) ([]CloPercentage, error)
}

type CoursePortfolioUseCase interface {
Generate(courseId string) (*CoursePortfolio, error)
CalculateGradeDistribution(courseId string) (*GradeDistribution, error)
EvaluateTabeeOutcomes(courseId string) ([]TabeeOutcome, error)
}
12 changes: 9 additions & 3 deletions entity/score.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ type StudentScore struct {
Score float64 `json:"score" validate:"required"`
}

type AssignmentScore struct {
Scores []Score `json:"scores"`
SubmittedAmount int `json:"submittedAmount"`
EnrolledAmount int `json:"enrolledAmount"`
}

type ScoreRepository interface {
GetAll() ([]Score, error)
GetById(id string) (*Score, error)
Expand All @@ -37,11 +43,11 @@ type ScoreRepository interface {
type ScoreUseCase interface {
GetAll() ([]Score, error)
GetById(id string) (*Score, error)
GetByAssignmentId(assignmentId string) ([]Score, error)
GetByAssignmentId(assignmentId string) (*AssignmentScore, error)
GetByUserId(userId string) ([]Score, error)
GetByStudentId(studentId string) ([]Score, error)
CreateMany(userId string, assignmentId string, studentScores []StudentScore) error
Update(scoreId string, score float64) error
Delete(id string) error
Update(user User, scoreId string, score float64) error
Delete(user User, id string) error
FilterSubmittedScoreStudents(assignmentId string, studentIds []string) ([]string, error)
}
22 changes: 16 additions & 6 deletions entity/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@ const (
)

type User struct {
Id string `json:"id" gorm:"primaryKey;type:char(255)"`
Email string `json:"email" gorm:"unique"`
Password string `json:"password"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
Role string `json:"role" gorm:"default:'LECTURER'"`
Id string `json:"id" gorm:"primaryKey;type:char(255)"`
Email string `json:"email" gorm:"unique"`
Password string `json:"password"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
Role UserRole `json:"role" gorm:"default:'LECTURER'"`
}

func (u User) IsRoles(expectedRoles []UserRole) bool {
for _, expectedRole := range expectedRoles {
if u.Role == expectedRole {
return true
}
}

return false
}

type UserRepository interface {
Expand Down
3 changes: 0 additions & 3 deletions infrastructure/fiber/controller/auth.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package controller

import (
"fmt"
"time"

"github.com/gofiber/fiber/v2"
Expand Down Expand Up @@ -59,8 +58,6 @@ func (c AuthController) SignIn(ctx *fiber.Ctx) error {
}

func (c AuthController) SignOut(ctx *fiber.Ctx) error {
fmt.Println(c.config.Session.CookieName)

sid := ctx.Cookies(c.config.Session.CookieName)
cookie, err := c.authUseCase.SignOut(sid)
if err != nil {
Expand Down
Loading

0 comments on commit 7833cb3

Please sign in to comment.