generated from VLADIMIR/template
fix double applications
This commit is contained in:
@@ -24,11 +24,11 @@ func NewRepository(filepath string) (*Repository, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, err = db.Exec("CREATE TABLE IF NOT EXISTS actions (id INTEGER PRIMARY KEY AUTOINCREMENT, place TEXT, teamId INTEGER);")
|
||||
_, err = db.Exec("CREATE TABLE IF NOT EXISTS actions (id INTEGER PRIMARY KEY AUTOINCREMENT, place TEXT, teamId INTEGER, FOREIGN KEY (teamId) REFERENCES teams(id) ON DELETE CASCADE);")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, err = db.Exec("CREATE TABLE IF NOT EXISTS applications (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, teamId INTEGER, state TEXT);")
|
||||
_, err = db.Exec("CREATE TABLE IF NOT EXISTS applications (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, teamId INTEGER, state TEXT, FOREIGN KEY (teamId) REFERENCES teams(id) ON DELETE CASCADE);")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -127,19 +127,36 @@ func (r *Repository) GetTeam(ctx context.Context, teamId any, password any) (*mo
|
||||
return teams[0], nil
|
||||
}
|
||||
|
||||
func (r *Repository) AddApplications(ctx context.Context, actions []*models.Action) error {
|
||||
for _, action := range actions {
|
||||
for _, application := range action.Applications {
|
||||
_, err := r.db.Exec("insert into applications (name, teamId, state) values ($1, $2, $3)", application.Name, action.TeamID, application.State)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
func (r *Repository) AddApplications(ctx context.Context, teamId int64, applications []*models.Application) error {
|
||||
for _, application := range applications {
|
||||
_, err := r.db.Exec("insert into applications (name, teamId, state) values ($1, $2, $3)", application.Name, teamId, application.State)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Repository) GetApplications(ctx context.Context, teamId int64, state string) ([]*models.Application, error) {
|
||||
func (r *Repository) GetApplications(ctx context.Context, teamId int64) ([]*models.Application, error) {
|
||||
rows, err := r.db.Query("select id, name from applications where teamId = $1", teamId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
applications := []*models.Application{}
|
||||
|
||||
for rows.Next() {
|
||||
item := &models.Application{}
|
||||
err := rows.Scan(&item.ID, &item.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
applications = append(applications, item)
|
||||
}
|
||||
return applications, nil
|
||||
}
|
||||
|
||||
func (r *Repository) GetApplicationsByState(ctx context.Context, teamId int64, state string) ([]*models.Application, error) {
|
||||
rows, err := r.db.Query("select id, name from applications where teamId = $1 and state = $2", teamId, state)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user