Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
MahtabBukhari committed May 17, 2024
1 parent 0b96e3a commit a10c5f2
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 101 deletions.
4 changes: 0 additions & 4 deletions db/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,10 @@ func InitDB() {
db.AutoMigrate(&ConnectionCodes{})
db.AutoMigrate(&BountyRoles{})
db.AutoMigrate(&UserInvoiceData{})
<<<<<<< HEAD
db.AutoMigrate(&WorkspaceRepositories{})
db.AutoMigrate(&WorkspaceFeatures{})
db.AutoMigrate(&FeaturePhase{})
db.AutoMigrate(&FeatureStory{})
=======
db.AutoMigrate(&WorkspaceFeatures{})
>>>>>>> e1f721d5 (Modify Features endpoint and add delete feature)

DB.MigrateTablesWithOrgUuid()
DB.MigrateOrganizationToWorkspace()
Expand Down
58 changes: 18 additions & 40 deletions db/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,11 @@ package db
import (
"errors"
"fmt"
<<<<<<< HEAD
"net/http"
"strings"
"time"

"github.com/stakwork/sphinx-tribes/utils"
=======
"github.com/stakwork/sphinx-tribes/utils"
"net/http"
"strings"
"time"
>>>>>>> e1f721d5 (Modify Features endpoint and add delete feature)
)

func (db database) GetFeaturesByWorkspaceUuid(uuid string, r *http.Request) []WorkspaceFeatures {
Expand Down Expand Up @@ -65,21 +58,34 @@ func (db database) CreateOrEditFeature(m WorkspaceFeatures) (WorkspaceFeatures,
m.Brief = strings.TrimSpace(m.Brief)
m.Requirements = strings.TrimSpace(m.Requirements)
m.Architecture = strings.TrimSpace(m.Architecture)
<<<<<<< HEAD

now := time.Now()
m.Updated = &now

if db.db.Model(&m).Where("uuid = ?", m.Uuid).Updates(&m).RowsAffected == 0 {
var existing WorkspaceFeatures
result := db.db.Model(&WorkspaceFeatures{}).Where("uuid = ?", m.Uuid).First(&existing)
if result.RowsAffected == 0 {

m.Created = &now
db.db.Create(&m)
}
} else {

db.db.Model(&WorkspaceFeatures{}).Where("uuid = ?", m.Uuid).Find(&m)
db.db.Model(&WorkspaceFeatures{}).Where("uuid = ?", m.Uuid).Updates(m)
}

db.db.Model(&WorkspaceFeatures{}).Where("uuid = ?", m.Uuid).First(&m)
return m, nil
}

func (db database) DeleteFeatureByUuid(uuid string) error {
result := db.db.Where("uuid = ?", uuid).Delete(&WorkspaceFeatures{})

if result.RowsAffected == 0 {
return errors.New("no feature found to delete")
}
return nil

}

func (db database) CreateOrEditFeaturePhase(phase FeaturePhase) (FeaturePhase, error) {
phase.Name = strings.TrimSpace(phase.Name)

Expand Down Expand Up @@ -175,32 +181,4 @@ func (db database) DeleteFeatureStoryByUuid(featureUuid, storyUuid string) error
return errors.New("no story found to delete")
}
return nil
=======
now := time.Now()
m.Updated = &now

var existing WorkspaceFeatures
result := db.db.Model(&WorkspaceFeatures{}).Where("uuid = ?", m.Uuid).First(&existing)
if result.RowsAffected == 0 {

m.Created = &now
db.db.Create(&m)
} else {

db.db.Model(&WorkspaceFeatures{}).Where("uuid = ?", m.Uuid).Updates(m)
}

db.db.Model(&WorkspaceFeatures{}).Where("uuid = ?", m.Uuid).First(&m)
return m, nil
}

func (db database) DeleteFeatureByUuid(uuid string) error {
result := db.db.Where("uuid = ?", uuid).Delete(&WorkspaceFeatures{})

if result.RowsAffected == 0 {
return errors.New("no feature found to delete")
}
return nil

>>>>>>> e1f721d5 (Modify Features endpoint and add delete feature)
}
6 changes: 0 additions & 6 deletions db/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,12 @@ type Database interface {
PersonUniqueNameFromName(name string) (string, error)
ProcessAlerts(p Person)
UserHasAccess(pubKeyFromAuth string, uuid string, role string) bool
<<<<<<< HEAD
CreateWorkspaceRepository(m WorkspaceRepositories) (WorkspaceRepositories, error)
GetWorkspaceRepositorByWorkspaceUuid(uuid string) []WorkspaceRepositories
=======
>>>>>>> e1f721d5 (Modify Features endpoint and add delete feature)
CreateOrEditFeature(m WorkspaceFeatures) (WorkspaceFeatures, error)
GetFeaturesByWorkspaceUuid(uuid string, r *http.Request) []WorkspaceFeatures
GetWorkspaceFeaturesCount(uuid string) int64
GetFeatureByUuid(uuid string) WorkspaceFeatures
<<<<<<< HEAD
CreateOrEditFeaturePhase(phase FeaturePhase) (FeaturePhase, error)
GetPhasesByFeatureUuid(featureUuid string) []FeaturePhase
GetFeaturePhaseByUuid(featureUuid, phaseUuid string) (FeaturePhase, error)
Expand All @@ -158,7 +154,5 @@ type Database interface {
GetFeatureStoriesByFeatureUuid(featureUuid string) ([]FeatureStory, error)
GetFeatureStoryByUuid(featureUuid, storyUuid string) (FeatureStory, error)
DeleteFeatureStoryByUuid(featureUuid, storyUuid string) error
=======
DeleteFeatureByUuid(uuid string) error
>>>>>>> e1f721d5 (Modify Features endpoint and add delete feature)
}
6 changes: 0 additions & 6 deletions db/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,6 @@ type WorkspaceUsersData struct {
Person
}

<<<<<<< HEAD
type WorkspaceRepositories struct {
ID uint `json:"id"`
Uuid string `gorm:"not null" json:"uuid"`
Expand All @@ -564,8 +563,6 @@ type WorkspaceRepositories struct {
UpdatedBy string `json:"updated_by"`
}

=======
>>>>>>> e1f721d5 (Modify Features endpoint and add delete feature)
type WorkspaceFeatures struct {
ID uint `json:"id"`
Uuid string `gorm:"not null" json:"uuid"`
Expand All @@ -580,7 +577,6 @@ type WorkspaceFeatures struct {
UpdatedBy string `json:"updated_by"`
}

<<<<<<< HEAD
type FeaturePhase struct {
Uuid string `json:"uuid" gorm:"primary_key"`
FeatureUuid string `json:"feature_uuid"`
Expand All @@ -592,8 +588,6 @@ type FeaturePhase struct {
UpdatedBy string `json:"updated_by"`
}

=======
>>>>>>> e1f721d5 (Modify Features endpoint and add delete feature)
type BountyRoles struct {
Name string `json:"name"`
}
Expand Down
35 changes: 8 additions & 27 deletions handlers/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,13 @@ package handlers
import (
"encoding/json"
"fmt"
<<<<<<< HEAD
"io"
"net/http"

=======
>>>>>>> e1f721d5 (Modify Features endpoint and add delete feature)
"github.com/go-chi/chi"
"github.com/rs/xid"
"github.com/stakwork/sphinx-tribes/auth"
"github.com/stakwork/sphinx-tribes/db"
<<<<<<< HEAD
=======
"io"
"net/http"
>>>>>>> e1f721d5 (Modify Features endpoint and add delete feature)
)

type featureHandler struct {
Expand Down Expand Up @@ -77,8 +69,7 @@ func (oh *featureHandler) CreateOrEditFeatures(w http.ResponseWriter, r *http.Re
json.NewEncoder(w).Encode(p)
}

<<<<<<< HEAD
func (oh *featureHandler) GetFeaturesByWorkspaceUuid(w http.ResponseWriter, r *http.Request) {
func (oh *featureHandler) DeleteFeature(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string)
if pubKeyFromAuth == "" {
Expand All @@ -88,14 +79,17 @@ func (oh *featureHandler) GetFeaturesByWorkspaceUuid(w http.ResponseWriter, r *h
}

uuid := chi.URLParam(r, "uuid")
workspaceFeatures := oh.db.GetFeaturesByWorkspaceUuid(uuid, r)
err := oh.db.DeleteFeatureByUuid(uuid)
if err != nil {
w.WriteHeader(http.StatusNotFound)
json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
return
}

w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(workspaceFeatures)
fmt.Fprint(w, "Feature deleted successfully")
}

=======
>>>>>>> e1f721d5 (Modify Features endpoint and add delete feature)
func (oh *featureHandler) GetWorkspaceFeaturesCount(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string)
Expand Down Expand Up @@ -128,11 +122,7 @@ func (oh *featureHandler) GetFeatureByUuid(w http.ResponseWriter, r *http.Reques
json.NewEncoder(w).Encode(workspaceFeature)
}

<<<<<<< HEAD
func (oh *featureHandler) CreateOrEditFeaturePhase(w http.ResponseWriter, r *http.Request) {
=======
func (oh *featureHandler) DeleteFeature(w http.ResponseWriter, r *http.Request) {
>>>>>>> e1f721d5 (Modify Features endpoint and add delete feature)
ctx := r.Context()
pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string)
if pubKeyFromAuth == "" {
Expand All @@ -141,7 +131,6 @@ func (oh *featureHandler) DeleteFeature(w http.ResponseWriter, r *http.Request)
return
}

<<<<<<< HEAD
newPhase := db.FeaturePhase{}
decoder := json.NewDecoder(r.Body)
err := decoder.Decode(&newPhase)
Expand Down Expand Up @@ -201,18 +190,13 @@ func (oh *featureHandler) DeleteFeaturePhase(w http.ResponseWriter, r *http.Requ
phaseUuid := chi.URLParam(r, "phase_uuid")

err := oh.db.DeleteFeaturePhase(featureUuid, phaseUuid)
=======
uuid := chi.URLParam(r, "uuid")
err := oh.db.DeleteFeatureByUuid(uuid)
>>>>>>> e1f721d5 (Modify Features endpoint and add delete feature)
if err != nil {
w.WriteHeader(http.StatusNotFound)
json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
return
}

w.WriteHeader(http.StatusOK)
<<<<<<< HEAD
json.NewEncoder(w).Encode(map[string]string{"message": "Phase deleted successfully"})
}

Expand Down Expand Up @@ -295,7 +279,4 @@ func (oh *featureHandler) DeleteStory(w http.ResponseWriter, r *http.Request) {

w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]string{"message": "Story deleted successfully"})
=======
fmt.Fprint(w, "Feature deleted successfully")
>>>>>>> e1f721d5 (Modify Features endpoint and add delete feature)
}
21 changes: 14 additions & 7 deletions handlers/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,11 +783,7 @@ func (oh *workspaceHandler) UpdateWorkspace(w http.ResponseWriter, r *http.Reque
json.NewEncoder(w).Encode(p)
}

<<<<<<< HEAD
func (oh *workspaceHandler) CreateWorkspaceRepository(w http.ResponseWriter, r *http.Request) {
=======
func (oh *workspaceHandler) GetFeaturesByWorkspaceUuid(w http.ResponseWriter, r *http.Request) {
>>>>>>> e1f721d5 (Modify Features endpoint and add delete feature)
ctx := r.Context()
pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string)
if pubKeyFromAuth == "" {
Expand All @@ -796,7 +792,6 @@ func (oh *workspaceHandler) GetFeaturesByWorkspaceUuid(w http.ResponseWriter, r
return
}

<<<<<<< HEAD
workspaceRepo := db.WorkspaceRepositories{}
body, _ := io.ReadAll(r.Body)
r.Body.Close()
Expand Down Expand Up @@ -846,10 +841,22 @@ func (oh *workspaceHandler) GetWorkspaceRepositorByWorkspaceUuid(w http.Response

uuid := chi.URLParam(r, "uuid")
workspaceFeatures := oh.db.GetWorkspaceRepositorByWorkspaceUuid(uuid)
=======

w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(workspaceFeatures)
}

func (oh *workspaceHandler) GetFeaturesByWorkspaceUuid(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string)
if pubKeyFromAuth == "" {
fmt.Println("no pubkey from auth")
w.WriteHeader(http.StatusUnauthorized)
return
}

uuid := chi.URLParam(r, "workspace_uuid")
workspaceFeatures := oh.db.GetFeaturesByWorkspaceUuid(uuid, r)
>>>>>>> e1f721d5 (Modify Features endpoint and add delete feature)

w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(workspaceFeatures)
Expand Down
37 changes: 37 additions & 0 deletions mocks/Database.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 1 addition & 8 deletions routes/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ func FeatureRoutes() chi.Router {
r.Use(auth.PubKeyContext)

r.Post("/", featureHandlers.CreateOrEditFeatures)
<<<<<<< HEAD
r.Get("/forworkspace/{uuid}", featureHandlers.GetFeaturesByWorkspaceUuid)
r.Get("/{uuid}", featureHandlers.GetFeatureByUuid)
r.Get("/workspace/count/{uuid}", featureHandlers.GetWorkspaceFeaturesCount)
r.Delete("/{uuid}", featureHandlers.DeleteFeature)

r.Post("/phase", featureHandlers.CreateOrEditFeaturePhase)
r.Get("/{feature_uuid}/phase", featureHandlers.GetFeaturePhases)
Expand All @@ -28,12 +27,6 @@ func FeatureRoutes() chi.Router {
r.Get("/{feature_uuid}/story", featureHandlers.GetStoriesByFeatureUuid)
r.Get("/{feature_uuid}/story/{story_uuid}", featureHandlers.GetStoryByUuid)
r.Delete("/{feature_uuid}/story/{story_uuid}", featureHandlers.DeleteStory)
=======
r.Get("/{uuid}", featureHandlers.GetFeatureByUuid)
r.Get("/workspace/count/{uuid}", featureHandlers.GetWorkspaceFeaturesCount)
r.Delete("/{uuid}", featureHandlers.DeleteFeature)

>>>>>>> e1f721d5 (Modify Features endpoint and add delete feature)
})
return r
}
4 changes: 1 addition & 3 deletions routes/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@ func WorkspaceRoutes() chi.Router {
r.Post("/mission", workspaceHandlers.UpdateWorkspace)
r.Post("/tactics", workspaceHandlers.UpdateWorkspace)
r.Post("/schematicurl", workspaceHandlers.UpdateWorkspace)
<<<<<<< HEAD

r.Post("/repositories", workspaceHandlers.CreateWorkspaceRepository)
r.Get("/repositories/{uuid}", workspaceHandlers.GetWorkspaceRepositorByWorkspaceUuid)
=======

r.Get("/{workspace_uuid}/features", workspaceHandlers.GetFeaturesByWorkspaceUuid)
>>>>>>> e1f721d5 (Modify Features endpoint and add delete feature)
})
return r
}

0 comments on commit a10c5f2

Please sign in to comment.