Skip to content

Commit ca85e57

Browse files
committed
add CoursePreferences, MusicalInformation model
1 parent 186f5ec commit ca85e57

File tree

6 files changed

+66
-35
lines changed

6 files changed

+66
-35
lines changed

controllers/user/profile/input.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
package profile
22

3-
import model "github.com/donaderoyan/talentgrowth-be/models"
4-
53
type UpdateProfileInput struct {
6-
FirstName string `json:"firstName" validate:"required,alpha" updateValidation:"omitempty,alpha"`
7-
LastName string `json:"lastName" validate:"required,alpha" updateValidation:"omitempty,alpha"`
8-
Phone string `json:"phone" validate:"required,e164" updateValidation:"omitempty,e164"`
9-
Address model.Address `json:"address" validate:"omitempty" updateValidation:"omitempty"`
10-
Birthday string `json:"birthday" validate:"omitempty,customdate,datebeforetoday" updateValidation:"omitempty,customdate,datebeforetoday"`
11-
Gender string `json:"gender" validate:"omitempty,oneof=male female" updateValidation:"omitempty,oneof=male female"`
12-
Nationality string `json:"nationality" validate:"omitempty" updateValidation:"omitempty"`
13-
Bio string `json:"bio" validate:"omitempty" updateValidation:"omitempty"`
14-
ProfilePicture string `json:"profilePicture" validate:"omitempty,url" updateValidation:"omitempty,url"`
4+
FirstName string `json:"firstName" validate:"required,alpha" updateValidation:"omitempty,alpha"`
5+
LastName string `json:"lastName" validate:"required,alpha" updateValidation:"omitempty,alpha"`
6+
Phone string `json:"phone" validate:"required,e164" updateValidation:"omitempty,e164"`
7+
Address Address `json:"address" validate:"omitempty" updateValidation:"omitempty"`
8+
Birthday string `json:"birthday" validate:"omitempty,customdate,datebeforetoday" updateValidation:"omitempty,customdate,datebeforetoday"`
9+
Gender string `json:"gender" validate:"omitempty,oneof=male female" updateValidation:"omitempty,oneof=male female"`
10+
Nationality string `json:"nationality" validate:"omitempty" updateValidation:"omitempty"`
11+
Bio string `json:"bio" validate:"omitempty" updateValidation:"omitempty"`
12+
ProfilePicture string `json:"profilePicture" validate:"omitempty,url" updateValidation:"omitempty,url"`
13+
}
14+
15+
type Address struct {
16+
Street string `json:"street,omitempty" validate:"omitempty" updateValidation:"omitempty"`
17+
City string `json:"city" validate:"required" updateValidation:"omitempty"`
18+
State string `json:"state" validate:"required" updateValidation:"omitempty"`
19+
PostalCode string `json:"postalCode" validate:"required" updateValidation:"omitempty"`
20+
Country string `json:"country" validate:"required" updateValidation:"omitempty"`
1521
}

controllers/user/profile/service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (s *service) UpdateProfileService(userID string, input *UpdateProfileInput)
3636
}
3737

