Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Feat/return id to post #58

Merged
merged 2 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions controllers/v1/rulesheets.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ func (rc *rulesheets) CreateRulesheet() gin.HandlerFunc {
}

var response = responses.NewRulesheet(&dto)
//id := c.Query("id")
c.JSON(http.StatusCreated, response)
}

}

// GetRulesheets godoc
Expand Down
2 changes: 1 addition & 1 deletion models/rulesheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// Rulesheet ...
type Rulesheet struct {
gorm.Model
Name string
Name string `gorm:"type:varchar(255);uniqueIndex"`
Description string
Slug string //`gorm:"unique_index"`
HasStringRule bool
Expand Down
9 changes: 6 additions & 3 deletions services/rulesheets.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,20 @@ func NewRulesheets(repository repository.Rulesheets, gitlabService Gitlab) Rules
// CreateRulesheet ...
func (rs rulesheets) Create(ctx context.Context, rulesheetDTO *dtos.Rulesheet) (err error) {

//TODO verifica unicidade do nome
rulesheet, _ := models.NewRulesheetV1(*rulesheetDTO)
rulesheet.Slug = slug.Make(rulesheet.Slug)
if rulesheet.Slug == "" {
rulesheet.Slug = slug.Make(rulesheet.Name)
}

fmt.Print(rulesheet.Slug)

err = rs.repository.Create(ctx, &rulesheet)
if err != nil {
log.Errorf("Error on create rulesheet into repository: %v", err)
return
}

rulesheetDTO.ID = rulesheet.ID
rulesheetDTO.Slug = rulesheet.Slug
err = rs.gitlabService.Save(rulesheetDTO, "[FEATWS BOT] Create Repo")
if err != nil {
log.Errorf("Error on save rulesheet into repository: %v", err)
Expand Down