Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

snake case DTOs + cleanup DTOs #663

Merged
merged 9 commits into from
Sep 4, 2024
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
23 changes: 23 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,31 @@ linters:
- durationcheck
- sloglint
- unconvert
- tagliatelle

issues:
exclude-rules:
- path: repository/ingested_data_indexes_repository.go
text: "should be called, not discarded, to avoid a context leak"

linters-settings:
tagliatelle:
# Check the struct tag name case.
case:
# Use the struct field name to check the name of the struct tag.
# Default: false
use-field-name: true
# `camel` is used for `json` and `yaml`, and `header` is used for `header` (can be overridden)
# Default: {}
rules:
# Any struct tag type can be used.
# Support string case: `camel`, `pascal`, `kebab`, `snake`, `upperSnake`, `goCamel`, `goPascal`, `goKebab`, `goSnake`, `upper`, `lower`, `header`
json: snake
yaml: camel
xml: camel
toml: camel
bson: camel
avro: snake
mapstructure: kebab
env: upperSnake
envconfig: upperSnake
62 changes: 8 additions & 54 deletions api/handle_datamodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,14 @@ func handleGetDataModel(uc usecases.Usecases) func(c *gin.Context) {
}
}

type createTableInput struct {
Name string `json:"name"`
Description string `json:"description"`
}

