Satellite Projects db entity and api updated (#772)

* Satellite Projects db entity and api updated

* get users projects query updated with dbx
This commit is contained in:
Yehor Butko 2018-12-06 17:19:47 +02:00 committed by GitHub
parent d6f6ab56a1
commit 0c95fba4c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 196 additions and 111 deletions

View File

@ -16,6 +16,8 @@ type Projects interface {
GetAll(ctx context.Context) ([]Project, error)
// GetByOwnerID is a method for querying projects from the database by ownerID.
GetByOwnerID(ctx context.Context, ownerID uuid.UUID) ([]Project, error)
// GetByUserID is a method for querying all projects from the database by userID.
GetByUserID(ctx context.Context, userID uuid.UUID) ([]Project, error)
// Get is a method for querying project from the database by id.
Get(ctx context.Context, id uuid.UUID) (*Project, error)
// Insert is a method for inserting project into the database.
@ -33,6 +35,7 @@ type Project struct {
OwnerID *uuid.UUID `json:"ownerId"`
Name string `json:"name"`
CompanyName string `json:"companyName"`
Description string `json:"description"`
// stores last accepted version of terms of use.
TermsAccepted int `json:"termsAccepted"`
@ -42,13 +45,11 @@ type Project struct {
// ProjectInfo holds data needed to create/update Project
type ProjectInfo struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
CompanyName string `json:"companyName"`
Description string `json:"description"`
// Indicates if user accepted Terms & Conditions during project creation on UI
IsTermsAccepted bool `json:"isTermsAccepted"`
OwnerName string `json:"ownerName"`
CreatedAt time.Time `json:"createdAt"`
}

View File

@ -55,7 +55,8 @@ model project (
field id blob
field owner_id user.id setnull ( nullable, updatable )
field name text ( updatable )
field name text
field company_name text
field description text ( updatable )
// stores last accepted version of terms of use
field terms_accepted int ( updatable )
@ -71,6 +72,11 @@ read all (
select project
where project.owner_id = ?
)
read all (
select project
join project.id = project_member.project_id
where project_member.member_id = ?
)
create project ( )
update project ( where project.id = ? )
delete project ( where project.id = ? )

View File

@ -291,6 +291,7 @@ CREATE TABLE projects (
id BLOB NOT NULL,
owner_id BLOB REFERENCES users( id ) ON DELETE SET NULL,
name TEXT NOT NULL,
company_name TEXT NOT NULL,
description TEXT NOT NULL,
terms_accepted INTEGER NOT NULL,
created_at TIMESTAMP NOT NULL,
@ -661,6 +662,7 @@ type Project struct {
Id []byte
OwnerId []byte
Name string
CompanyName string
Description string
TermsAccepted int
CreatedAt time.Time
@ -674,7 +676,6 @@ type Project_Create_Fields struct {
type Project_Update_Fields struct {
OwnerId Project_OwnerId_Field
Name Project_Name_Field
Description Project_Description_Field
TermsAccepted Project_TermsAccepted_Field
}
@ -746,6 +747,24 @@ func (f Project_Name_Field) value() interface{} {
func (Project_Name_Field) _Column() string { return "name" }
type Project_CompanyName_Field struct {
_set bool
_value string
}
func Project_CompanyName(v string) Project_CompanyName_Field {
return Project_CompanyName_Field{_set: true, _value: v}
}
func (f Project_CompanyName_Field) value() interface{} {
if !f._set {
return nil
}
return f._value
}
func (Project_CompanyName_Field) _Column() string { return "company_name" }
type Project_Description_Field struct {
_set bool
_value string
@ -1126,6 +1145,7 @@ func (obj *sqlite3Impl) Create_Company(ctx context.Context,
func (obj *sqlite3Impl) Create_Project(ctx context.Context,
project_id Project_Id_Field,
project_name Project_Name_Field,
project_company_name Project_CompanyName_Field,
project_description Project_Description_Field,
project_terms_accepted Project_TermsAccepted_Field,
optional Project_Create_Fields) (
@ -1135,16 +1155,17 @@ func (obj *sqlite3Impl) Create_Project(ctx context.Context,
__id_val := project_id.value()
__owner_id_val := optional.OwnerId.value()
__name_val := project_name.value()
__company_name_val := project_company_name.value()
__description_val := project_description.value()
__terms_accepted_val := project_terms_accepted.value()
__created_at_val := __now
var __embed_stmt = __sqlbundle_Literal("INSERT INTO projects ( id, owner_id, name, description, terms_accepted, created_at ) VALUES ( ?, ?, ?, ?, ?, ? )")
var __embed_stmt = __sqlbundle_Literal("INSERT INTO projects ( id, owner_id, name, company_name, description, terms_accepted, created_at ) VALUES ( ?, ?, ?, ?, ?, ?, ? )")
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
obj.logStmt(__stmt, __id_val, __owner_id_val, __name_val, __description_val, __terms_accepted_val, __created_at_val)
obj.logStmt(__stmt, __id_val, __owner_id_val, __name_val, __company_name_val, __description_val, __terms_accepted_val, __created_at_val)
__res, err := obj.driver.Exec(__stmt, __id_val, __owner_id_val, __name_val, __description_val, __terms_accepted_val, __created_at_val)
__res, err := obj.driver.Exec(__stmt, __id_val, __owner_id_val, __name_val, __company_name_val, __description_val, __terms_accepted_val, __created_at_val)
if err != nil {
return nil, obj.makeErr(err)
}
@ -1252,7 +1273,7 @@ func (obj *sqlite3Impl) Get_Company_By_UserId(ctx context.Context,
func (obj *sqlite3Impl) All_Project(ctx context.Context) (
rows []*Project, err error) {
var __embed_stmt = __sqlbundle_Literal("SELECT projects.id, projects.owner_id, projects.name, projects.description, projects.terms_accepted, projects.created_at FROM projects")
var __embed_stmt = __sqlbundle_Literal("SELECT projects.id, projects.owner_id, projects.name, projects.company_name, projects.description, projects.terms_accepted, projects.created_at FROM projects")
var __values []interface{}
__values = append(__values)
@ -1268,7 +1289,7 @@ func (obj *sqlite3Impl) All_Project(ctx context.Context) (
for __rows.Next() {
project := &Project{}
err = __rows.Scan(&project.Id, &project.OwnerId, &project.Name, &project.Description, &project.TermsAccepted, &project.CreatedAt)
err = __rows.Scan(&project.Id, &project.OwnerId, &project.Name, &project.CompanyName, &project.Description, &project.TermsAccepted, &project.CreatedAt)
if err != nil {
return nil, obj.makeErr(err)
}
@ -1285,7 +1306,7 @@ func (obj *sqlite3Impl) Get_Project_By_Id(ctx context.Context,
project_id Project_Id_Field) (
project *Project, err error) {
var __embed_stmt = __sqlbundle_Literal("SELECT projects.id, projects.owner_id, projects.name, projects.description, projects.terms_accepted, projects.created_at FROM projects WHERE projects.id = ?")
var __embed_stmt = __sqlbundle_Literal("SELECT projects.id, projects.owner_id, projects.name, projects.company_name, projects.description, projects.terms_accepted, projects.created_at FROM projects WHERE projects.id = ?")
var __values []interface{}
__values = append(__values, project_id.value())
@ -1294,7 +1315,7 @@ func (obj *sqlite3Impl) Get_Project_By_Id(ctx context.Context,
obj.logStmt(__stmt, __values...)
project = &Project{}
err = obj.driver.QueryRow(__stmt, __values...).Scan(&project.Id, &project.OwnerId, &project.Name, &project.Description, &project.TermsAccepted, &project.CreatedAt)
err = obj.driver.QueryRow(__stmt, __values...).Scan(&project.Id, &project.OwnerId, &project.Name, &project.CompanyName, &project.Description, &project.TermsAccepted, &project.CreatedAt)
if err != nil {
return nil, obj.makeErr(err)
}
@ -1308,7 +1329,7 @@ func (obj *sqlite3Impl) All_Project_By_OwnerId(ctx context.Context,
var __cond_0 = &__sqlbundle_Condition{Left: "projects.owner_id", Equal: true, Right: "?", Null: true}
var __embed_stmt = __sqlbundle_Literals{Join: "", SQLs: []__sqlbundle_SQL{__sqlbundle_Literal("SELECT projects.id, projects.owner_id, projects.name, projects.description, projects.terms_accepted, projects.created_at FROM projects WHERE "), __cond_0}}
var __embed_stmt = __sqlbundle_Literals{Join: "", SQLs: []__sqlbundle_SQL{__sqlbundle_Literal("SELECT projects.id, projects.owner_id, projects.name, projects.company_name, projects.description, projects.terms_accepted, projects.created_at FROM projects WHERE "), __cond_0}}
var __values []interface{}
__values = append(__values)
@ -1329,7 +1350,40 @@ func (obj *sqlite3Impl) All_Project_By_OwnerId(ctx context.Context,
for __rows.Next() {
project := &Project{}
err = __rows.Scan(&project.Id, &project.OwnerId, &project.Name, &project.Description, &project.TermsAccepted, &project.CreatedAt)
err = __rows.Scan(&project.Id, &project.OwnerId, &project.Name, &project.CompanyName, &project.Description, &project.TermsAccepted, &project.CreatedAt)
if err != nil {
return nil, obj.makeErr(err)
}
rows = append(rows, project)
}
if err := __rows.Err(); err != nil {
return nil, obj.makeErr(err)
}
return rows, nil
}
func (obj *sqlite3Impl) All_Project_By_ProjectMember_MemberId(ctx context.Context,
project_member_member_id ProjectMember_MemberId_Field) (
rows []*Project, err error) {
var __embed_stmt = __sqlbundle_Literal("SELECT projects.id, projects.owner_id, projects.name, projects.company_name, projects.description, projects.terms_accepted, projects.created_at FROM projects JOIN project_members ON projects.id = project_members.project_id WHERE project_members.member_id = ?")
var __values []interface{}
__values = append(__values, project_member_member_id.value())
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
obj.logStmt(__stmt, __values...)
__rows, err := obj.driver.Query(__stmt, __values...)
if err != nil {
return nil, obj.makeErr(err)
}
defer __rows.Close()
for __rows.Next() {
project := &Project{}
err = __rows.Scan(&project.Id, &project.OwnerId, &project.Name, &project.CompanyName, &project.Description, &project.TermsAccepted, &project.CreatedAt)
if err != nil {
return nil, obj.makeErr(err)
}
@ -1628,11 +1682,6 @@ func (obj *sqlite3Impl) Update_Project_By_Id(ctx context.Context,
__sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("owner_id = ?"))
}
if update.Name._set {
__values = append(__values, update.Name.value())
__sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("name = ?"))
}
if update.Description._set {
__values = append(__values, update.Description.value())
__sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("description = ?"))
@ -1661,12 +1710,12 @@ func (obj *sqlite3Impl) Update_Project_By_Id(ctx context.Context,
return nil, obj.makeErr(err)
}
var __embed_stmt_get = __sqlbundle_Literal("SELECT projects.id, projects.owner_id, projects.name, projects.description, projects.terms_accepted, projects.created_at FROM projects WHERE projects.id = ?")
var __embed_stmt_get = __sqlbundle_Literal("SELECT projects.id, projects.owner_id, projects.name, projects.company_name, projects.description, projects.terms_accepted, projects.created_at FROM projects WHERE projects.id = ?")
var __stmt_get = __sqlbundle_Render(obj.dialect, __embed_stmt_get)
obj.logStmt("(IMPLIED) "+__stmt_get, __args...)
err = obj.driver.QueryRow(__stmt_get, __args...).Scan(&project.Id, &project.OwnerId, &project.Name, &project.Description, &project.TermsAccepted, &project.CreatedAt)
err = obj.driver.QueryRow(__stmt_get, __args...).Scan(&project.Id, &project.OwnerId, &project.Name, &project.CompanyName, &project.Description, &project.TermsAccepted, &project.CreatedAt)
if err == sql.ErrNoRows {
return nil, nil
}
@ -1870,13 +1919,13 @@ func (obj *sqlite3Impl) getLastProject(ctx context.Context,
pk int64) (
project *Project, err error) {
var __embed_stmt = __sqlbundle_Literal("SELECT projects.id, projects.owner_id, projects.name, projects.description, projects.terms_accepted, projects.created_at FROM projects WHERE _rowid_ = ?")
var __embed_stmt = __sqlbundle_Literal("SELECT projects.id, projects.owner_id, projects.name, projects.company_name, projects.description, projects.terms_accepted, projects.created_at FROM projects WHERE _rowid_ = ?")
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
obj.logStmt(__stmt, pk)
project = &Project{}
err = obj.driver.QueryRow(__stmt, pk).Scan(&project.Id, &project.OwnerId, &project.Name, &project.Description, &project.TermsAccepted, &project.CreatedAt)
err = obj.driver.QueryRow(__stmt, pk).Scan(&project.Id, &project.OwnerId, &project.Name, &project.CompanyName, &project.Description, &project.TermsAccepted, &project.CreatedAt)
if err != nil {
return nil, obj.makeErr(err)
}
@ -2045,6 +2094,16 @@ func (rx *Rx) All_Project_By_OwnerId(ctx context.Context,
return tx.All_Project_By_OwnerId(ctx, project_owner_id)
}
func (rx *Rx) All_Project_By_ProjectMember_MemberId(ctx context.Context,
project_member_member_id ProjectMember_MemberId_Field) (
rows []*Project, err error) {
var tx *Tx
if tx, err = rx.getTx(ctx); err != nil {
return
}
return tx.All_Project_By_ProjectMember_MemberId(ctx, project_member_member_id)
}
func (rx *Rx) Create_Company(ctx context.Context,
company_user_id Company_UserId_Field,
company_name Company_Name_Field,
@ -2065,6 +2124,7 @@ func (rx *Rx) Create_Company(ctx context.Context,
func (rx *Rx) Create_Project(ctx context.Context,
project_id Project_Id_Field,
project_name Project_Name_Field,
project_company_name Project_CompanyName_Field,
project_description Project_Description_Field,
project_terms_accepted Project_TermsAccepted_Field,
optional Project_Create_Fields) (
@ -2073,7 +2133,7 @@ func (rx *Rx) Create_Project(ctx context.Context,
if tx, err = rx.getTx(ctx); err != nil {
return
}
return tx.Create_Project(ctx, project_id, project_name, project_description, project_terms_accepted, optional)
return tx.Create_Project(ctx, project_id, project_name, project_company_name, project_description, project_terms_accepted, optional)
}
@ -2265,6 +2325,10 @@ type Methods interface {
project_owner_id Project_OwnerId_Field) (
rows []*Project, err error)
All_Project_By_ProjectMember_MemberId(ctx context.Context,
project_member_member_id ProjectMember_MemberId_Field) (
rows []*Project, err error)
Create_Company(ctx context.Context,
company_user_id Company_UserId_Field,
company_name Company_Name_Field,
@ -2278,6 +2342,7 @@ type Methods interface {
Create_Project(ctx context.Context,
project_id Project_Id_Field,
project_name Project_Name_Field,
project_company_name Project_CompanyName_Field,
project_description Project_Description_Field,
project_terms_accepted Project_TermsAccepted_Field,
optional Project_Create_Fields) (

View File

@ -25,6 +25,7 @@ CREATE TABLE projects (
id BLOB NOT NULL,
owner_id BLOB REFERENCES users( id ) ON DELETE SET NULL,
name TEXT NOT NULL,
company_name TEXT NOT NULL,
description TEXT NOT NULL,
terms_accepted INTEGER NOT NULL,
created_at TIMESTAMP NOT NULL,

View File

@ -39,6 +39,16 @@ func (projects *projects) GetByOwnerID(ctx context.Context, ownerID uuid.UUID) (
return projectsFromDbxSlice(projectsDbx)
}
// GetByUserID is a method for querying all projects from the database by userID.
func (projects *projects) GetByUserID(ctx context.Context, userID uuid.UUID) ([]satellite.Project, error) {
projectsDbx, err := projects.db.All_Project_By_ProjectMember_MemberId(ctx, dbx.ProjectMember_MemberId(userID[:]))
if err != nil {
return nil, err
}
return projectsFromDbxSlice(projectsDbx)
}
// Get is a method for querying project from the database by id.
func (projects *projects) Get(ctx context.Context, id uuid.UUID) (*satellite.Project, error) {
project, err := projects.db.Get_Project_By_Id(ctx, dbx.Project_Id(id[:]))
@ -67,6 +77,7 @@ func (projects *projects) Insert(ctx context.Context, project *satellite.Project
createdProject, err := projects.db.Create_Project(ctx,
dbx.Project_Id(projectID[:]),
dbx.Project_Name(project.Name),
dbx.Project_CompanyName(project.CompanyName),
dbx.Project_Description(project.Description),
dbx.Project_TermsAccepted(project.TermsAccepted),
dbx.Project_Create_Fields{
@ -87,15 +98,20 @@ func (projects *projects) Delete(ctx context.Context, id uuid.UUID) error {
return err
}
// Update is a method for updating user entity
// Update is a method for updating project entity
func (projects *projects) Update(ctx context.Context, project *satellite.Project) error {
_, err := projects.db.Update_Project_By_Id(ctx,
dbx.Project_Id(project.ID[:]),
dbx.Project_Update_Fields{
Name: dbx.Project_Name(project.Name),
updateFields := dbx.Project_Update_Fields{
Description: dbx.Project_Description(project.Description),
TermsAccepted: dbx.Project_TermsAccepted(project.TermsAccepted),
})
}
if project.OwnerID != nil {
updateFields.OwnerId = dbx.Project_OwnerId(project.OwnerID[:])
}
_, err := projects.db.Update_Project_By_Id(ctx,
dbx.Project_Id(project.ID[:]),
updateFields)
return err
}
@ -114,6 +130,7 @@ func projectFromDBX(project *dbx.Project) (*satellite.Project, error) {
u := &satellite.Project{
ID: id,
Name: project.Name,
CompanyName: project.CompanyName,
Description: project.Description,
TermsAccepted: project.TermsAccepted,
CreatedAt: project.CreatedAt,

View File

@ -25,10 +25,10 @@ func TestProjectsRepository(t *testing.T) {
// for project
name = "Project"
companyName = "Comp Name"
description = "some description"
// updated project values
newName = "NewProject"
newDescription = "some new description"
)
@ -59,6 +59,7 @@ func TestProjectsRepository(t *testing.T) {
project := &satellite.Project{
OwnerID: nil,
Name: name,
CompanyName: companyName,
Description: description,
TermsAccepted: 1,
}
@ -85,6 +86,7 @@ func TestProjectsRepository(t *testing.T) {
OwnerID: &owner.ID,
Name: name,
CompanyName: companyName,
Description: description,
TermsAccepted: 1,
}
@ -105,6 +107,7 @@ func TestProjectsRepository(t *testing.T) {
assert.Equal(t, projectsByOwnerID[0].OwnerID, &owner.ID)
assert.Equal(t, projectsByOwnerID[0].Name, name)
assert.Equal(t, projectsByOwnerID[0].CompanyName, companyName)
assert.Equal(t, projectsByOwnerID[0].Description, description)
assert.Equal(t, projectsByOwnerID[0].TermsAccepted, 1)
@ -116,6 +119,7 @@ func TestProjectsRepository(t *testing.T) {
assert.Equal(t, projectByID.ID, projectsByOwnerID[0].ID)
assert.Equal(t, projectByID.OwnerID, &owner.ID)
assert.Equal(t, projectByID.Name, name)
assert.Equal(t, projectByID.CompanyName, companyName)
assert.Equal(t, projectByID.Description, description)
assert.Equal(t, projectByID.TermsAccepted, 1)
})
@ -131,9 +135,8 @@ func TestProjectsRepository(t *testing.T) {
newProject := &satellite.Project{
ID: oldProjects[0].ID,
OwnerID: &owner.ID,
Name: newName,
Description: newDescription,
TermsAccepted: 1,
TermsAccepted: 2,
}
err = projects.Update(ctx, newProject)
@ -148,9 +151,8 @@ func TestProjectsRepository(t *testing.T) {
assert.Equal(t, newProject.ID, oldProjects[0].ID)
assert.Equal(t, newProject.OwnerID, &owner.ID)
assert.Equal(t, newProject.Name, newName)
assert.Equal(t, newProject.Description, newDescription)
assert.Equal(t, newProject.TermsAccepted, 1)
assert.Equal(t, newProject.TermsAccepted, 2)
})
t.Run("Delete project success", func(t *testing.T) {

View File

@ -14,6 +14,7 @@ const (
projectInputType = "projectInput"
fieldOwnerName = "ownerName"
fieldCompanyName = "companyName"
fieldDescription = "description"
// Indicates if user accepted Terms & Conditions during project creation
// Used in input model
@ -21,17 +22,17 @@ const (
)
// graphqlProject creates *graphql.Object type representation of satellite.ProjectInfo
func graphqlProject() *graphql.Object {
func graphqlProject(service *satellite.Service) *graphql.Object {
return graphql.NewObject(graphql.ObjectConfig{
Name: projectType,
Fields: graphql.Fields{
fieldID: &graphql.Field{
Type: graphql.String,
},
fieldOwnerName: &graphql.Field{
fieldName: &graphql.Field{
Type: graphql.String,
},
fieldName: &graphql.Field{
fieldCompanyName: &graphql.Field{
Type: graphql.String,
},
fieldDescription: &graphql.Field{
@ -43,6 +44,22 @@ func graphqlProject() *graphql.Object {
fieldCreatedAt: &graphql.Field{
Type: graphql.DateTime,
},
fieldOwnerName: &graphql.Field{
Type: graphql.String,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
project, _ := p.Source.(satellite.Project)
if project.OwnerID == nil {
return "", nil
}
user, err := service.GetUser(p.Context, *project.OwnerID)
if err != nil {
return "", nil
}
return user.FirstName + " " + user.LastName, nil
},
},
},
})
}
@ -55,6 +72,9 @@ func graphqlProjectInput() *graphql.InputObject {
fieldName: &graphql.InputObjectFieldConfig{
Type: graphql.String,
},
fieldCompanyName: &graphql.InputObjectFieldConfig{
Type: graphql.String,
},
fieldDescription: &graphql.InputObjectFieldConfig{
Type: graphql.String,
},
@ -70,6 +90,7 @@ func fromMapProjectInfo(args map[string]interface{}) (project satellite.ProjectI
project.Name, _ = args[fieldName].(string)
project.Description, _ = args[fieldDescription].(string)
project.IsTermsAccepted, _ = args[fieldIsTermsAccepted].(bool)
project.CompanyName, _ = args[fieldCompanyName].(string)
return
}

View File

@ -6,7 +6,6 @@ package satelliteql
import (
"github.com/graphql-go/graphql"
"github.com/skyrings/skyring-common/tools/uuid"
"storj.io/storj/pkg/satellite"
)

View File

@ -53,13 +53,13 @@ func (c *TypeCreator) Create(service *satellite.Service) error {
return err
}
c.project = graphqlProject()
if err := c.project.Error(); err != nil {
c.projectInput = graphqlProjectInput()
if err := c.projectInput.Error(); err != nil {
return err
}
c.projectInput = graphqlProjectInput()
if err := c.projectInput.Error(); err != nil {
c.project = graphqlProject(service)
if err := c.project.Error(); err != nil {
return err
}

View File

@ -7,7 +7,6 @@ import (
"context"
"crypto/sha256"
"crypto/subtle"
"fmt"
"time"
"github.com/skyrings/skyring-common/tools/uuid"
@ -17,7 +16,6 @@ import (
"storj.io/storj/pkg/auth"
"storj.io/storj/pkg/satellite/satelliteauth"
"storj.io/storj/pkg/utils"
)
// Service is handling accounts related logic
@ -209,21 +207,13 @@ func (s *Service) GetProject(ctx context.Context, projectID uuid.UUID) (*Project
}
// GetUsersProjects is a method for querying all projects
func (s *Service) GetUsersProjects(ctx context.Context) ([]ProjectInfo, error) {
// TODO: parse id and query only users projects, not all
_, err := GetAuth(ctx)
func (s *Service) GetUsersProjects(ctx context.Context) ([]Project, error) {
auth, err := GetAuth(ctx)
if err != nil {
return nil, err
}
// TODO: should return only users projects, not all
projects, err := s.store.Projects().GetAll(ctx)
if err != nil {
return nil, errs.New("Can not fetch projects!")
}
return s.projectsToProjectInfoSlice(ctx, projects)
return s.store.Projects().GetByUserID(ctx, auth.User.ID)
}
// CreateProject is a method for creating new project
@ -240,11 +230,23 @@ func (s *Service) CreateProject(ctx context.Context, projectInfo ProjectInfo) (*
project := &Project{
OwnerID: &auth.User.ID,
Description: projectInfo.Description,
CompanyName: projectInfo.CompanyName,
Name: projectInfo.Name,
TermsAccepted: 1, //TODO: get lat version of Term of Use
}
return s.store.Projects().Insert(ctx, project)
// For now we make this operations sequentially.
// But soon we will add functionality to be able to
// do any operations in transaction scope
prj, err := s.store.Projects().Insert(ctx, project)
if err != nil {
return nil, err
}
// Project owner is also a project member
_, err = s.store.ProjectMembers().Insert(ctx, auth.User.ID, prj.ID)
return prj, err
}
// DeleteProject is a method for deleting project by id
@ -390,51 +392,3 @@ func (s *Service) authorize(ctx context.Context, claims *satelliteauth.Claims) (
return user, nil
}
// projectToProjectInfo is used for creating ProjectInfo entity from Project struct
func (s *Service) projectToProjectInfo(ctx context.Context, project *Project) (*ProjectInfo, error) {
if project == nil {
return nil, errs.New("project parameter is nil")
}
projInfo := &ProjectInfo{
ID: project.ID,
Name: project.Name,
Description: project.Description,
// TODO: create a better check for isTermsAccepted
IsTermsAccepted: true,
CreatedAt: project.CreatedAt,
}
if project.OwnerID == nil {
return projInfo, nil
}
owner, err := s.store.Users().Get(ctx, *project.OwnerID)
if err != nil {
return projInfo, nil
}
projInfo.OwnerName = fmt.Sprintf("%s %s", owner.FirstName, owner.LastName)
return projInfo, nil
}
// projectsToProjectInfoSlice is used for creating []ProjectInfo entities from []Project struct
func (s *Service) projectsToProjectInfoSlice(ctx context.Context, projects []Project) ([]ProjectInfo, error) {
var projectsInfo []ProjectInfo
var errors []error
// Generating []dbo from []dbx and collecting all errors
for _, project := range projects {
project, err := s.projectToProjectInfo(ctx, &project)
if err != nil {
errors = append(errors, err)
continue
}
projectsInfo = append(projectsInfo, *project)
}
return projectsInfo, utils.CombineErrors(errors...)
}

View File

@ -7,6 +7,8 @@ import gql from "graphql-tag";
// Performs graqhQL request.
// Throws an exception if error occurs
export async function createProject(project: Project): Promise<any> {
console.log("in api", project);
let response = await apollo.mutate(
{
mutation: gql(`
@ -15,6 +17,7 @@ export async function createProject(project: Project): Promise<any> {
input: {
name: "${project.name}",
description: "${project.description}",
companyName: "${project.companyName}",
isTermsAccepted: ${project.isTermsAccepted},
}
)
@ -46,6 +49,7 @@ export async function fetchProjects(): Promise<any> {
description
createdAt
ownerName
companyName
isTermsAccepted
}
}`

View File

@ -22,6 +22,7 @@
:cols="40"
wrap="hard"
v-model.lazy="value"
@change="onInput"
@input="onInput">
</textarea>
<input

View File

@ -73,6 +73,7 @@ import Button from "@/components/common/Button.vue";
data: function() {
return {
name: "",
companyName: "",
description: "",
isTermsAccepted: false,
termsAcceptedError: false,
@ -84,6 +85,9 @@ import Button from "@/components/common/Button.vue";
this.$data.name = value;
this.$data.nameError = "";
},
setCompanyName: function(value: string) : void {
this.$data.companyName = value;
},
setProjectDescription: function(value: string) : void {
this.$data.description = value;
},
@ -115,7 +119,9 @@ import Button from "@/components/common/Button.vue";
let isSuccess = this.$store.dispatch("createProject", {
name: this.$data.name,
description: this.$data.description,
companyName: this.$data.companyName,
isTermsAccepted: this.$data.isTermsAccepted,
});
if (!isSuccess) {

View File

@ -12,7 +12,7 @@
</div>
<div class="project-details-info-container__name-container">
<h2>Company / Organization</h2>
<h3>Name Project</h3>
<h3>{{companyName}}</h3>
</div>
</div>
<div class="project-details-info-container">
@ -133,6 +133,9 @@ import { EMPTY_STATE_IMAGES } from '@/utils/constants/emptyStatesImages'
description: function(): string {
return this.$store.getters.selectedProject.description;
},
companyName: function(): string {
return this.$store.getters.selectedProject.companyName;
},
projectApproval: function(): string {
let date = new Date(this.$store.getters.selectedProject.createdAt);

View File

@ -13,6 +13,7 @@ export const projectsModule = {
name: "Choose Project",
id: "",
ownerName: "",
companyName: "",
description: "",
isTermsAccepted: false,
createdAt: "",
@ -68,6 +69,8 @@ export const projectsModule = {
createProject: async function({commit}: any, project: Project): Promise<boolean> {
let response = await createProject(project);
console.log("in action", project);
if(!response || response.errors) {
return false;
}

View File

@ -7,14 +7,16 @@ declare type Project = {
ownerName: string,
name: string,
description: string
description: string,
companyName: string,
isTermsAccepted: boolean,
createdAt: string
createdAt: string,
isSelected: boolean,
}
// UpdateProjectModel is a type, used for updating project description
declare type UpdateProjectModel = {
id: string,
description: string
description: string,
}