Skip to content

Commit

Permalink
Social profile (#41)
Browse files Browse the repository at this point in the history
* move Social Profile to top level

* Locked fields added

* docker version update

---------

Co-authored-by: Vishisht Dubey <98794736+vishisht-dubey@users.noreply.github.com>
  • Loading branch information
shalearkane and vishisht-dubey authored Jun 8, 2024
1 parent ca7c568 commit b1d0b26
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 29 deletions.
2 changes: 0 additions & 2 deletions constants/datatypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ const (
TYPE_FLOAT64 = "float64"

// complex
TYPE_DATE = "date"
TYPE_PRIMITIVE_DATETIME = "primitive.DateTime"
TYPE_SOCIAL = "social"
TYPE_CHOICES = "choices"
)
40 changes: 24 additions & 16 deletions controller/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package controller
import (
"fmt"
"reflect"
"strings"

"strconv"

Expand Down Expand Up @@ -54,38 +53,40 @@ func AssignReservationCategory(category *interfaces.GenericField[string], isEWS
(**rc).IsPWD = isPWD.Value
}

func AssignSocialProfile(field *interfaces.GenericField[interfaces.TYPE_SOCIAL], social **studentModel.SocialProfile, forward bool) {
func AssignSocialProfile(profile *interfaces.SocialProfile, social **studentModel.SocialProfile, forward bool) {
if forward {
field.DataType = constants.TYPE_SOCIAL
profile.URL.DataType = constants.TYPE_STRING
profile.Username.DataType = constants.TYPE_STRING

if *social != nil {
field.IsNull = reflect2.IsNil(*social)
profile.URL.IsNull = false
profile.Username.IsNull = false

if !field.IsNull {
field.Value = (**social).URL + "|" + (**social).Username
}
profile.URL.Value = (*social).URL
profile.Username.Value = (*social).Username

field.IsVerified = &(*social).Verification.IsVerified
profile.URL.IsVerified = &(*social).Verification.IsVerified
profile.Username.IsVerified = &(*social).Verification.IsVerified

return
}

field.IsNull = true
field.Value = ""
profile.URL.IsNull = true
profile.Username.IsNull = true

return
}

// backward mapping

if field.IsNull {
if profile.URL.IsNull || profile.Username.IsNull {
return
}

*social = new(studentModel.SocialProfile)

val := field.Value
(**social).URL = strings.Split(val, "|")[0]
(**social).Username = strings.Split(val, "|")[1]
(**social).URL = profile.URL.Value
(**social).Username = profile.Username.Value
}

func AssignNilPossibleValue[V int | float64 | string | constantModel.Course | constantModel.Gender | primitive.DateTime](field *interfaces.GenericField[V], value **V, forward bool) {
Expand Down Expand Up @@ -236,7 +237,7 @@ func AssignBatch(profile *interfaces.GenericField[string], institute *studentMod
}
}

func MapProfileSocials(profile *interfaces.ProfileSocials, socials *studentModel.SocialProfiles, forward bool) {
func MapSocialProfiles(profile *interfaces.SocialProfiles, socials *studentModel.SocialProfiles, forward bool) {
AssignSocialProfile(&profile.LinkedIn, &socials.LinkedIn, forward)
AssignSocialProfile(&profile.Github, &socials.Github, forward)
AssignSocialProfile(&profile.CodeChef, &socials.CodeChef, forward)
Expand All @@ -258,6 +259,13 @@ func MapProfileInstitute(profile *interfaces.ProfileInstitute, institute *studen
AssignNilPossibleValue(&profile.Specialisation, &institute.Specialisation, forward)
AssignNilPossibleValue(&profile.Honours, &institute.Academics.Honours, forward)
AssignNilPossibleValue(&profile.ThesisEndDate, &institute.Academics.ThesisEndDate, forward)

if forward {
profile.RollNumber.IsLocked = true
profile.Batch.IsLocked = true
profile.InstituteEmail.IsLocked = true
profile.Department.IsLocked = true
}
}

func MapPastAcademics(profile *interfaces.ProfilePastAcademics, institute *studentModel.Academics, forward bool) {
Expand All @@ -278,7 +286,7 @@ func MapRanks(profile *interfaces.ProfilePastAcademics, rank *studentModel.Acade
func MapStudentToStudentProfile(profile *interfaces.StudentProfile, student *studentModel.Student, forward bool) {
// Profile
MapProfilePersonal(&profile.Profile.PersonalProfile, student, forward)
MapProfileSocials(&profile.Profile.SocialProfile, &student.SocialProfiles, forward)
MapSocialProfiles(&profile.SocialProfiles, &student.SocialProfiles, forward)
MapProfileInstitute(&profile.Profile.InstituteProfile, student, forward)

// Past Academics
Expand Down
27 changes: 16 additions & 11 deletions interfaces/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,21 @@ type ProfilePersonal struct {
MotherTongue GenericField[string] `json:"motherTongue,omitempty"`
}

type ProfileSocials struct {
LinkedIn GenericField[TYPE_SOCIAL] `json:"linkedIn,omitempty"`
Github GenericField[TYPE_SOCIAL] `json:"github,omitempty"`
Kaggle GenericField[TYPE_SOCIAL] `json:"kaggle,omitempty"`
MicrosoftTeams GenericField[TYPE_SOCIAL] `json:"microsoftTeams,omitempty"`
Skype GenericField[TYPE_SOCIAL] `json:"skype,omitempty"`
GoogleScholar GenericField[TYPE_SOCIAL] `json:"googleScholar,omitempty"`
Codeforces GenericField[TYPE_SOCIAL] `json:"codeforces,omitempty"`
CodeChef GenericField[TYPE_SOCIAL] `json:"codechef,omitempty"`
Leetcode GenericField[TYPE_SOCIAL] `json:"leetcode,omitempty"`
type SocialProfile struct {
URL GenericField[string] `json:"url,omitempty"`
Username GenericField[string] `json:"username,omitempty"`
}

type SocialProfiles struct {
LinkedIn SocialProfile `json:"linkedIn,omitempty"`
Github SocialProfile `json:"github,omitempty"`
Kaggle SocialProfile `json:"kaggle,omitempty"`
MicrosoftTeams SocialProfile `json:"microsoftTeams,omitempty"`
Skype SocialProfile `json:"skype,omitempty"`
GoogleScholar SocialProfile `json:"googleScholar,omitempty"`
Codeforces SocialProfile `json:"codeforces,omitempty"`
CodeChef SocialProfile `json:"codechef,omitempty"`
Leetcode SocialProfile `json:"leetcode,omitempty"`
}

type GenericRank struct {
Expand All @@ -71,7 +76,6 @@ type ProfileInstitute struct {

type ProfileDetails struct {
PersonalProfile ProfilePersonal `json:"personal_profile,omitempty"`
SocialProfile ProfileSocials `json:"social_profile,omitempty"`
InstituteProfile ProfileInstitute `json:"institute_profile,omitempty"`
}

Expand Down Expand Up @@ -126,6 +130,7 @@ type ProfileCurrentAcademics struct {

type StudentProfile struct {
Profile ProfileDetails `json:"profile,omitempty"`
SocialProfiles SocialProfiles `json:"social_profiles,omitempty"`
PastAcademics ProfilePastAcademics `json:"past_academics,omitempty"`
CurrentAcademics ProfileCurrentAcademics `json:"current_academics,omitempty"`
}

0 comments on commit b1d0b26

Please sign in to comment.