func handleCreateTable(uc usecases.Usecases) func(c *gin.Context) {
return func(c *gin.Context) {
organizationID, err := utils.OrganizationIdFromRequest(c.Request)
if presentError(c, err) {
return
}

var input createTableInput
var input dto.CreateTableInput
if err := json.NewDecoder(c.Request.Body).Decode(&input); err != nil {
presentError(c, errors.Wrap(models.BadParameterError, err.Error()))
return
Expand All @@ -60,36 +55,9 @@ func handleCreateTable(uc usecases.Usecases) func(c *gin.Context) {
}
}

func handleUpdateDataModelTable(uc usecases.Usecases) func(c *gin.Context) {
return func(c *gin.Context) {
var input createFieldInput
if err := json.NewDecoder(c.Request.Body).Decode(&input); err != nil {
presentError(c, errors.Wrap(models.BadParameterError, err.Error()))
return
}
tableID := c.Param("tableID")

usecase := usecasesWithCreds(c.Request, uc).NewDataModelUseCase()
err := usecase.UpdateDataModelTable(c.Request.Context(), tableID, input.Description)
if presentError(c, err) {
return
}
c.Status(http.StatusNoContent)
}
}

type createFieldInput struct {
Name string `json:"name"`
Description string `json:"description"`
Type string `json:"type"`
Nullable bool `json:"nullable"`
IsEnum bool `json:"is_enum"`
IsUnique bool `json:"is_unique"`
}

func handleCreateField(uc usecases.Usecases) func(c *gin.Context) {
return func(c *gin.Context) {
var input createFieldInput
var input dto.CreateFieldInput
if err := json.NewDecoder(c.Request.Body).Decode(&input); err != nil {
presentError(c, errors.Wrap(models.BadParameterError, err.Error()))
return
Expand Down Expand Up @@ -117,15 +85,9 @@ func handleCreateField(uc usecases.Usecases) func(c *gin.Context) {
}
}

type updateFieldInput struct {
Description *string `json:"description"`
IsEnum *bool `json:"is_enum"`
IsUnique *bool `json:"is_unique"`
}

func handleUpdateDataModelField(uc usecases.Usecases) func(c *gin.Context) {
return func(c *gin.Context) {
var input updateFieldInput
var input dto.UpdateFieldInput
if err := c.ShouldBindJSON(&input); err != nil {
c.Status(http.StatusBadRequest)
return
Expand All @@ -145,22 +107,14 @@ func handleUpdateDataModelField(uc usecases.Usecases) func(c *gin.Context) {
}
}

type createLinkInput struct {
Name string `json:"name"`
ParentTableID string `json:"parent_table_id"`
ParentFieldID string `json:"parent_field_id"`
ChildTableID string `json:"child_table_id"`
ChildFieldID string `json:"child_field_id"`
}

func handleCreateLink(uc usecases.Usecases) func(c *gin.Context) {
return func(c *gin.Context) {
organizationID, err := utils.OrganizationIdFromRequest(c.Request)
if presentError(c, err) {
return
}

var input createLinkInput
var input dto.CreateLinkInput
if err := json.NewDecoder(c.Request.Body).Decode(&input); err != nil {
presentError(c, errors.Wrap(models.BadParameterError, err.Error()))
return
Expand All @@ -169,10 +123,10 @@ func handleCreateLink(uc usecases.Usecases) func(c *gin.Context) {
link := models.DataModelLinkCreateInput{
OrganizationID: organizationID,
Name: input.Name,
ParentTableID: input.ParentTableID,
ParentFieldID: input.ParentFieldID,
ChildTableID: input.ChildTableID,
ChildFieldID: input.ChildFieldID,
ParentTableID: input.ParentTableId,
ParentFieldID: input.ParentFieldId,
ChildTableID: input.ChildTableId,
ChildFieldID: input.ChildFieldId,
}

usecase := usecasesWithCreds(c.Request, uc).NewDataModelUseCase()
Expand Down
8 changes: 4 additions & 4 deletions api/handle_decision.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ func handlePostDecision(uc usecases.Usecases, marbleAppHost string) func(c *gin.
c.Request.Context(),
models.CreateDecisionInput{
OrganizationId: organizationId,
PayloadRaw: requestData.TriggerObjectRaw,
PayloadRaw: requestData.TriggerObject,
ScenarioId: requestData.ScenarioId,
TriggerObjectTable: requestData.TriggerObjectType,
TriggerObjectTable: requestData.ObjectType,
},
false,
true,
Expand Down Expand Up @@ -154,8 +154,8 @@ func handlePostAllDecisions(uc usecases.Usecases, marbleAppHost string) func(c *
c.Request.Context(),
models.CreateAllDecisionsInput{
OrganizationId: organizationId,
PayloadRaw: requestData.TriggerObjectRaw,
TriggerObjectTable: requestData.TriggerObjectType,
PayloadRaw: requestData.TriggerObject,
TriggerObjectTable: requestData.ObjectType,
},
)
if presentError(c, err) {
Expand Down
4 changes: 2 additions & 2 deletions api/handle_scenario_iterations.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

func handleListScenarioIterations(uc usecases.Usecases) func(c *gin.Context) {
return func(c *gin.Context) {
scenarioID := c.Query("scenarioId")
scenarioId := c.Query("scenario_id")
organizationId, err := utils.OrganizationIdFromRequest(c.Request)
if presentError(c, err) {
return
Expand All @@ -28,7 +28,7 @@ func handleListScenarioIterations(uc usecases.Usecases) func(c *gin.Context) {
c.Request.Context(),
organizationId,
models.GetScenarioIterationFilters{
ScenarioId: utils.PtrTo(scenarioID, &utils.PtrToOptions{OmitZero: true}),
ScenarioId: utils.PtrTo(scenarioId, &utils.PtrToOptions{OmitZero: true}),
})
if presentError(c, err) {
return
Expand Down
36 changes: 6 additions & 30 deletions api/handle_scenario_publications.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package api
import (
"fmt"
"net/http"
"time"

"github.com/cockroachdb/errors"
"github.com/gin-gonic/gin"
Expand All @@ -15,35 +14,15 @@ import (
"github.com/checkmarble/marble-backend/utils"
)

type APIScenarioPublication struct {
Id string `json:"id"`
Rank int32 `json:"rank"`
ScenarioId string `json:"scenarioID"`
ScenarioIterationId string `json:"scenarioIterationID"`
PublicationAction string `json:"publicationAction"`
CreatedAt time.Time `json:"createdAt"`
}

func NewAPIScenarioPublication(sp models.ScenarioPublication) APIScenarioPublication {
return APIScenarioPublication{
Id: sp.Id,
Rank: sp.Rank,
ScenarioId: sp.ScenarioId,
ScenarioIterationId: sp.ScenarioIterationId,
PublicationAction: sp.PublicationAction.String(),
CreatedAt: sp.CreatedAt,
}
}

func handleListScenarioPublications(uc usecases.Usecases) func(c *gin.Context) {
return func(c *gin.Context) {
organizationId, err := utils.OrganizationIdFromRequest(c.Request)
if presentError(c, err) {
return
}

scenarioID := c.Query("scenarioID")
scenarioIterationID := c.Query("scenarioIterationID")
scenarioID := c.Query("scenario_id")
scenarioIterationID := c.Query("scenario_iteration_id")

usecase := usecasesWithCreds(c.Request, uc).NewScenarioPublicationUsecase()
scenarioPublications, err := usecase.ListScenarioPublications(
Expand All @@ -56,7 +35,7 @@ func handleListScenarioPublications(uc usecases.Usecases) func(c *gin.Context) {
if presentError(c, err) {
return
}
c.JSON(http.StatusOK, pure_utils.Map(scenarioPublications, NewAPIScenarioPublication))
c.JSON(http.StatusOK, pure_utils.Map(scenarioPublications, dto.AdaptScenarioPublicationDto))
}
}

Expand All @@ -77,14 +56,11 @@ func handleCreateScenarioPublication(uc usecases.Usecases) func(c *gin.Context)
scenarioPublications, err := usecase.ExecuteScenarioPublicationAction(
c.Request.Context(),
organizationId,
models.PublishScenarioIterationInput{
ScenarioIterationId: data.ScenarioIterationId,
PublicationAction: models.PublicationActionFrom(data.PublicationAction),
})
dto.AdaptCreateScenarioPublicationBody(data))
if handleExpectedPublicationError(c, err) || presentError(c, err) {
return
}
c.JSON(http.StatusOK, pure_utils.Map(scenarioPublications, NewAPIScenarioPublication))
c.JSON(http.StatusOK, pure_utils.Map(scenarioPublications, dto.AdaptScenarioPublicationDto))
}
}

Expand All @@ -97,7 +73,7 @@ func handleGetScenarioPublication(uc usecases.Usecases) func(c *gin.Context) {
if presentError(c, err) {
return
}
c.JSON(http.StatusOK, NewAPIScenarioPublication(scenarioPublication))
c.JSON(http.StatusOK, dto.AdaptScenarioPublicationDto(scenarioPublication))
}
}

Expand Down
2 changes: 1 addition & 1 deletion api/handle_snoozes.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func handleSnoozeDecision(uc usecases.Usecases) func(c *gin.Context) {
}
}

func handleSnoozesOfScenarioIteartion(uc usecases.Usecases) func(c *gin.Context) {
func handleSnoozesOfScenarioIteration(uc usecases.Usecases) func(c *gin.Context) {
return func(c *gin.Context) {
_, err := utils.OrganizationIdFromRequest(c.Request)
if presentError(c, err) {
Expand Down
3 changes: 1 addition & 2 deletions api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func addRoutes(r *gin.Engine, auth Authentication, tokenHandler TokenHandler, uc
router.POST("/scenario-iterations/:iteration_id/commit",
handleCommitScenarioIterationVersion(uc))
router.POST("/scenario-iterations/:iteration_id/schedule-execution", handleCreateScheduledExecution(uc))
router.GET("/scenario-iterations/:iteration_id/active-snoozes", handleSnoozesOfScenarioIteartion(uc))
router.GET("/scenario-iterations/:iteration_id/active-snoozes", handleSnoozesOfScenarioIteration(uc))

router.GET("/scenario-iteration-rules", handleListRules(uc))
router.POST("/scenario-iteration-rules", handleCreateRule(uc))
Expand Down Expand Up @@ -150,7 +150,6 @@ func addRoutes(r *gin.Engine, auth Authentication, tokenHandler TokenHandler, uc

router.GET("/data-model", handleGetDataModel(uc))
router.POST("/data-model/tables", handleCreateTable(uc))
router.PATCH("/data-model/tables/:tableID", handleUpdateDataModelTable(uc))
router.POST("/data-model/links", handleCreateLink(uc))
router.POST("/data-model/tables/:tableID/fields", handleCreateField(uc))
router.PATCH("/data-model/fields/:fieldID", handleUpdateDataModelField(uc))
Expand Down
File renamed without changes.
63 changes: 18 additions & 45 deletions dto/custom_list_dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@ import (
)

type CustomList struct {
Id string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Id string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
CreatedAt_deprec time.Time `json:"createdAt"` //nolint:tagliatelle
UpdatedAt_deprec time.Time `json:"updatedAt"` //nolint:tagliatelle
}

func AdaptCustomListDto(list models.CustomList) CustomList {
return CustomList{
Id: list.Id,
Name: list.Name,
Description: list.Description,
CreatedAt: list.CreatedAt,
UpdatedAt: list.UpdatedAt,
Id: list.Id,
Name: list.Name,
Description: list.Description,
CreatedAt: list.CreatedAt,
UpdatedAt: list.UpdatedAt,
CreatedAt_deprec: list.CreatedAt,
UpdatedAt_deprec: list.UpdatedAt,
}
}

type CustomListWithValues struct {
Id string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Values []CustomListValue `json:"values"`
CustomList
Values []CustomListValue `json:"values"`
}

type CustomListValue struct {
Expand All @@ -41,12 +41,8 @@ type CustomListValue struct {

func AdaptCustomListWithValuesDto(list models.CustomList, values []models.CustomListValue) CustomListWithValues {
return CustomListWithValues{
Id: list.Id,
Name: list.Name,
Description: list.Description,
CreatedAt: list.CreatedAt,
UpdatedAt: list.UpdatedAt,
Values: pure_utils.Map(values, AdaptCustomListValueDto),
CustomList: AdaptCustomListDto(list),
Values: pure_utils.Map(values, AdaptCustomListValueDto),
}
}

Expand All @@ -71,29 +67,6 @@ type UpdateCustomListBodyDto struct {
Description string `json:"description"`
}

type UpdateCustomListInputDto struct {
CustomListID string `in:"path=customListId"`
Body *UpdateCustomListBodyDto `in:"body=json"`
}

type GetCustomListInputDto struct {
CustomListID string `in:"path=customListId"`
}

type DeleteCustomListInputDto struct {
CustomListID string `in:"path=customListId"`
}

type CreateCustomListValueInputDto struct {
CustomListID string `in:"path=customListId"`
Body *CreateCustomListValueBodyDto `in:"body=json"`
}

type CreateCustomListValueBodyDto struct {
Value string `json:"value"`
}

type DeleteCustomListValueInputDto struct {
CustomListID string `in:"path=customListId"`
CustomListValueId string `in:"path=customListValueId"`
}
Loading