Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
HARMONY-experimental-branch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Robin Korfmann
HARMONY-experimental-branch
Commits
92e9725e
Commit
92e9725e
authored
1 month ago
by
Dasan Ibrahim
Browse files
Options
Downloads
Patches
Plain Diff
Delete project to fix package problem
parent
670373e3
No related branches found
No related tags found
1 merge request
!4
merge dev to main
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/app/project/projects.go
+0
-226
0 additions, 226 deletions
src/app/project/projects.go
with
0 additions
and
226 deletions
src/app/project/projects.go
deleted
100644 → 0
+
0
−
226
View file @
670373e3
package
project
import
(
"context"
"errors"
"time"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/org-harmony/harmony/src/core/trace"
"github.com/org-harmony/harmony/src/core/validation"
)
// Errors that can be defined in the module
var
(
ErrProjectNotFound
=
errors
.
New
(
"project not found"
)
ErrProjectAlreadyExists
=
errors
.
New
(
"project already exists"
)
ErrInvalidProject
=
errors
.
New
(
"invalid project data"
)
ErrProjectUpdateFailed
=
errors
.
New
(
"failed to update project"
)
ErrProjectDeleteFailed
=
errors
.
New
(
"failed to delete project"
)
ErrProjectCreationFailed
=
errors
.
New
(
"failed to create project"
)
)
// Project represents a project in the system
type
Project
struct
{
ID
uuid
.
UUID
`json:"id"`
Name
string
`json:"name"`
Description
string
`json:"description"`
OwnerID
uuid
.
UUID
`json:"owner_id"`
Status
string
`json:"status"`
CreatedAt
time
.
Time
`json:"created_at"`
UpdatedAt
time
.
Time
`json:"updated_at"`
}
// NewProject creates a new instance of Project
func
NewProject
(
name
,
description
string
,
ownerID
uuid
.
UUID
,
status
string
)
*
Project
{
now
:=
time
.
Now
()
return
&
Project
{
ID
:
uuid
.
New
(),
Name
:
name
,
Description
:
description
,
OwnerID
:
ownerID
,
Status
:
status
,
CreatedAt
:
now
,
UpdatedAt
:
now
,
}
}
// Service defines operations available for projects
type
Service
interface
{
Create
(
ctx
context
.
Context
,
project
*
Project
)
error
GetByID
(
ctx
context
.
Context
,
id
uuid
.
UUID
)
(
*
Project
,
error
)
Edit
(
ctx
context
.
Context
,
project
*
Project
)
error
Delete
(
ctx
context
.
Context
,
id
uuid
.
UUID
)
error
List
(
ctx
context
.
Context
,
ownerID
uuid
.
UUID
)
([]
*
Project
,
error
)
}
type
service
struct
{
repo
Repository
validator
validation
.
V
logger
trace
.
Logger
}
func
(
s
*
service
)
GetByID
(
ctx
context
.
Context
,
id
uuid
.
UUID
)
(
*
Project
,
error
)
{
project
,
err
:=
s
.
repo
.
GetByID
(
ctx
,
id
)
if
err
!=
nil
{
s
.
logger
.
Error
(
"Failed to get project"
,
"error"
,
err
,
"id"
,
id
)
return
nil
,
ErrProjectNotFound
}
return
project
,
nil
}
func
(
s
*
service
)
Edit
(
ctx
context
.
Context
,
project
*
Project
)
error
{
return
s
.
Update
(
ctx
,
project
)
}
func
(
s
*
service
)
Update
(
ctx
context
.
Context
,
project
*
Project
)
error
{
if
err
:=
s
.
validator
.
Struct
(
project
);
err
!=
nil
{
s
.
logger
.
Error
(
"Invalid project data"
,
"error"
,
err
)
return
ErrInvalidProject
}
project
.
UpdatedAt
=
time
.
Now
()
if
err
:=
s
.
repo
.
Update
(
ctx
,
project
);
err
!=
nil
{
s
.
logger
.
Error
(
"Failed to update project"
,
"error"
,
err
)
return
ErrProjectUpdateFailed
}
return
nil
}
func
(
s
*
service
)
Delete
(
ctx
context
.
Context
,
id
uuid
.
UUID
)
error
{
if
err
:=
s
.
repo
.
Delete
(
ctx
,
id
);
err
!=
nil
{
s
.
logger
.
Error
(
"Failed to delete project"
,
"error"
,
err
,
"id"
,
id
)
return
ErrProjectDeleteFailed
}
return
nil
}
func
(
s
*
service
)
List
(
ctx
context
.
Context
,
ownerID
uuid
.
UUID
)
([]
*
Project
,
error
)
{
projects
,
err
:=
s
.
repo
.
List
(
ctx
,
ownerID
)
if
err
!=
nil
{
s
.
logger
.
Error
(
"Failed to list projects"
,
"error"
,
err
,
"ownerID"
,
ownerID
)
return
nil
,
err
}
return
projects
,
nil
}
// Repository defines persistence operations for projects
type
Repository
interface
{
Create
(
ctx
context
.
Context
,
project
*
Project
)
error
GetByID
(
ctx
context
.
Context
,
id
uuid
.
UUID
)
(
*
Project
,
error
)
Update
(
ctx
context
.
Context
,
project
*
Project
)
error
Delete
(
ctx
context
.
Context
,
id
uuid
.
UUID
)
error
List
(
ctx
context
.
Context
,
ownerID
uuid
.
UUID
)
([]
*
Project
,
error
)
RepositoryName
()
string
}
type
repository
struct
{
db
*
pgxpool
.
Pool
}
func
NewRepository
(
db
*
pgxpool
.
Pool
)
Repository
{
return
&
repository
{
db
:
db
}
}
func
(
r
*
repository
)
RepositoryName
()
string
{
return
"project"
}
func
(
r
*
repository
)
Create
(
ctx
context
.
Context
,
project
*
Project
)
error
{
query
:=
`
INSERT INTO projects (id, name, description, owner_id, status, created_at, updated_at)
VALUES ($1, $2, $3, $4, $5, $6, $7)
`
_
,
err
:=
r
.
db
.
Exec
(
ctx
,
query
,
project
.
ID
,
project
.
Name
,
project
.
Description
,
project
.
OwnerID
,
project
.
Status
,
project
.
CreatedAt
,
project
.
UpdatedAt
,
)
return
err
}
func
(
r
*
repository
)
GetByID
(
ctx
context
.
Context
,
id
uuid
.
UUID
)
(
*
Project
,
error
)
{
query
:=
`
SELECT id, name, description, owner_id, status, created_at, updated_at
FROM projects
WHERE id = $1
`
var
project
Project
err
:=
r
.
db
.
QueryRow
(
ctx
,
query
,
id
)
.
Scan
(
&
project
.
ID
,
&
project
.
Name
,
&
project
.
Description
,
&
project
.
OwnerID
,
&
project
.
Status
,
&
project
.
CreatedAt
,
&
project
.
UpdatedAt
,
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
project
,
nil
}
func
(
r
*
repository
)
Update
(
ctx
context
.
Context
,
project
*
Project
)
error
{
query
:=
`
UPDATE projects
SET name = $1, description = $2, status = $3, updated_at = $4
WHERE id = $5
`
_
,
err
:=
r
.
db
.
Exec
(
ctx
,
query
,
project
.
Name
,
project
.
Description
,
project
.
Status
,
project
.
UpdatedAt
,
project
.
ID
,
)
return
err
}
func
(
r
*
repository
)
Delete
(
ctx
context
.
Context
,
id
uuid
.
UUID
)
error
{
query
:=
"DELETE FROM projects WHERE id = $1"
_
,
err
:=
r
.
db
.
Exec
(
ctx
,
query
,
id
)
return
err
}
func
(
r
*
repository
)
List
(
ctx
context
.
Context
,
ownerID
uuid
.
UUID
)
([]
*
Project
,
error
)
{
query
:=
`
SELECT id, name, description, owner_id, status, created_at, updated_at
FROM projects
WHERE owner_id = $1
ORDER BY created_at DESC
`
rows
,
err
:=
r
.
db
.
Query
(
ctx
,
query
,
ownerID
)
if
err
!=
nil
{
return
nil
,
err
}
defer
rows
.
Close
()
var
projects
[]
*
Project
for
rows
.
Next
()
{
var
project
Project
err
:=
rows
.
Scan
(
&
project
.
ID
,
&
project
.
Name
,
&
project
.
Description
,
&
project
.
OwnerID
,
&
project
.
Status
,
&
project
.
CreatedAt
,
&
project
.
UpdatedAt
,
)
if
err
!=
nil
{
return
nil
,
err
}
projects
=
append
(
projects
,
&
project
)
}
if
err
:=
rows
.
Err
();
err
!=
nil
{
return
nil
,
err
}
return
projects
,
nil
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment