-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7119973
commit be31f46
Showing
11 changed files
with
189 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package musicalinfo | ||
|
||
type MusicalInfoInput struct { | ||
SkillLevel string `json:"skill_level" validate:"required" updateValidation:"omitempty"` | ||
PrimaryInstrument string `json:"primary_instrument" validate:"required" updateValidation:"omitempty"` | ||
SecondaryInstruments []string `json:"secondary_instruments,omitempty" validate:"omitempty" updateValidation:"omitempty"` | ||
Genres []string `json:"genres" validate:"omitempty" updateValidation:"omitempty"` | ||
FavoriteArtists []string `json:"favorite_artists,omitempty" validate:"omitempty" updateValidation:"omitempty"` | ||
LearningGoals []string `json:"learning_goals,omitempty" validate:"omitempty" updateValidation:"omitempty"` | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package musicalinfo | ||
|
||
import ( | ||
model "github.com/donaderoyan/talentgrowth-be/models" | ||
"go.mongodb.org/mongo-driver/bson" | ||
) | ||
|
||
func (s *service) UpdateMusicalInfoService(userID string, input *MusicalInfoInput) (*model.MusicalInfo, error) { | ||
|
||
fields := bson.M{ | ||
"skillLevel": input.SkillLevel, | ||
"primaryInstrument": input.PrimaryInstrument, | ||
"secondaryInstruments": input.SecondaryInstruments, | ||
"genres": input.Genres, | ||
"favoriteArtists": input.FavoriteArtists, | ||
"learningGoals": input.LearningGoals, | ||
} | ||
|
||
result, err := s.repository.UpdateMusicalInfo(userID, fields) | ||
|
||
return result, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package musicalinfo | ||
|
||
import ( | ||
model "github.com/donaderoyan/talentgrowth-be/models" | ||
"go.mongodb.org/mongo-driver/bson" | ||
) | ||
|
||
func (s *service) CreateMusicalInfoService(userID string, input *MusicalInfoInput) (*model.MusicalInfo, error) { | ||
|
||
fields := bson.M{ | ||
"skillLevel": input.SkillLevel, | ||
"primaryInstrument": input.PrimaryInstrument, | ||
"secondaryInstruments": input.SecondaryInstruments, | ||
"genres": input.Genres, | ||
"favoriteArtists": input.FavoriteArtists, | ||
"learningGoals": input.LearningGoals, | ||
} | ||
|
||
result, err := s.repository.CreateMusicalInfo(userID, fields) | ||
|
||
return result, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package musicalinfohandler | ||
|
||
import musicalinfo "github.com/donaderoyan/talentgrowth-be/controllers/user/musicalinfo" | ||
|
||
type handler struct { | ||
service musicalinfo.Service | ||
} | ||
|
||
func NewMusicalInfohandler(service musicalinfo.Service) *handler { | ||
return &handler{service: service} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package musicalinfohandler | ||
|
||
import ( | ||
"net/http" | ||
|
||
musicalinfo "github.com/donaderoyan/talentgrowth-be/controllers/user/musicalinfo" | ||
util "github.com/donaderoyan/talentgrowth-be/utils" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func (h *handler) CreateMusicalInfoHandler(ctx *gin.Context) { | ||
userID := ctx.Param("id") | ||
var input musicalinfo.MusicalInfoInput | ||
|
||
if err := ctx.ShouldBindJSON(&input); err != nil { | ||
util.ErrorResponse(ctx, "Create musical information failed", http.StatusBadRequest, http.MethodPost, err.Error()) | ||
} | ||
|
||
if errValidator := util.Validator(input, "validate"); errValidator != nil { | ||
util.ErrorResponse(ctx, "The input value is invalid", http.StatusBadRequest, http.MethodPost, errValidator.Error()) | ||
return | ||
} | ||
|
||
updateMusicalInfo, errUpdate := h.service.CreateMusicalInfoService(userID, &input) | ||
if errUpdate != nil { | ||
switch errUpdate.(type) { | ||
case *musicalinfo.MusicalInfoCreateError: | ||
util.ErrorResponse(ctx, "Create musical information failed", http.StatusBadRequest, http.MethodPost, errUpdate.Error()) | ||
return | ||
default: | ||
// Handle other unexpected errors | ||
util.ErrorResponse(ctx, "Internal server error", http.StatusInternalServerError, http.MethodPost, errUpdate.Error()) | ||
return | ||
} | ||
} | ||
|
||
util.APIResponse(ctx, "Musical information created successfully", http.StatusOK, http.MethodPost, updateMusicalInfo) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters