Skip to content

Commit

Permalink
Merge pull request #912 from factly/fix/minor-issues
Browse files Browse the repository at this point in the history
Fix/minor issues
  • Loading branch information
shreeharsha-factly authored Jul 20, 2023
2 parents f5fa2b9 + 710a7ac commit a9a1085
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
16 changes: 10 additions & 6 deletions server/service/core/action/category/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ func create(w http.ResponseWriter, r *http.Request) {
errorx.Render(w, errorx.Parser(errorx.DecodeError()))
return
}
// Check if parent category exist or not

categoryService := service.GetCategoryService()
_, err = categoryService.GetById(sID, int(category.ParentID))
if err != nil {
loggerx.Error(err)
errorx.Render(w, errorx.Parser(errorx.GetMessage("Parent category does not exist", http.StatusUnprocessableEntity)))
return

if category.ParentID != 0 {
// Check if parent category exist or not
_, err = categoryService.GetById(sID, int(category.ParentID))
if err != nil {
loggerx.Error(err)
errorx.Render(w, errorx.Parser(errorx.GetMessage("Parent category does not exist", http.StatusUnprocessableEntity)))
return
}
}

result, serviceErr := categoryService.Create(r.Context(), sID, uID, category)
Expand Down
14 changes: 8 additions & 6 deletions server/service/core/action/category/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@ func update(w http.ResponseWriter, r *http.Request) {
errorx.Render(w, errorx.Parser(errorx.RecordNotFound()))
return
}
// Check if parent category exist or not
_, err = categoryService.GetById(sID, int(category.ParentID))
if err != nil {
loggerx.Error(err)
errorx.Render(w, errorx.Parser(errorx.GetMessage("Parent category does not exist", http.StatusUnprocessableEntity)))
return
if category.ParentID != 0 {
// Check if parent category exist or not
_, err = categoryService.GetById(sID, int(category.ParentID))
if err != nil {
loggerx.Error(err)
errorx.Render(w, errorx.Parser(errorx.GetMessage("Parent category does not exist", http.StatusUnprocessableEntity)))
return
}
}
result, serviceErr := categoryService.Update(sID, uID, id, category)
if serviceErr != nil {
Expand Down
4 changes: 2 additions & 2 deletions server/service/fact-check/service/claimant.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
)

type claimantPaging struct {
Total int64 `json:"total"`
Nodes []Claimant `json:"nodes"`
Total int64 `json:"total"`
Nodes []model.Claimant `json:"nodes"`
}

// claimant model
Expand Down
2 changes: 1 addition & 1 deletion server/service/fact-check/service/rating.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func (rs RatingService) Default(ctx context.Context, sID, uID int, ratings []mod
return ratingPaging{}, errorx.Parser(errorx.DecodeError())
}

ratings[i].BackgroundColour, err = util.GetJSONDescription(ratings[i].Description)
ratings[i].BackgroundColour, err = util.GetJSONDescription(ratings[i].BackgroundColour)
if err != nil {
tx.Rollback()
loggerx.Error(err)
Expand Down

0 comments on commit a9a1085

Please sign in to comment.