diff --git a/src/insight/insight-connect.go b/src/insight/insight-connect.go index b531711..43bebff 100644 --- a/src/insight/insight-connect.go +++ b/src/insight/insight-connect.go @@ -87,8 +87,8 @@ type ( BillableHoursFormattedString string BillableTimeString string BillableTotal float64 - Date string - Description string + TimeEntryDate string `json:"Date,omitempty"` + TimeEntryDescription string `json:"Description,omitempty"` ProjectId string `json:"Project_Id,omitempty"` RateBill float64 RateBurden float64 @@ -127,7 +127,7 @@ func (ic *Interconnect) UpdateUsers() { } func (ic *Interconnect) UpdateTimeEntries() { - users := ic.DBConnector.FetchUsers() + users := ic.DBConnector.FetchEngineerUsers() for _, userPtr := range *users { user := *userPtr entries := ic.Client.GetTimeAllTimeEntriesForUserThroughDate(user.Id, "2022-04-28") diff --git a/src/insight/insight-database.go b/src/insight/insight-database.go index 2b365ab..5eb3145 100644 --- a/src/insight/insight-database.go +++ b/src/insight/insight-database.go @@ -26,7 +26,7 @@ func NewDBConnection() *DBConnector { } func (c *DBConnector) CreateTables() { - tableCreationScripts := []string{"create-user-table.sql", "create-timeentry-table.sql"} + tableCreationScripts := []string{"create-insight-user-table.sql", "create-timeentry-table.sql"} for _, scriptName := range tableCreationScripts { c.ExecuteSqlScript(InsightDatabaseName, scriptName) @@ -51,8 +51,8 @@ func (c *DBConnector) UpdateTimeEntries(entries *[]*TimeEntry) { ent.BillableHoursFormattedString, ent.BillableTimeString, ent.BillableTotal, - ent.Date, - ent.Description, + ent.TimeEntryDate, + ent.TimeEntryDescription, ent.ProjectId, ent.RateBill, ent.RateBurden, @@ -103,6 +103,25 @@ func (c *DBConnector) FetchUsers() *[]*User { return &ret } +func (c *DBConnector) FetchEngineerUsers() *[]*User { + ret := make([]*User, 0, 50) + cx := c.checkoutConnection(InsightDatabaseName) + queryText := "SELECT insight.users.Id, insight.users.FirstName, insight.users.LastName, insight.users.EmailAddress FROM insight.users INNER JOIN projects.users on insight.users.EmailAddress = projects.users.email where projects.users.priv & POW(2, 25) > 0;" + rs, err := cx.Query(queryText) + if err != nil { + log.Fatalln(err) + } + for rs.Next() { + u := User{} + err := rs.Scan(&u.Id, &u.FirstName, &u.LastName, &u.EmailAddress) + if err != nil { + log.Fatalln(err) + } + ret = append(ret, &u) + } + return &ret +} + func (c *DBConnector) ExecuteSqlScript(database string, scriptName string) { db := c.checkoutConnection(database) defer c.returnConnection(db) diff --git a/src/sql/create-user-table.sql b/src/sql/create-insight-user-table.sql similarity index 100% rename from src/sql/create-user-table.sql rename to src/sql/create-insight-user-table.sql diff --git a/src/sql/create-timeentry-table.sql b/src/sql/create-timeentry-table.sql index f56b84a..f370cd0 100644 --- a/src/sql/create-timeentry-table.sql +++ b/src/sql/create-timeentry-table.sql @@ -10,8 +10,8 @@ CREATE TABLE insight.timeentry BillableHoursFormattedString VARCHAR(30), BillableTimeString VARCHAR(30), BillableTotal REAL, - Date VARCHAR(30), - Description VARCHAR(4096), + TimeEntryDate VARCHAR(30), + TimeEntryDescription VARCHAR(4096), ProjectId VARCHAR(50), RateBill REAL, RateBurden REAL, diff --git a/src/sql/update-timeentry.sql b/src/sql/update-timeentry.sql index 2ac7d2f..19c01c7 100644 --- a/src/sql/update-timeentry.sql +++ b/src/sql/update-timeentry.sql @@ -6,8 +6,8 @@ INSERT INTO insight.timeentry (ActualHours, BillableHoursFormattedString, BillableTimeString, BillableTotal, - Date, - Description, + TimeEntryDate, + TimeEntryDescription, ProjectId, RateBill, RateBurden,