Add quick'n'dirty interface for leads and features
This commit is contained in:
parent
1f8e6b698f
commit
617631063f
5 changed files with 68 additions and 0 deletions
|
|
@ -6,6 +6,8 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/enums"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
|
|
@ -13,6 +15,7 @@ import (
|
|||
"github.com/aarondl/opt/omit"
|
||||
"github.com/aarondl/opt/omitnull"
|
||||
//"github.com/rs/zerolog/log"
|
||||
"github.com/stephenafamo/scan"
|
||||
)
|
||||
|
||||
// Create a lead from the given signal and site
|
||||
|
|
@ -45,3 +48,31 @@ func leadCreate(ctx context.Context, txn bob.Executor, user User, signal_id int3
|
|||
}
|
||||
return &lead.ID, nil
|
||||
}
|
||||
func leadsBySiteID(ctx context.Context, site_ids []int32) (map[int32][]types.Lead, error) {
|
||||
rows, err := bob.All(ctx, db.PGInstance.BobDB, psql.Select(
|
||||
sm.Columns(
|
||||
"id",
|
||||
"site_id",
|
||||
),
|
||||
sm.From("lead"),
|
||||
sm.Where(
|
||||
models.Leads.Columns.SiteID.EQ(psql.Any(site_ids)),
|
||||
),
|
||||
), scan.StructMapper[types.Lead]())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query leads: %w", err)
|
||||
}
|
||||
results := make(map[int32][]types.Lead, len(site_ids))
|
||||
for _, site_id := range site_ids {
|
||||
results[site_id] = make([]types.Lead, 0)
|
||||
}
|
||||
for _, row := range rows {
|
||||
leads, ok := results[row.SiteID]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("impossible")
|
||||
}
|
||||
leads = append(leads, row)
|
||||
results[row.SiteID] = leads
|
||||
}
|
||||
return results, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,6 +117,18 @@ func SiteList(ctx context.Context, user User, limit int) ([]*types.Site, error)
|
|||
}
|
||||
result.Features = features
|
||||
}
|
||||
leads_by_site_id, err := leadsBySiteID(ctx, site_ids)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query leads for sites: %w", err)
|
||||
}
|
||||
for _, result := range results {
|
||||
leads, ok := leads_by_site_id[result.ID]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("impossible")
|
||||
}
|
||||
result.Leads = leads
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
func SitesByID(ctx context.Context, ids []int32) (map[int32]*models.Site, error) {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ type Site struct {
|
|||
Features []Feature `db:"-" json:"features"`
|
||||
FileID int32 `db:"file_id" json:"file_id"`
|
||||
ID int32 `db:"id" json:"id"`
|
||||
Leads []Lead `db:"-" json:"leads"`
|
||||
Notes string `db:"notes" json:"notes"`
|
||||
OrganizationID int32 `db:"organization_id" json:"organization_id"`
|
||||
Owner Contact `db:"owner" json:"owner"`
|
||||
|
|
|
|||
|
|
@ -35,6 +35,19 @@
|
|||
<td><b>Parcel Description</b></td>
|
||||
<td>{{ selectedSite?.parcel?.description }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
Features<br />
|
||||
<ul>
|
||||
<li v-for="(feature, index) in selectedSite?.features">
|
||||
{{ feature.type }}
|
||||
</li>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Leads: {{ selectedSite?.leads.length ?? "none" }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -528,12 +528,23 @@ export interface Parcel {
|
|||
description: string;
|
||||
id: number;
|
||||
}
|
||||
export interface Feature {
|
||||
id: number;
|
||||
location: Location;
|
||||
type: string;
|
||||
}
|
||||
export interface Lead {
|
||||
id: number;
|
||||
site_id: number;
|
||||
}
|
||||
export interface Site {
|
||||
address: Address;
|
||||
created: string;
|
||||
creator_id: number;
|
||||
features: Feature[];
|
||||
file_id: number;
|
||||
id: number;
|
||||
leads: Lead[];
|
||||
notes: string;
|
||||
organization_id: number;
|
||||
owner?: Contact;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue