Skip to content

Commit

Permalink
add CoursePreferences, MusicalInformation model
Browse files Browse the repository at this point in the history
  • Loading branch information
donaderoyan committed May 27, 2024
1 parent 186f5ec commit ca85e57
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 35 deletions.
28 changes: 17 additions & 11 deletions controllers/user/profile/input.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package profile

import model "github.com/donaderoyan/talentgrowth-be/models"

type UpdateProfileInput struct {
FirstName string `json:"firstName" validate:"required,alpha" updateValidation:"omitempty,alpha"`
LastName string `json:"lastName" validate:"required,alpha" updateValidation:"omitempty,alpha"`
Phone string `json:"phone" validate:"required,e164" updateValidation:"omitempty,e164"`
Address model.Address `json:"address" validate:"omitempty" updateValidation:"omitempty"`
Birthday string `json:"birthday" validate:"omitempty,customdate,datebeforetoday" updateValidation:"omitempty,customdate,datebeforetoday"`
Gender string `json:"gender" validate:"omitempty,oneof=male female" updateValidation:"omitempty,oneof=male female"`
Nationality string `json:"nationality" validate:"omitempty" updateValidation:"omitempty"`
Bio string `json:"bio" validate:"omitempty" updateValidation:"omitempty"`
ProfilePicture string `json:"profilePicture" validate:"omitempty,url" updateValidation:"omitempty,url"`
FirstName string `json:"firstName" validate:"required,alpha" updateValidation:"omitempty,alpha"`
LastName string `json:"lastName" validate:"required,alpha" updateValidation:"omitempty,alpha"`
Phone string `json:"phone" validate:"required,e164" updateValidation:"omitempty,e164"`
Address Address `json:"address" validate:"omitempty" updateValidation:"omitempty"`
Birthday string `json:"birthday" validate:"omitempty,customdate,datebeforetoday" updateValidation:"omitempty,customdate,datebeforetoday"`
Gender string `json:"gender" validate:"omitempty,oneof=male female" updateValidation:"omitempty,oneof=male female"`
Nationality string `json:"nationality" validate:"omitempty" updateValidation:"omitempty"`
Bio string `json:"bio" validate:"omitempty" updateValidation:"omitempty"`
ProfilePicture string `json:"profilePicture" validate:"omitempty,url" updateValidation:"omitempty,url"`
}

type Address struct {
Street string `json:"street,omitempty" validate:"omitempty" updateValidation:"omitempty"`
City string `json:"city" validate:"required" updateValidation:"omitempty"`
State string `json:"state" validate:"required" updateValidation:"omitempty"`
PostalCode string `json:"postalCode" validate:"required" updateValidation:"omitempty"`
Country string `json:"country" validate:"required" updateValidation:"omitempty"`
}
4 changes: 2 additions & 2 deletions controllers/user/profile/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (s *service) UpdateProfileService(userID string, input *UpdateProfileInput)
}

