diff --git a/handler/migration.go b/handler/migration.go index fc5e071..ed2f3d2 100644 --- a/handler/migration.go +++ b/handler/migration.go @@ -124,6 +124,7 @@ func (h *Handler) MigrateStudentDataToV2(ctx *gin.Context) { oldStudent.CompaniesAlloted = []string{} } + errorArray := []string{} var EndYearOffset int var Course Constant.Course @@ -137,14 +138,25 @@ func (h *Handler) MigrateStudentDataToV2(ctx *gin.Context) { case "phd": EndYearOffset = 6 Course = Constant.PHD - default: + case "btech": EndYearOffset = 4 Course = Constant.BTECH + default: + EndYearOffset = -1 + Course = Constant.BTECH + errorArray = append(errorArray, "course") } - errorArray := []string{} category := GetCategoryFromString(oldStudent.Category) + kaggle := "" + if oldStudent.Kaggle != "" { + kaggle = oldStudent.Kaggle + } + if oldStudent.Kaggel != "" { + kaggle = oldStudent.Kaggel + } + jeeRank, errJeeRank := GetRankFromString(oldStudent.JeeRank, category) if errJeeRank != nil { fmt.Println(errJeeRank) @@ -175,24 +187,26 @@ func (h *Handler) MigrateStudentDataToV2(ctx *gin.Context) { dob = 0 } + gender := Constant.Gender(strings.ToLower(oldStudent.Gender)) + newStudent := Student.Student{ Id: oldStudent.ID, Groups: oldStudent.Groups, CompaniesAlloted: oldStudent.CompaniesAlloted, - Batch: Student.Batch{ + Batch: &Student.Batch{ StartYear: oldStudent.Batch, EndYear: oldStudent.Batch + EndYearOffset, }, RollNo: oldStudent.RollNo, InstituteEmail: oldStudent.Email, Department: oldStudent.Department, - Course: Course, + Course: &Course, FirstName: oldStudent.FirstName, LastName: oldStudent.LastName, - Gender: Constant.Gender(strings.ToLower(oldStudent.Gender)), + Gender: &gender, DOB: &dob, PermanentAddress: oldStudent.PermanentAddress, PresentAddress: oldStudent.PresentAddress, @@ -229,6 +243,8 @@ func (h *Handler) MigrateStudentDataToV2(ctx *gin.Context) { Four: oldStudent.SemesterFour, Five: oldStudent.SemesterFive, Six: oldStudent.SemesterSix, + Seven: oldStudent.SemesterSeven, + Eight: oldStudent.SemesterEight, }, SummerTermDetails: Student.SummerTermSPI{ One: oldStudent.SummerOne, @@ -265,12 +281,15 @@ func (h *Handler) MigrateStudentDataToV2(ctx *gin.Context) { URL: oldStudent.Github, }, Kaggle: &Student.SocialProfile{ - URL: oldStudent.Kaggle, + URL: kaggle, }, Skype: &Student.SocialProfile{ URL: oldStudent.Skype, }, }, + Extras: Student.Extras{ + VideoResume: &oldStudent.VideoResume, + }, StructVersion: 2, CreatedAt: primitive.NewDateTimeFromTime(time.Now()), diff --git a/handler/verify.go b/handler/verify.go index 3915e5c..de6ffa4 100644 --- a/handler/verify.go +++ b/handler/verify.go @@ -4,6 +4,7 @@ import ( "github.com/FrosTiK-SD/auth/constants" "github.com/FrosTiK-SD/auth/controller" "github.com/FrosTiK-SD/auth/model" + constant "github.com/FrosTiK-SD/models/constant" "github.com/FrosTiK-SD/models/misc" "github.com/gin-gonic/gin" @@ -58,9 +59,9 @@ func ValidateRankDetails(rd **model.RankDetails) { } } -func ValidateString(s *string) { - if s != nil && *s == "" { - s = nil +func ValidateString(s **string) { + if *s != nil && *(*s) == "" { + *s = nil } } @@ -76,10 +77,31 @@ func ValidateAttachment(a **misc.Attachment) { } } +func ValidateBatch(b **model.Batch) { + if *b != nil && (*b).StartYear <= 0 { + *b = nil + } +} + +func ValidateGender(g **constant.Gender) { + if *g != nil && *(*g) == "" { + *g = nil + } +} + +func ValidateCourse(c **constant.Course) { + if *c != nil && *(*c) == "" { + *c = nil + } +} + func ValidateData(student *model.Student) { - ValidateString(student.Specialisation) - ValidateString(student.MiddleName) + ValidateBatch(&student.Batch) + ValidateCourse(&student.Course) + ValidateString(&student.Specialisation) + ValidateString(&student.MiddleName) ValidateAttachment(&student.ProfilePicture) + ValidateGender(&student.Gender) if student.DOB != nil && *student.DOB <= 10 { student.DOB = nil @@ -98,7 +120,7 @@ func ValidateData(student *model.Student) { ValidateEducationDetails(&student.Academics.XthClass) ValidateEducationDetails(&student.Academics.XIIthClass) ValidateEducationDetails(&student.Academics.UnderGraduate) - ValidateString(student.Academics.Honours) + ValidateString(&student.Academics.Honours) ValidateEducationDetails(&student.Academics.PostGraduate) if student.Academics.ThesisEndDate != nil && *student.Academics.ThesisEndDate <= 0 { diff --git a/model/student.go b/model/student.go index 8249cd4..4cde8f0 100644 --- a/model/student.go +++ b/model/student.go @@ -20,6 +20,7 @@ type OldStudent struct { Github string `json:"github" bson:"github"` MicrosoftTeams string `json:"microsoftTeams" bson:"microsoftTeams"` Kaggle string `json:"kaggle" bson:"kaggle"` + Kaggel string `json:"kaggel" bson:"kaggel"` Skype string `json:"skypeId" bson:"skypeId"` Mobile int64 `json:"mobile" bson:"mobile"` Gender string `json:"gender" bson:"gender"` @@ -51,12 +52,15 @@ type OldStudent struct { UgCollege string `json:"ugCollege" bson:"ugCollege"` UgScore float64 `json:"ugScore" bson:"ugScore"` UgYear int `json:"ugPassingyear" bson:"ugPassingyear"` + VideoResume string `json:"videoResume" bson:"videoResume"` SemesterOne float64 `json:"semesterOne" bson:"semesterOne"` SemesterTwo float64 `json:"semesterTwo" bson:"semesterTwo"` SemesterThree float64 `json:"semesterThree" bson:"semesterThree"` SemesterFour float64 `json:"semesterFour" bson:"semesterFour"` SemesterFive float64 `json:"semesterFive" bson:"semesterFive"` SemesterSix float64 `json:"semesterSix" bson:"semesterSix"` + SemesterSeven float64 `json:"semesterSeven" bson:"semesterSeven"` + SemesterEight float64 `json:"semesterEight" bson:"semesterEight"` SummerOne float64 `json:"summerOne" bson:"summerOne"` SummerTwo float64 `json:"summerTwo" bson:"summerTwo"` SummerThree float64 `json:"summerThree" bson:"summerThree"` diff --git a/model/student2.go b/model/student2.go index c11142a..63456eb 100644 --- a/model/student2.go +++ b/model/student2.go @@ -47,20 +47,20 @@ type EducationDetails struct { } type Academics struct { - JEERank *RankDetails `json:"jeeRank" bson:"jeeRank"` - GATERank *RankDetails `json:"gateRank" bson:"gateRank"` - XthClass *EducationDetails `json:"xClass" bson:"xClass"` - XIIthClass *EducationDetails `json:"xiiClass" bson:"xiiClass"` - UnderGraduate *EducationDetails `json:"underGraduate" bson:"underGraduate"` - Honours *string `json:"honours" bson:"honours"` - PostGraduate *EducationDetails `json:"postGraduate" bson:"postGraduate"` - ThesisEndDate *primitive.DateTime `json:"thesisEndDate" bson:"thesisEndDate"` - EducationGap int `json:"educationGap" bson:"educationGap"` - SemesterDetails SemesterSPI `json:"semesterSPI" bson:"semesterSPI"` - SummerTermDetails SummerTermSPI `json:"summerTermSPI" bson:"summerTermSPI"` - CurrentCGPA float64 `json:"currentCGPA" bson:"currentCGPA"` - ActiveBacklogs int `json:"activeBacklogs" bson:"activeBacklogs"` - TotalBacklogs int `json:"totalBacklogs" bson:"totalBacklogs"` + JEERank *RankDetails `json:"jeeRank" bson:"jeeRank"` + GATERank *RankDetails `json:"gateRank" bson:"gateRank"` + XthClass *EducationDetails `json:"xClass" bson:"xClass"` + XIIthClass *EducationDetails `json:"xiiClass" bson:"xiiClass"` + UnderGraduate *EducationDetails `json:"underGraduate" bson:"underGraduate"` + Honours *string `json:"honours" bson:"honours"` + PostGraduate *EducationDetails `json:"postGraduate" bson:"postGraduate"` + ThesisEndDate *primitive.DateTime `json:"thesisEndDate" bson:"thesisEndDate"` + EducationGap int `json:"educationGap" bson:"educationGap"` + SemesterSPI SemesterSPI `json:"semesterSPI" bson:"semesterSPI"` + SummerTermSPI SummerTermSPI `json:"summerTermSPI" bson:"summerTermSPI"` + CurrentCGPA float64 `json:"currentCGPA" bson:"currentCGPA"` + ActiveBacklogs int `json:"activeBacklogs" bson:"activeBacklogs"` + TotalBacklogs int `json:"totalBacklogs" bson:"totalBacklogs"` Verification misc.Verification `json:"verification" bson:"verification"` } @@ -97,7 +97,7 @@ type ParentsDetails struct { } type Extras struct { - VideoResume string `bson:"videoResume" json:"videoResume"` + VideoResume *string `bson:"videoResume" json:"videoResume"` Verification misc.Verification `bson:"verification" json:"verification"` } @@ -116,19 +116,19 @@ type Student struct { Groups []primitive.ObjectID `json:"groups" bson:"groups"` CompaniesAlloted []string `json:"companiesAlloted" bson:"companiesAlloted"` - Batch Batch `json:"batch" bson:"batch"` - RollNo int `json:"rollNo" bson:"rollNo"` - InstituteEmail string `json:"email" bson:"email"` - Department string `json:"department" bson:"department"` - Course constant.Course `json:"course" bson:"course"` - Specialisation *string `json:"specialisation" bson:"specialisation"` + Batch *Batch `json:"batch" bson:"batch"` + RollNo int `json:"rollNo" bson:"rollNo"` + InstituteEmail string `json:"email" bson:"email"` + Department string `json:"department" bson:"department"` + Course *constant.Course `json:"course" bson:"course"` + Specialisation *string `json:"specialisation" bson:"specialisation"` FirstName string `json:"firstName" bson:"firstName"` MiddleName *string `json:"middleName" bson:"middleName"` LastName string `json:"lastName" bson:"lastName"` ProfilePicture *misc.Attachment `json:"profilePicture" bson:"profilePicture"` - Gender constant.Gender `json:"gender" bson:"gender"` + Gender *constant.Gender `json:"gender" bson:"gender"` DOB *primitive.DateTime `json:"dob" bson:"dob"` PermanentAddress string `json:"permanentAddress" bson:"permanentAddress"` PresentAddress string `json:"presentAddress" bson:"presentAddress"` @@ -141,6 +141,7 @@ type Student struct { Academics Academics `json:"academics" bson:"academics"` WorkExperience []WorkExperience `json:"workExperience" bson:"workExperience"` SocialProfiles SocialProfiles `json:"socialProfiles" bson:"socialProfiles"` + Extras Extras `json:"extras" bson:"extras"` // metadata StructVersion int `json:"version" bson:"version"`