Start to populate site information in review task
This commit is contained in:
parent
03dccb638a
commit
c4c22f6733
6 changed files with 71 additions and 2 deletions
|
|
@ -100,6 +100,21 @@ func SiteList(ctx context.Context, user User, limit int) ([]*types.Site, error)
|
|||
}
|
||||
return results, nil
|
||||
}
|
||||
func SitesByID(ctx context.Context, ids []int32) (map[int32]*models.Site, error) {
|
||||
rows, err := models.Sites.Query(
|
||||
sm.Where(
|
||||
models.Sites.Columns.ID.EQ(psql.Any(ids)),
|
||||
),
|
||||
).All(ctx, db.PGInstance.BobDB)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query sites: %w", err)
|
||||
}
|
||||
results := make(map[int32]*models.Site, len(rows))
|
||||
for _, row := range rows {
|
||||
results[row.ID] = row
|
||||
}
|
||||
return results, err
|
||||
}
|
||||
func siteFromAddress(ctx context.Context, txn bob.Tx, user User, address_id int32) (*models.Site, error) {
|
||||
site, err := models.Sites.Query(
|
||||
models.SelectWhere.Sites.AddressID.EQ(address_id),
|
||||
|
|
|
|||
19
platform/types/review_task.go
Normal file
19
platform/types/review_task.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type ReviewTask struct {
|
||||
Created time.Time `db:"created" json:"created"`
|
||||
Creator User `db:"creator" json:"creator"`
|
||||
ID int32 `db:"id" json:"id"`
|
||||
Pool *ReviewTaskPool `db:"pool" json:"pool"`
|
||||
Reviewed *time.Time `db:"reviewed" json:"reviewed"`
|
||||
Reviewer *User `db:"reviewer" json:"reviewer"`
|
||||
}
|
||||
type ReviewTaskPool struct {
|
||||
Condition string `db:"condition" json:"condition"`
|
||||
Location Location `db:"location" json:"location"`
|
||||
Site Site `db:"site" json:"site"`
|
||||
}
|
||||
|
|
@ -2,6 +2,8 @@ package types
|
|||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
)
|
||||
|
||||
type Site struct {
|
||||
|
|
@ -19,3 +21,15 @@ type Site struct {
|
|||
Tags map[string]string `db:"tags" json:"tags"`
|
||||
Version int32 `db:"version" json:"version"`
|
||||
}
|
||||
|
||||
func SiteFromModel(s *models.Site) Site {
|
||||
return Site{
|
||||
Created: s.Created,
|
||||
CreatorID: s.CreatorID,
|
||||
//FileID: s.FileID,
|
||||
ID: s.ID,
|
||||
Notes: s.Notes,
|
||||
OrganizationID: s.OrganizationID,
|
||||
//ParcelID: s.ParcelID,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
6
platform/types/user.go
Normal file
6
platform/types/user.go
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
package types
|
||||
|
||||
type User struct {
|
||||
ID int32 `db:"id" json:"id"`
|
||||
Name string `db:"-" json:"name"`
|
||||
}
|
||||
|
|
@ -39,7 +39,6 @@ type reviewTask struct {
|
|||
type reviewTaskPool struct {
|
||||
Condition string `json:"condition"`
|
||||
Location types.Location `json:"location"`
|
||||
Owner types.Contact `json:"owner"`
|
||||
Site types.Site `json:"site"`
|
||||
}
|
||||
type contentListReviewTask struct {
|
||||
|
|
@ -77,7 +76,7 @@ func (res *reviewTaskR) List(ctx context.Context, r *http.Request, user platform
|
|||
Longitude float64 `db:"longitude"`
|
||||
Reviewed *time.Time `db:"reviewed"`
|
||||
ReviewerID *int32 `db:"reviewer_id"`
|
||||
Species *string `db:"species"`
|
||||
SiteID int32 `db:"site_id"`
|
||||
Title string `db:"title"`
|
||||
Type string `db:"type"`
|
||||
}
|
||||
|
|
@ -98,6 +97,7 @@ func (res *reviewTaskR) List(ctx context.Context, r *http.Request, user platform
|
|||
"address.unit AS \"address.unit\"",
|
||||
"ST_Y(address.location) AS latitude",
|
||||
"ST_X(address.location) AS longitude",
|
||||
"site.id AS site_id",
|
||||
),
|
||||
sm.From("review_task_pool"),
|
||||
sm.InnerJoin("feature_pool").OnEQ(
|
||||
|
|
@ -130,8 +130,20 @@ func (res *reviewTaskR) List(ctx context.Context, r *http.Request, user platform
|
|||
if err != nil {
|
||||
return nil, nhttp.NewError("users by id: %w", err)
|
||||
}
|
||||
site_ids := make([]int32, len(rows))
|
||||
for i, row := range rows {
|
||||
site_ids[i] = row.SiteID
|
||||
}
|
||||
sites_by_id, err := platform.SitesByID(ctx, site_ids)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("sites by id: %w", err)
|
||||
}
|
||||
tasks := make([]reviewTask, len(rows))
|
||||
for i, row := range rows {
|
||||
site, ok := sites_by_id[row.SiteID]
|
||||
if !ok {
|
||||
return nil, nhttp.NewError("no site %d", row.SiteID)
|
||||
}
|
||||
tasks[i] = reviewTask{
|
||||
Address: row.Address,
|
||||
Created: row.Created,
|
||||
|
|
@ -143,6 +155,7 @@ func (res *reviewTaskR) List(ctx context.Context, r *http.Request, user platform
|
|||
Latitude: row.Latitude,
|
||||
Longitude: row.Longitude,
|
||||
},
|
||||
Site: types.SiteFromModel(site),
|
||||
},
|
||||
Reviewed: row.Reviewed,
|
||||
Reviewer: userOrNil(users_by_id, row.ReviewerID),
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ type sessionURLAPI struct {
|
|||
ReviewTask string `json:"review_task"`
|
||||
ServiceRequest string `json:"service_request"`
|
||||
Signal string `json:"signal"`
|
||||
Site string `json:"site"`
|
||||
Sync string `json:"sync"`
|
||||
Upload string `json:"upload"`
|
||||
User string `json:"user"`
|
||||
|
|
@ -99,6 +100,7 @@ func (res *sessionR) Get(ctx context.Context, r *http.Request, user platform.Use
|
|||
ReviewTask: config.MakeURLNidus("/api/review-task"),
|
||||
ServiceRequest: config.MakeURLNidus("/api/service-request"),
|
||||
Signal: config.MakeURLNidus("/api/signal"),
|
||||
Site: config.MakeURLNidus("/api/site"),
|
||||
Sync: config.MakeURLNidus("/api/sync"),
|
||||
Upload: config.MakeURLNidus("/api/upload"),
|
||||
User: config.MakeURLNidus("/api/user"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue