generated from dezh-tech/geb
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(domain): add get all route (#1)
- Loading branch information
1 parent
ea5e956
commit 4144c36
Showing
34 changed files
with
566 additions
and
314 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 |
---|---|---|
@@ -1 +1,5 @@ | ||
build | ||
**/.env | ||
**/config.yml | ||
.vscode | ||
**/*.log |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,53 @@ | ||
package handlers | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/dezh-tech/panda/pkg" | ||
"github.com/dezh-tech/panda/pkg/validator" | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
// CreateDomain creates a new domain. | ||
// | ||
// @Summary Create a new domain | ||
// @Description Create a new domain with the specified attributes. | ||
// @Tags domains | ||
// @Accept json | ||
// @Produce json | ||
// @Param domain body DomainCreateRequest true "Domain creation payload" | ||
// @Success 200 {object} pkg.ResponseDto{data=DomainCreateResponse} "Domain created successfully" | ||
// @Failure 400 {object} pkg.ResponseDto[validator.Varror] "Bad Request - Validation error" | ||
// @Failure 500 {object} pkg.ResponseDto[string] "Internal Server Error" | ||
// @Router /domains [post] | ||
func (dh Domain) create(c echo.Context) error { | ||
req := new(DomainCreateRequest) | ||
if err := c.Bind(req); err != nil { | ||
return echo.NewHTTPError(http.StatusBadRequest, pkg.ResponseDto{ | ||
Success: false, | ||
Error: validator.Varror{Error: "invalid input"}, | ||
}) | ||
} | ||
|
||
// Validate the request payload | ||
v := validator.NewValidator() | ||
validationErrors := v.Validate(req) | ||
if validationErrors != nil { | ||
return echo.NewHTTPError(http.StatusBadRequest, pkg.ResponseDto{ | ||
Success: false, | ||
Error: validator.Varror{ValidationErrors: validationErrors}, | ||
}) | ||
} | ||
|
||
// Call the domain service to create the domain | ||
ctx := c.Request().Context() | ||
resp, err := dh.service.Create(ctx, req.Domain, req.Status, req.BasePricePerIdentifier, req.DefaultTTL) | ||
if err != nil { | ||
return echo.NewHTTPError(http.StatusInternalServerError, pkg.ResponseDto{ | ||
Success: false, | ||
Error: validator.Varror{Error: echo.ErrInternalServerError.Error()}, | ||
}) | ||
} | ||
|
||
return c.JSON(http.StatusOK, pkg.ResponseDto{Success: true, Data: DomainCreateResponse{ID: resp}}) | ||
} |
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,43 @@ | ||
package handlers | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/dezh-tech/panda/pkg" | ||
"github.com/dezh-tech/panda/pkg/validator" | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
// DomainGetAll retrieves all domains. | ||
// | ||
// @Summary Retrieve all domains | ||
// @Description Get a list of all domains with their attributes. | ||
// @Tags domains | ||
// @Accept json | ||
// @Produce json | ||
// @Success 200 {object} pkg.ResponseDto{data=[]DomainGetResponse} "Domains retrieved successfully" | ||
// @Failure 500 {object} pkg.ResponseDto[string] "Internal Server Error" | ||
// @Router /domains [get] | ||
func (dh Domain) getAll(c echo.Context) error { | ||
ctx := c.Request().Context() | ||
domains, err := dh.service.GetAllWithoutFilter(ctx) | ||
if err != nil { | ||
return echo.NewHTTPError(http.StatusInternalServerError, pkg.ResponseDto{ | ||
Success: false, | ||
Error: validator.Varror{Error: echo.ErrInternalServerError.Error()}, | ||
}) | ||
} | ||
|
||
domainsRes := make([]DomainGetResponse, 0) | ||
for _, d := range *domains { | ||
domainsRes = append(domainsRes, DomainGetResponse{ | ||
Domain: d.Domain, | ||
BasePricePerIdentifier: d.BasePricePerIdentifier, | ||
DefaultTTL: d.DefaultTTL, | ||
Status: d.Status, | ||
}) | ||
} | ||
|
||
// Respond with the created domain's ID | ||
return c.JSON(http.StatusOK, pkg.ResponseDto{Success: true, Data: domainsRes}) | ||
} |
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,13 @@ | ||
package handlers | ||
|
||
import service "github.com/dezh-tech/panda/services/domain" | ||
|
||
type Domain struct { | ||
service service.Domain | ||
} | ||
|
||
func NewDomainService(domainSvc service.Domain) Domain { | ||
return Domain{ | ||
service: domainSvc, | ||
} | ||
} |
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,8 @@ | ||
package handlers | ||
|
||
type DomainCreateRequest struct { | ||
Domain string `json:"domain" validate:"required,hostname"` | ||
BasePricePerIdentifier uint `json:"base_price_per_identifier" validate:"required,min=1"` | ||
DefaultTTL uint32 `json:"default_ttl" validate:"required,min=1"` | ||
Status string `json:"status" validate:"required,oneof=active inactive"` | ||
} |
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,12 @@ | ||
package handlers | ||
|
||
type DomainCreateResponse struct { | ||
ID interface{} `json:"id"` | ||
} | ||
|
||
type DomainGetResponse struct { | ||
Domain string `json:"domain"` | ||
BasePricePerIdentifier uint `json:"base_price_per_identifier"` | ||
DefaultTTL uint32 `json:"default_ttl"` | ||
Status string `json:"status"` | ||
} |
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,12 @@ | ||
package handlers | ||
|
||
import ( | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
func (dh Domain) SetDomainRoutes(e *echo.Echo) { | ||
userGroup := e.Group("/domains") | ||
|
||
userGroup.POST("", dh.create) | ||
userGroup.GET("", dh.getAll) | ||
} |
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
deliveries/http/handlers/domain_handler/dto/domain_request.go
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
deliveries/http/handlers/domain_handler/dto/domain_response.go
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.