adding more server/client communication commands, need to fix echo path params
This commit is contained in:
		@@ -4,12 +4,15 @@ import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"net/http"
 | 
			
		||||
 | 
			
		||||
	"github.com/deranjer/gvc/common"
 | 
			
		||||
	serverconfig "github.com/deranjer/gvc/server/serverconfig"
 | 
			
		||||
	"github.com/labstack/echo"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// GetInfo return the relevant repo specific info to the client
 | 
			
		||||
func (Server *GVCServer) GetInfo(context echo.Context) error {
 | 
			
		||||
	repo := context.Param("repoName")
 | 
			
		||||
	repo := context.Param("repo")
 | 
			
		||||
	fmt.Println("Asking about repo: ", repo)
 | 
			
		||||
	config := Server.Config
 | 
			
		||||
	var repoInfo RepoInfoRequest // Create an engine struct that contains basic server info as well as all repo info
 | 
			
		||||
	for _, knownRepo := range config.Repos {
 | 
			
		||||
@@ -31,14 +34,57 @@ func (Server *GVCServer) GetInfo(context echo.Context) error {
 | 
			
		||||
func (Server *GVCServer) LockFile(context echo.Context) error {
 | 
			
		||||
	fileType := context.Param("type")
 | 
			
		||||
	fileName := context.Param("name")
 | 
			
		||||
	repoName := context.Param("repo")
 | 
			
		||||
	var repo serverconfig.RepoConfig
 | 
			
		||||
	for i, knownRepo := range Server.Config.Repos {
 | 
			
		||||
		if knownRepo.RepoName == repoName {
 | 
			
		||||
			repo = Server.Config.Repos[i]
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	switch fileType {
 | 
			
		||||
	case "file":
 | 
			
		||||
		//common.CheckFileTypes(fileName, fileType,)
 | 
			
		||||
		err := common.CheckFileTypes(fileName, fileType, repo.Locked)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return fmt.Errorf("failed checking file lock: %s", err)
 | 
			
		||||
		}
 | 
			
		||||
		fmt.Println("Filename: ", fileName)
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Refresh sends all updated information to client (like git fetch)
 | 
			
		||||
func (Server *GVCServer) Refresh(context echo.Context) error {
 | 
			
		||||
	repoName := context.Param("repo")
 | 
			
		||||
	var serverRepo serverconfig.RepoConfig
 | 
			
		||||
	for i, repo := range Server.Config.Repos {
 | 
			
		||||
		if repo.RepoName == repoName {
 | 
			
		||||
			serverRepo = Server.Config.Repos[i]
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	// pull the locks and ignores to send back to client
 | 
			
		||||
	branches := serverRepo.LocalBranches
 | 
			
		||||
	serverLocks := serverRepo.Locked
 | 
			
		||||
	serverIgnores := serverRepo.DefaultIgnores
 | 
			
		||||
	refreshResult := common.RepoRefreshRequest{
 | 
			
		||||
		Branches: branches,
 | 
			
		||||
		Locked:   serverLocks,
 | 
			
		||||
		Ignores:  serverIgnores,
 | 
			
		||||
	}
 | 
			
		||||
	return context.JSON(http.StatusOK, refreshResult)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Revert fetches the supplied file (or entire repo) at version X and pushes it to the client // TODO: This should perhaps just be part of PULL?
 | 
			
		||||
func (Server *GVCServer) Revert(context echo.Context) error {
 | 
			
		||||
	repoName := context.Param("repo")
 | 
			
		||||
	return context.JSON(http.StatusOK, repoName)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Pull fetches the latest changes from the server to the client.
 | 
			
		||||
func (Server *GVCServer) Pull(context echo.Context) error {
 | 
			
		||||
	helloMsg := "server alive"
 | 
			
		||||
	return context.JSON(http.StatusOK, helloMsg)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Hello just verifies the server is running //TODO remove this, just extra shit we are sending
 | 
			
		||||
func (Server *GVCServer) Hello(context echo.Context) error {
 | 
			
		||||
	helloMsg := "server alive"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user