Skip to content

Commit

Permalink
implement get configurations of project api.
Browse files Browse the repository at this point in the history
  • Loading branch information
Anupam-dagar committed Mar 13, 2022
1 parent 2ab5cdf commit 6601695
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
14 changes: 14 additions & 0 deletions controllers/configuration.controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
type ConfigurationControllerInterface interface {
CreateConfiguration(*gin.Context)
UpdateConfiguration(ctx *gin.Context)
GetConfigurations(ctx *gin.Context)
}

type ConfigurationController struct {
Expand Down Expand Up @@ -62,3 +63,16 @@ func (cc *ConfigurationController) UpdateConfiguration(ctx *gin.Context) {

utilities.ResponseWithSuccess(ctx, http.StatusAccepted, project)
}

func (cc *ConfigurationController) GetConfigurations(ctx *gin.Context) {
userId := ctx.GetString("id")
projectId := ctx.Param("projectId")

configurations, err := cc.ConfigurationService.GetConfigurations(projectId, userId)
if err != nil {
utilities.ResponseWithError(ctx, err)
return
}

utilities.ResponseWithSuccess(ctx, http.StatusOK, configurations)
}
10 changes: 10 additions & 0 deletions repositories/configuration.repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
type ConfigurationRepositoryInterface interface {
CreateConfiguration(*models.Configuration) error
UpdateConfigurationById(*models.Configuration, string) error
GetConfigurations(string) ([]models.Configuration, error)
}

type ConfigurationRepository struct {
Expand Down Expand Up @@ -39,3 +40,12 @@ func (cr *ConfigurationRepository) UpdateConfigurationById(configuration *models

return err
}

func (cr *ConfigurationRepository) GetConfigurations(projectId string) (configurations []models.Configuration, err error) {
db := cr.Db

db.Where("project_id = ?", projectId)
err = db.Find(&configurations).Error

return configurations, err
}
1 change: 1 addition & 0 deletions server/router/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ func (engine Router) ConfigurationRoute(routeGroup *gin.RouterGroup) {

configurationRoute.POST("/:projectId", oc.CreateConfiguration)
configurationRoute.PUT("/:projectId/:id", oc.UpdateConfiguration)
configurationRoute.GET("/:projectId", oc.GetConfigurations)
}
}
20 changes: 20 additions & 0 deletions services/configuration.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
type ConfigurationServiceInterface interface {
CreateConfiguration(models.ConfigurationCreateRequest, string, string) (models.Configuration, error)
UpdateConfiguration(models.ConfigurationUpdateRequest, string, string, string) (models.Configuration, error)
GetConfigurations(string, string) ([]models.Configuration, error)
}

type ConfigurationService struct {
Expand Down Expand Up @@ -65,3 +66,22 @@ func (cs *ConfigurationService) UpdateConfiguration(

return configuration, err
}

func (cs *ConfigurationService) GetConfigurations(projectId string, userId string) (configurations []models.Configuration, err error) {
userProjectPrivilege, err := cs.UserMappingRepository.GetUserLevelMapping(userId, projectId, constants.PROJECT)

if err != nil {
return configurations, err
}

if !userProjectPrivilege.IsRead {
return configurations, fmt.Errorf(string(constants.Unauthorised))
}

configurations, err = cs.ConfigurationRepository.GetConfigurations(projectId)
if err != nil {
return configurations, err
}

return configurations, err
}

0 comments on commit 6601695

Please sign in to comment.