3838
// Handle address update if present
39-
if input.Address != (model.Address{}) {
39+
if input.Address != (Address{}) {
4040
correctFieldNames["address.street"] = input.Address.Street
4141
correctFieldNames["address.city"] = input.Address.City
4242
correctFieldNames["address.state"] = input.Address.State
@@ -48,7 +48,7 @@ func (s *service) UpdateProfileService(userID string, input *UpdateProfileInput)
4848
for key, value := range correctFieldNames {
4949
if value == nil || (reflect.TypeOf(value).Kind() == reflect.String && value == "") {
5050
delete(correctFieldNames, key)
51-
} else if val, ok := value.(model.Address); ok && val == (model.Address{}) {
51+
} else if val, ok := value.(Address); ok && val == (Address{}) {
5252
delete(correctFieldNames, key)
5353
}
5454
}

models/course_preferences.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package model
2+
3+
type CoursePreferences struct {
4+
PreferredLearningMode string `bson:"preferred_learning_mode" json:"preferred_learning_mode"`
5+
Availability []string `bson:"availability" json:"availability"`
6+
PreferredInstructors []string `bson:"preferred_instructors,omitempty" json:"preferred_instructors,omitempty"` // this may change when Instructor model is implemented
7+
}

models/musical_information.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package model
2+
3+
import "go.mongodb.org/mongo-driver/bson/primitive"
4+
5+
// MusicalInformation struct for user's musical details
6+
type MusicalInformation struct {
7+
ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"`
8+
UserID primitive.ObjectID `bson:"user_id" json:"user_id"` // Reference to the User
9+
SkillLevel string `bson:"skill_level" json:"skill_level"`
10+
PrimaryInstrument string `bson:"primary_instrument" json:"primary_instrument"`
11+
SecondaryInstruments []string `bson:"secondary_instruments,omitempty" json:"secondary_instruments,omitempty"`
12+
Genres []string `bson:"genres" json:"genres"`
13+
FavoriteArtists []string `bson:"favorite_artists,omitempty" json:"favorite_artists,omitempty"`
14+
LearningGoals []string `bson:"learning_goals,omitempty" json:"learning_goals,omitempty"`
15+
}

models/registry.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ type Model struct {
77
func RegisterModels() []string {
88
return []string{
99
"User",
10+
"MusicalInformation",
11+
"CoursePreferences",
1012
// "Product", etc ...
1113
}
1214
}

models/user.go

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,35 @@ import (
77
)
88

99
type User struct {
10-
ID primitive.ObjectID `bson:"_id,omitempty"`
11-
FirstName string `bson:"firstName" validate:"alpha"`
12-
LastName string `bson:"lastName" validate:"alpha"`
13-
Email string `bson:"email" validate:"required,email"`
14-
Password string `bson:"password" validate:"required"`
15-
RememberToken string `bson:"rememberToken,omitempty"`
16-
Phone string `bson:"phone" validate:"e164"`
17-
Birthday time.Time `bson:"birthday,omitempty" validate:"omitempty,datetime"`
18-
Gender string `bson:"gender,omitempty" validate:"omitempty,oneof=male female other"`
19-
Nationality string `bson:"nationality,omitempty"`
20-
Bio string `bson:"bio,omitempty"`
21-
ProfilePicture string `bson:"profilePicture,omitempty" validate:"omitempty,url"`
10+
ID primitive.ObjectID `bson:"_id,omitempty" json:"id"`
11+
FirstName string `bson:"firstName" json:"firstName"`
12+
LastName string `bson:"lastName" json:"lastName"`
13+
Email string `bson:"email" json:"email"`
14+
Password string `bson:"password" json:"password"`
15+
RememberToken string `bson:"rememberToken,omitempty" json:"rememberToken,omitempty"`
16+
Phone string `bson:"phone" json:"phone"`
17+
Birthday time.Time `bson:"birthday,omitempty" json:"birthday,omitempty"`
18+
Gender string `bson:"gender,omitempty" json:"gender,omitempty"`
19+
Nationality string `bson:"nationality,omitempty" json:"nationality,omitempty"`
20+
Bio string `bson:"bio,omitempty" json:"bio,omitempty"`
21+
ProfilePicture string `bson:"profilePicture,omitempty" json:"profilePicture,omitempty"`
22+
Address Address `bson:"address,omitempty" json:"address,omitempty"`
2223

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

26-
CreatedAt time.Time `bson:"createdAt"`
27-
UpdatedAt time.Time `bson:"updatedAt"`
28-
DeletedAt *time.Time `bson:"deletedAt,omitempty"`
27+
CreatedAt time.Time `bson:"createdAt" json:"createdAt"`
28+
UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt"`
29+
DeletedAt *time.Time `bson:"deletedAt,omitempty" json:"deletedAt,omitempty"`
2930
// RoleID primitive.ObjectID `bson:"roleId" validate:"required"` // currently not used
3031
}
3132

3233
type Address struct {
33-
Street string `bson:"street,omitempty" validate:"omitempty"`
34-
City string `bson:"city" validate:"required"`
35-
State string `bson:"state" validate:"required"`
36-
PostalCode string `bson:"postalCode" validate:"required"`
37-
Country string `bson:"country" validate:"required"`
34+
Street string `bson:"street,omitempty" json:"street,omitempty"`
35+
City string `bson:"city" json:"city"`
36+
State string `bson:"state" json:"state"`
37+
PostalCode string `bson:"postalCode" json:"postalCode"`
38+
Country string `bson:"country" json:"country"`
3839
}
3940

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

0 commit comments

Comments
 (0)