Skip to content

Modern Docker Management, Designed for Everyone

chore(dto): add dtos for most handlers

Kyle Mendell27d250017311
diff --git a/backend/internal/api/image_maturity_handler.go b/backend/internal/api/image_maturity_handler.go
index e9d03da2d..df8a95508 100644
--- a/backend/internal/api/image_maturity_handler.go
+++ b/backend/internal/api/image_maturity_handler.go
@@ -6,6 +6,7 @@ import (
"time"
"github.com/gin-gonic/gin"
+ "github.com/ofkm/arcane-backend/internal/dto"
"github.com/ofkm/arcane-backend/internal/models"
"github.com/ofkm/arcane-backend/internal/services"
)
@@ -95,20 +96,10 @@ func (h *ImageMaturityHandler) GetImageMaturity(c *gin.Context) {
})
}
-type SetMaturityRequest struct {
- Repository string `json:"repository" binding:"required"`
- Tag string `json:"tag" binding:"required"`
- Version string `json:"version" binding:"required"`
- Date string `json:"date"`
- Status string `json:"status" binding:"required"`
- UpdatesAvailable bool `json:"updatesAvailable"`
- Metadata map[string]interface{} `json:"metadata,omitempty"`
-}
-
func (h *ImageMaturityHandler) SetImageMaturity(c *gin.Context) {
imageID := c.Param("imageId")
- var req SetMaturityRequest
+ var req dto.SetMaturityDto
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"success": false,
diff --git a/backend/internal/api/routes.go b/backend/internal/api/routes.go
index eee00f7ad..d50f958cb 100644
--- a/backend/internal/api/routes.go
+++ b/backend/internal/api/routes.go
@@ -198,14 +198,6 @@ func setupSystemRoutes(api *gin.RouterGroup, dockerService *services.DockerClien
system.POST("/containers/start-all", systemHandler.StartAllContainers)
system.POST("/containers/start-stopped", systemHandler.StartAllStoppedContainers)
system.POST("/containers/stop-all", systemHandler.StopAllContainers)
-
- // {
- // "containers": true,
- // "images": true,
- // "volumes": true,
- // "networks": true,
- // "dangling": true
- // }
}
func setupContainerRoutes(api *gin.RouterGroup, services *Services) {
diff --git a/backend/internal/api/settings_handler.go b/backend/internal/api/settings_handler.go
index a9d74d58f..1fd71e03f 100644
--- a/backend/internal/api/settings_handler.go
+++ b/backend/internal/api/settings_handler.go
@@ -4,6 +4,7 @@ import (
"net/http"
"github.com/gin-gonic/gin"
+ "github.com/ofkm/arcane-backend/internal/dto"
"github.com/ofkm/arcane-backend/internal/models"
"github.com/ofkm/arcane-backend/internal/services"
)
@@ -34,24 +35,8 @@ func (h *SettingsHandler) GetSettings(c *gin.Context) {
})
}
-type UpdateSettingsRequest struct {
- DockerHost *string `json:"dockerHost,omitempty"`
- StacksDirectory *string `json:"stacksDirectory,omitempty"`
- AutoUpdate *bool `json:"autoUpdate,omitempty"`
- AutoUpdateInterval *int `json:"autoUpdateInterval,omitempty"`
- PollingEnabled *bool `json:"pollingEnabled,omitempty"`
- PollingInterval *int `json:"pollingInterval,omitempty"`
- PruneMode *string `json:"pruneMode,omitempty"`
- RegistryCredentials *models.JSON `json:"registryCredentials,omitempty"`
- TemplateRegistries *models.JSON `json:"templateRegistries,omitempty"`
- Auth *models.JSON `json:"auth,omitempty"`
- Onboarding *models.JSON `json:"onboarding,omitempty"`
- BaseServerURL *string `json:"baseServerUrl,omitempty"`
- MaturityThresholdDays *int `json:"maturityThresholdDays,omitempty"`
-}
-
func (h *SettingsHandler) UpdateSettings(c *gin.Context) {
- var req UpdateSettingsRequest
+ var req dto.UpdateSettingsDto
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"success": false,
diff --git a/backend/internal/api/stack_handler.go b/backend/internal/api/stack_handler.go
index 7c62b89d3..3c7d7b3a6 100644
--- a/backend/internal/api/stack_handler.go
+++ b/backend/internal/api/stack_handler.go
@@ -8,6 +8,7 @@ import (
"time"
"github.com/gin-gonic/gin"
+ "github.com/ofkm/arcane-backend/internal/dto"
"github.com/ofkm/arcane-backend/internal/models"
"github.com/ofkm/arcane-backend/internal/services"
)
@@ -24,30 +25,6 @@ func NewStackHandler(stackService *services.StackService) *StackHandler {
}
}
-type CreateStackRequest struct {
- Name string `json:"name" binding:"required"`
- ComposeContent string `json:"composeContent" binding:"required"`
- EnvContent *string `json:"envContent,omitempty"`
- AgentID *string `json:"agentId,omitempty"`
-}
-
-type UpdateStackRequest struct {
- Name *string `json:"name,omitempty"`
- ComposeContent *string `json:"composeContent,omitempty"`
- EnvContent *string `json:"envContent,omitempty"`
- AutoUpdate *bool `json:"autoUpdate,omitempty"`
-}
-
-type RedeployStackRequest struct {
- Profiles []string `json:"profiles,omitempty"`
- EnvOverrides map[string]string `json:"envOverrides,omitempty"`
-}
-
-type DestroyStackRequest struct {
- RemoveFiles bool `json:"removeFiles,omitempty"`
- RemoveVolumes bool `json:"removeVolumes,omitempty"`
-}
-
func (h *StackHandler) ListStacks(c *gin.Context) {
stacks, err := h.stackService.ListStacks(c.Request.Context())
if err != nil {
@@ -103,7 +80,7 @@ func (h *StackHandler) ListStacks(c *gin.Context) {
}
func (h *StackHandler) CreateStack(c *gin.Context) {
- var req CreateStackRequest
+ var req dto.CreateStackDto
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"success": false,
@@ -196,7 +173,7 @@ func (h *StackHandler) GetStack(c *gin.Context) {
func (h *StackHandler) UpdateStack(c *gin.Context) {
stackID := c.Param("id")
- var req UpdateStackRequest
+ var req dto.UpdateStackDto
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"success": false,
@@ -344,9 +321,9 @@ func (h *StackHandler) RestartStack(c *gin.Context) {
func (h *StackHandler) RedeployStack(c *gin.Context) {
stackID := c.Param("id")
- var req RedeployStackRequest
+ var req dto.RedeployStackDto
if err := c.ShouldBindJSON(&req); err != nil {
- req = RedeployStackRequest{
+ req = dto.RedeployStackDto{
Profiles: []string{},
EnvOverrides: map[string]string{},
}
@@ -386,9 +363,9 @@ func (h *StackHandler) DownStack(c *gin.Context) {
func (h *StackHandler) DestroyStack(c *gin.Context) {
stackID := c.Param("id")
- var req DestroyStackRequest
+ var req dto.DestroyStackDto
if err := c.ShouldBindJSON(&req); err != nil {
- req = DestroyStackRequest{
+ req = dto.DestroyStackDto{
RemoveFiles: false,
RemoveVolumes: false,
}
diff --git a/backend/internal/api/user_handler.go b/backend/internal/api/user_handler.go
index 5100db568..facb9e16c 100644
--- a/backend/internal/api/user_handler.go
+++ b/backend/internal/api/user_handler.go
@@ -6,6 +6,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/google/uuid"
+ "github.com/ofkm/arcane-backend/internal/dto"
"github.com/ofkm/arcane-backend/internal/models"
"github.com/ofkm/arcane-backend/internal/services"
"golang.org/x/crypto/bcrypt"
@@ -21,20 +22,6 @@ func NewUserHandler(userService *services.UserService) *UserHandler {
}
}
-type CreateUserRequest struct {
- Username string `json:"username" binding:"required"`
- Password string `json:"password" binding:"required"`
- DisplayName *string `json:"displayName,omitempty"`
- Email *string `json:"email,omitempty"`
- Roles []string `json:"roles,omitempty"`
-}
-
-type UpdateUserRequest struct {
- DisplayName *string `json:"displayName,omitempty"`
- Email *string `json:"email,omitempty"`
- Roles []string `json:"roles,omitempty"`
-}
-
func (h *UserHandler) ListUsers(c *gin.Context) {
users, err := h.userService.ListUsers(c.Request.Context())
if err != nil {
@@ -64,7 +51,7 @@ func (h *UserHandler) ListUsers(c *gin.Context) {
}
func (h *UserHandler) CreateUser(c *gin.Context) {
- var req CreateUserRequest
+ var req dto.CreateUserDto
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"success": false,
@@ -146,7 +133,7 @@ func (h *UserHandler) GetUser(c *gin.Context) {
func (h *UserHandler) UpdateUser(c *gin.Context) {
userID := c.Param("id")
- var req UpdateUserRequest
+ var req dto.UpdateUserDto
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"success": false,
diff --git a/backend/internal/dto/image_dto.go b/backend/internal/dto/image_dto.go
index 05d47a7c1..d4b7fa922 100644
--- a/backend/internal/dto/image_dto.go
+++ b/backend/internal/dto/image_dto.go
@@ -3,3 +3,13 @@ package dto
type ImagePullDto struct {
ImageName string `json:"imageName" binding:"required"`
}
+
+type SetMaturityDto struct {
+ Repository string `json:"repository" binding:"required"`
+ Tag string `json:"tag" binding:"required"`
+ Version string `json:"version" binding:"required"`
+ Date string `json:"date"`
+ Status string `json:"status" binding:"required"`
+ UpdatesAvailable bool `json:"updatesAvailable"`
+ Metadata map[string]interface{} `json:"metadata,omitempty"`
+}
diff --git a/backend/internal/dto/settings_dto.go b/backend/internal/dto/settings_dto.go
new file mode 100644
index 000000000..830701759
--- /dev/null
+++ b/backend/internal/dto/settings_dto.go
@@ -0,0 +1,19 @@
+package dto
+
+import "github.com/ofkm/arcane-backend/internal/models"
+
+type UpdateSettingsDto struct {
+ DockerHost *string `json:"dockerHost,omitempty"`
+ StacksDirectory *string `json:"stacksDirectory,omitempty"`
+ AutoUpdate *bool `json:"autoUpdate,omitempty"`
+ AutoUpdateInterval *int `json:"autoUpdateInterval,omitempty"`
+ PollingEnabled *bool `json:"pollingEnabled,omitempty"`
+ PollingInterval *int `json:"pollingInterval,omitempty"`
+ PruneMode *string `json:"pruneMode,omitempty"`
+ RegistryCredentials *models.JSON `json:"registryCredentials,omitempty"`
+ TemplateRegistries *models.JSON `json:"templateRegistries,omitempty"`
+ Auth *models.JSON `json:"auth,omitempty"`
+ Onboarding *models.JSON `json:"onboarding,omitempty"`
+ BaseServerURL *string `json:"baseServerUrl,omitempty"`
+ MaturityThresholdDays *int `json:"maturityThresholdDays,omitempty"`
+}
diff --git a/backend/internal/dto/stack_dto.go b/backend/internal/dto/stack_dto.go
new file mode 100644
index 000000000..fcd450f71
--- /dev/null
+++ b/backend/internal/dto/stack_dto.go
@@ -0,0 +1,25 @@
+package dto
+
+type CreateStackDto struct {
+ Name string `json:"name" binding:"required"`
+ ComposeContent string `json:"composeContent" binding:"required"`
+ EnvContent *string `json:"envContent,omitempty"`
+ AgentID *string `json:"agentId,omitempty"`
+}
+
+type UpdateStackDto struct {
+ Name *string `json:"name,omitempty"`
+ ComposeContent *string `json:"composeContent,omitempty"`
+ EnvContent *string `json:"envContent,omitempty"`
+ AutoUpdate *bool `json:"autoUpdate,omitempty"`
+}
+
+type RedeployStackDto struct {
+ Profiles []string `json:"profiles,omitempty"`
+ EnvOverrides map[string]string `json:"envOverrides,omitempty"`
+}
+
+type DestroyStackDto struct {
+ RemoveFiles bool `json:"removeFiles,omitempty"`
+ RemoveVolumes bool `json:"removeVolumes,omitempty"`
+}
diff --git a/backend/internal/dto/user_dto.go b/backend/internal/dto/user_dto.go
new file mode 100644
index 000000000..3871f7e45
--- /dev/null
+++ b/backend/internal/dto/user_dto.go
@@ -0,0 +1,15 @@
+package dto
+
+type CreateUserDto struct {
+ Username string `json:"username" binding:"required"`
+ Password string `json:"password" binding:"required"`
+ DisplayName *string `json:"displayName,omitempty"`
+ Email *string `json:"email,omitempty"`
+ Roles []string `json:"roles,omitempty"`
+}
+
+type UpdateUserDto struct {
+ DisplayName *string `json:"displayName,omitempty"`
+ Email *string `json:"email,omitempty"`
+ Roles []string `json:"roles,omitempty"`
+}