Skip to content

Commit

Permalink
Merge branch 'main' into sqlitch
Browse files Browse the repository at this point in the history
  • Loading branch information
Expressionless-Ball-Thing committed Oct 6, 2023
2 parents b8cda7f + 85cc526 commit 802281f
Show file tree
Hide file tree
Showing 47 changed files with 1,218 additions and 214 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Building docker containers using docker-compose
run: GO_MOD=go.mod docker-compose up -d --build
- name: Golang Tests
run: go test -v ./...
run: go test ./...
working-directory: ./backend
frontend_testing:
runs-on: ubuntu-latest
Expand Down
10 changes: 5 additions & 5 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
backend/ @hdphuong
postgres/ @hdphuong
utilities/ @hdphuong
services/ @hdphuong
backend/ @ShunyaoLiang
postgres/ @ShunyaoLiang
utilities/ @ShunyaoLiang
services/ @ShunyaoLiang

frontend/ @lauraw0 @james-teng-0
frontend/src/packages/editor @lauraw0 @james-teng-0 @hdphuong
frontend/src/packages/editor @lauraw0 @james-teng-0 @ShunyaoLiang
next/ @lauraw0 @james-teng-0

.github/ @csesoc/technical
Expand Down
26 changes: 6 additions & 20 deletions backend/database/repositories/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import (

// Implements IRepositoryInterface
type filesystemRepository struct {
frontEndID uuid.UUID
frontendRoot uuid.UUID
logicalName string
URL string
embeddedContext
}

// The ID for root, set this as the ID in a specified request
var FilesystemRootID uuid.UUID = uuid.Nil

// We really should use an ORM jesus this is ugly
func (rep filesystemRepository) query(query string, input ...interface{}) (FilesystemEntry, error) {
entity := FilesystemEntry{}
Expand Down Expand Up @@ -51,16 +52,6 @@ func (rep filesystemRepository) query(query string, input ...interface{}) (Files

// Returns: entry struct containing the entity that was just created
func (rep filesystemRepository) CreateEntry(file FilesystemEntry) (FilesystemEntry, error) {
if file.ParentFileID == FilesystemRootID {
// determine root ID
root, err := rep.GetRoot()
if err != nil {
return FilesystemEntry{}, errors.New("failed to get root")
}

file.ParentFileID = root.EntityID
}

var newID uuid.UUID
err := rep.ctx.Query("SELECT new_entity($1, $2, $3, $4)", []interface{}{file.ParentFileID, file.LogicalName, file.OwnerUserId, file.IsDocument}, &newID)
if err != nil {
Expand All @@ -70,17 +61,12 @@ func (rep filesystemRepository) CreateEntry(file FilesystemEntry) (FilesystemEnt
}

func (rep filesystemRepository) GetEntryWithID(ID uuid.UUID) (FilesystemEntry, error) {
if ID == FilesystemRootID {
return rep.GetRoot()
}

result, err := rep.query("SELECT * FROM filesystem WHERE EntityID = $1", ID)
return result, err
}

func (rep filesystemRepository) GetRoot() (FilesystemEntry, error) {
// Root is currently set to ID 1
return rep.query("SELECT * FROM filesystem WHERE EntityID = $1", FilesystemRootID)
return rep.query("SELECT * FROM filesystem WHERE EntityID = $1", rep.frontendRoot)
}

func (rep filesystemRepository) GetEntryWithParentID(ID uuid.UUID) (FilesystemEntry, error) {
Expand All @@ -95,7 +81,7 @@ func (rep filesystemRepository) GetIDWithPath(path string) (uuid.UUID, error) {
}

// Determine main parent
parent, err := rep.query("SELECT * FROM filesystem WHERE LogicalName = $1", parentNames[1])
parent, err := rep.query("SELECT * FROM filesystem WHERE LogicalName = $1 AND Parent = $2", parentNames[1], rep.frontendRoot)
if err != nil {
return uuid.Nil, err
}
Expand Down
35 changes: 34 additions & 1 deletion backend/database/repositories/frontends.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
package repositories

import (
"fmt"

"github.com/google/uuid"
)

type frontendsRepository struct {
embeddedContext
}

const InvalidFrontend = -1

func NewFrontendRepo(logicalName string, URL string, embeddedContext embeddedContext) (filesystemRepository, error) {
rows, err := embeddedContext.ctx.QueryRow("SELECT * from new_frontend($1, $2)", []interface{}{logicalName, URL})
if err != nil {
return filesystemRepository{}, fmt.Errorf("Error setting up frontend in Postgres (new_frontend): %w", err)
}

defer rows.Close()

var frontendID uuid.UUID
var frontendRoot uuid.UUID

if rows.Next() {
err := rows.Scan(&frontendID, &frontendRoot)
if err != nil {
return filesystemRepository{}, fmt.Errorf("Error scanning columns within new_frontend: %w", err)
}
}

return filesystemRepository{
frontendID,
frontendRoot,
logicalName,
URL,
embeddedContext,
}, nil
}

// GetFrontendFromURL is the implementation of the frontend repository for frontendRepository
func (rep frontendsRepository) GetFrontendFromURL(url string) int {
var frontendId int
err := rep.ctx.Query("SELECT FrontendId from frontend where FrontendUrl = $1;", []interface{}{url}, &frontendId)
err := rep.ctx.Query("SELECT ID from frontend where URL = $1;", []interface{}{url}, &frontendId)
if err != nil {
return InvalidFrontend
}
Expand Down
9 changes: 4 additions & 5 deletions backend/database/repositories/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"sync"

"cms.csesoc.unsw.edu.au/database/contexts"
"github.com/google/uuid"
)

// Start up a database connection with a provided context
Expand All @@ -15,10 +16,8 @@ var context contexts.DatabaseContext = nil
// Open constructors available for everyone

// NewFilesystemRepo instantiates a new file system repository with the current embedded context
func NewFilesystemRepo(context contexts.DatabaseContext) FilesystemRepository {
return filesystemRepository{
embeddedContext{context},
}
func NewFilesystemRepo(logicalName string, URL string, context contexts.DatabaseContext) (FilesystemRepository, error) {
return NewFrontendRepo(logicalName, URL, embeddedContext{context})
}

// NewGroupsRepo instantiates a new groups repository
Expand All @@ -36,7 +35,7 @@ func NewFrontendsRepo(context contexts.DatabaseContext) FrontendsRepository {
}

// NewPersonRepo instantiates a new person repository
func NewPersonRepo(frontendId int) PersonRepository {
func NewPersonRepo(frontendId uuid.UUID) PersonRepository {
return personRepository{
frontendId,
embeddedContext{getContext()},
Expand Down
Loading

0 comments on commit 802281f

Please sign in to comment.