1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 07:49:41 +02:00

feat(api): introduce new datastore interface (#3802)

* feat(api): introduce new datastore interface

* refactor(api): refactor http and main layers

* refactor(api): refactor http and bolt layers
This commit is contained in:
Anthony Lapenna 2020-05-20 17:23:15 +12:00 committed by Anthony Lapenna
parent 493de20540
commit 25103f08f9
151 changed files with 792 additions and 1004 deletions

View file

@ -12,9 +12,8 @@ import (
// Handler is the HTTP handler used to handle team operations.
type Handler struct {
*mux.Router
TeamService portainer.TeamService
TeamMembershipService portainer.TeamMembershipService
AuthorizationService *portainer.AuthorizationService
DataStore portainer.DataStore
AuthorizationService *portainer.AuthorizationService
}
// NewHandler creates a handler to manage team operations.

View file

@ -28,7 +28,7 @@ func (handler *Handler) teamCreate(w http.ResponseWriter, r *http.Request) *http
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
}
team, err := handler.TeamService.TeamByName(payload.Name)
team, err := handler.DataStore.Team().TeamByName(payload.Name)
if err != nil && err != portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve teams from the database", err}
}
@ -40,7 +40,7 @@ func (handler *Handler) teamCreate(w http.ResponseWriter, r *http.Request) *http
Name: payload.Name,
}
err = handler.TeamService.CreateTeam(team)
err = handler.DataStore.Team().CreateTeam(team)
if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to persist the team inside the database", err}
}

View file

@ -16,19 +16,19 @@ func (handler *Handler) teamDelete(w http.ResponseWriter, r *http.Request) *http
return &httperror.HandlerError{http.StatusBadRequest, "Invalid team identifier route variable", err}
}
_, err = handler.TeamService.Team(portainer.TeamID(teamID))
_, err = handler.DataStore.Team().Team(portainer.TeamID(teamID))
if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find a team with the specified identifier inside the database", err}
} else if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find a team with the specified identifier inside the database", err}
}
err = handler.TeamService.DeleteTeam(portainer.TeamID(teamID))
err = handler.DataStore.Team().DeleteTeam(portainer.TeamID(teamID))
if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to delete the team from the database", err}
}
err = handler.TeamMembershipService.DeleteTeamMembershipByTeamID(portainer.TeamID(teamID))
err = handler.DataStore.TeamMembership().DeleteTeamMembershipByTeamID(portainer.TeamID(teamID))
if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to delete associated team memberships from the database", err}
}

View file

@ -26,7 +26,7 @@ func (handler *Handler) teamInspect(w http.ResponseWriter, r *http.Request) *htt
return &httperror.HandlerError{http.StatusForbidden, "Access denied to team", portainer.ErrResourceAccessDenied}
}
team, err := handler.TeamService.Team(portainer.TeamID(teamID))
team, err := handler.DataStore.Team().Team(portainer.TeamID(teamID))
if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find a team with the specified identifier inside the database", err}
} else if err != nil {

View file

@ -10,7 +10,7 @@ import (
// GET request on /api/teams
func (handler *Handler) teamList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
teams, err := handler.TeamService.Teams()
teams, err := handler.DataStore.Team().Teams()
if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve teams from the database", err}
}

View file

@ -26,7 +26,7 @@ func (handler *Handler) teamMemberships(w http.ResponseWriter, r *http.Request)
return &httperror.HandlerError{http.StatusForbidden, "Access denied to team", portainer.ErrResourceAccessDenied}
}
memberships, err := handler.TeamMembershipService.TeamMembershipsByTeamID(portainer.TeamID(teamID))
memberships, err := handler.DataStore.TeamMembership().TeamMembershipsByTeamID(portainer.TeamID(teamID))
if err != nil {
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve associated team memberships from the database", err}
}

View file

@ -30,7 +30,7 @@ func (handler *Handler) teamUpdate(w http.ResponseWriter, r *http.Request) *http
return &httperror.HandlerError{http.StatusBadRequest, "Invalid request payload", err}
}
team, err := handler.TeamService.Team(portainer.TeamID(teamID))
team, err := handler.DataStore.Team().Team(portainer.TeamID(teamID))
if err == portainer.ErrObjectNotFound {
return &httperror.HandlerError{http.StatusNotFound, "Unable to find a team with the specified identifier inside the database", err}
} else if err != nil {
@ -41,7 +41,7 @@ func (handler *Handler) teamUpdate(w http.ResponseWriter, r *http.Request) *http
team.Name = payload.Name
}
err = handler.TeamService.UpdateTeam(team.ID, team)
err = handler.DataStore.Team().UpdateTeam(team.ID, team)
if err != nil {
return &httperror.HandlerError{http.StatusNotFound, "Unable to persist team changes inside the database", err}
}