// Handle address update if present
if input.Address != (model.Address{}) {
if input.Address != (Address{}) {
correctFieldNames["address.street"] = input.Address.Street
correctFieldNames["address.city"] = input.Address.City
correctFieldNames["address.state"] = input.Address.State
Expand All @@ -48,7 +48,7 @@ func (s *service) UpdateProfileService(userID string, input *UpdateProfileInput)
for key, value := range correctFieldNames {
if value == nil || (reflect.TypeOf(value).Kind() == reflect.String && value == "") {
delete(correctFieldNames, key)
} else if val, ok := value.(model.Address); ok && val == (model.Address{}) {
} else if val, ok := value.(Address); ok && val == (Address{}) {
delete(correctFieldNames, key)
}
}
Expand Down
7 changes: 7 additions & 0 deletions models/course_preferences.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package model

type CoursePreferences struct {
PreferredLearningMode string `bson:"preferred_learning_mode" json:"preferred_learning_mode"`
Availability []string `bson:"availability" json:"availability"`
PreferredInstructors []string `bson:"preferred_instructors,omitempty" json:"preferred_instructors,omitempty"` // this may change when Instructor model is implemented
}
15 changes: 15 additions & 0 deletions models/musical_information.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package model

import "go.mongodb.org/mongo-driver/bson/primitive"

// MusicalInformation struct for user's musical details
type MusicalInformation struct {
ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"`
UserID primitive.ObjectID `bson:"user_id" json:"user_id"` // Reference to the User
SkillLevel string `bson:"skill_level" json:"skill_level"`
PrimaryInstrument string `bson:"primary_instrument" json:"primary_instrument"`
SecondaryInstruments []string `bson:"secondary_instruments,omitempty" json:"secondary_instruments,omitempty"`
Genres []string `bson:"genres" json:"genres"`
FavoriteArtists []string `bson:"favorite_artists,omitempty" json:"favorite_artists,omitempty"`
LearningGoals []string `bson:"learning_goals,omitempty" json:"learning_goals,omitempty"`
}
2 changes: 2 additions & 0 deletions models/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ type Model struct {
func RegisterModels() []string {
return []string{
"User",
"MusicalInformation",
"CoursePreferences",
// "Product", etc ...
}
}
45 changes: 23 additions & 22 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,35 @@ import (
)

type User struct {
ID primitive.ObjectID `bson:"_id,omitempty"`
FirstName string `bson:"firstName" validate:"alpha"`
LastName string `bson:"lastName" validate:"alpha"`
Email string `bson:"email" validate:"required,email"`
Password string `bson:"password" validate:"required"`
RememberToken string `bson:"rememberToken,omitempty"`
Phone string `bson:"phone" validate:"e164"`
Birthday time.Time `bson:"birthday,omitempty" validate:"omitempty,datetime"`
Gender string `bson:"gender,omitempty" validate:"omitempty,oneof=male female other"`
Nationality string `bson:"nationality,omitempty"`
Bio string `bson:"bio,omitempty"`
ProfilePicture string `bson:"profilePicture,omitempty" validate:"omitempty,url"`
ID primitive.ObjectID `bson:"_id,omitempty" json:"id"`
FirstName string `bson:"firstName" json:"firstName"`
LastName string `bson:"lastName" json:"lastName"`
Email string `bson:"email" json:"email"`
Password string `bson:"password" json:"password"`
RememberToken string `bson:"rememberToken,omitempty" json:"rememberToken,omitempty"`
Phone string `bson:"phone" json:"phone"`
Birthday time.Time `bson:"birthday,omitempty" json:"birthday,omitempty"`
Gender string `bson:"gender,omitempty" json:"gender,omitempty"`
Nationality string `bson:"nationality,omitempty" json:"nationality,omitempty"`
Bio string `bson:"bio,omitempty" json:"bio,omitempty"`
ProfilePicture string `bson:"profilePicture,omitempty" json:"profilePicture,omitempty"`
Address Address `bson:"address,omitempty" json:"address,omitempty"`

// Using 'dive' in validation to apply validation rules on each field of the struct
Address Address `bson:"address,omitempty" validate:"omitempty"`
MusicalInfoID primitive.ObjectID `bson:"musical_info_id,omitempty" json:"musical_info_id,omitempty"` // Reference to MusicalInformation
CoursePrefs CoursePreferences `bson:"course_preferences" json:"course_preferences"` // Using embedded approach for now, will be change when Instructor model is implemented

CreatedAt time.Time `bson:"createdAt"`
UpdatedAt time.Time `bson:"updatedAt"`
DeletedAt *time.Time `bson:"deletedAt,omitempty"`
CreatedAt time.Time `bson:"createdAt" json:"createdAt"`
UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt"`
DeletedAt *time.Time `bson:"deletedAt,omitempty" json:"deletedAt,omitempty"`
// RoleID primitive.ObjectID `bson:"roleId" validate:"required"` // currently not used
}

type Address struct {
Street string `bson:"street,omitempty" validate:"omitempty"`
City string `bson:"city" validate:"required"`
State string `bson:"state" validate:"required"`
PostalCode string `bson:"postalCode" validate:"required"`
Country string `bson:"country" validate:"required"`
Street string `bson:"street,omitempty" json:"street,omitempty"`
City string `bson:"city" json:"city"`
State string `bson:"state" json:"state"`
PostalCode string `bson:"postalCode" json:"postalCode"`
Country string `bson:"country" json:"country"`
}

// SoftDelete sets the DeletedAt field to the current time to mark an entry as deleted.
Expand Down

0 comments on commit ca85e57

Please sign in to comment.