Skip to content

Commit

Permalink
fix fix fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shalearkane committed Jan 31, 2024
1 parent fde919b commit 51c1f6f
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 36 deletions.
35 changes: 27 additions & 8 deletions handler/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func (h *Handler) MigrateStudentDataToV2(ctx *gin.Context) {
oldStudent.CompaniesAlloted = []string{}
}

errorArray := []string{}
var EndYearOffset int
var Course Constant.Course

Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -222,15 +236,17 @@ func (h *Handler) MigrateStudentDataToV2(ctx *gin.Context) {
Score: oldStudent.XiiPercentage,
},
EducationGap: educationGap,
SemesterDetails: Student.SemesterSPI{
SemesterSPI: Student.SemesterSPI{
One: oldStudent.SemesterOne,
Two: oldStudent.SemesterTwo,
Three: oldStudent.SemesterThree,
Four: oldStudent.SemesterFour,
Five: oldStudent.SemesterFive,
Six: oldStudent.SemesterSix,
Seven: oldStudent.SemesterSeven,
Eight: oldStudent.SemesterEight,
},
SummerTermDetails: Student.SummerTermSPI{
SummerTermSPI: Student.SummerTermSPI{
One: oldStudent.SummerOne,
Two: oldStudent.SummerTwo,
Three: oldStudent.SummerThree,
Expand Down Expand Up @@ -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()),
Expand Down
34 changes: 28 additions & 6 deletions handler/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
}

Expand All @@ -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
Expand All @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions model/student.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
Expand Down
45 changes: 23 additions & 22 deletions model/student2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down Expand Up @@ -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"`
}

Expand All @@ -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"`
Expand All @@ -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"`
Expand Down

0 comments on commit 51c1f6f

Please sign in to comment.