Add user count column to residences admin page
- Add user_count field to ResidenceResponse DTO - Update residence handler to preload Users and calculate count - Count includes owner (1) plus all shared users - Add Users column to admin residences list 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -57,6 +57,10 @@ const columns: ColumnDef<Residence>[] = [
|
||||
accessorKey: 'owner_name',
|
||||
header: 'Owner',
|
||||
},
|
||||
{
|
||||
accessorKey: 'user_count',
|
||||
header: 'Users',
|
||||
},
|
||||
{
|
||||
accessorKey: 'city',
|
||||
header: 'Location',
|
||||
|
||||
@@ -109,6 +109,7 @@ export interface Residence {
|
||||
purchase_price?: number;
|
||||
is_primary: boolean;
|
||||
is_active: boolean;
|
||||
user_count: number;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
@@ -98,6 +98,7 @@ type ResidenceResponse struct {
|
||||
PurchasePrice *float64 `json:"purchase_price,omitempty"`
|
||||
IsPrimary bool `json:"is_primary"`
|
||||
IsActive bool `json:"is_active"`
|
||||
UserCount int `json:"user_count"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
}
|
||||
|
||||
@@ -36,7 +36,8 @@ func (h *AdminResidenceHandler) List(c *gin.Context) {
|
||||
|
||||
query := h.db.Model(&models.Residence{}).
|
||||
Preload("Owner").
|
||||
Preload("PropertyType")
|
||||
Preload("PropertyType").
|
||||
Preload("Users")
|
||||
|
||||
// Apply search
|
||||
if filters.Search != "" {
|
||||
@@ -331,6 +332,9 @@ func (h *AdminResidenceHandler) BulkDelete(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *AdminResidenceHandler) toResidenceResponse(res *models.Residence) dto.ResidenceResponse {
|
||||
// User count = owner (1) + shared users
|
||||
userCount := 1 + len(res.Users)
|
||||
|
||||
response := dto.ResidenceResponse{
|
||||
ID: res.ID,
|
||||
Name: res.Name,
|
||||
@@ -345,6 +349,7 @@ func (h *AdminResidenceHandler) toResidenceResponse(res *models.Residence) dto.R
|
||||
Description: res.Description,
|
||||
IsPrimary: res.IsPrimary,
|
||||
IsActive: res.IsActive,
|
||||
UserCount: userCount,
|
||||
CreatedAt: res.CreatedAt.Format("2006-01-02T15:04:05Z"),
|
||||
UpdatedAt: res.UpdatedAt.Format("2006-01-02T15:04:05Z"),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user