Make contractor residence optional with visibility rules
- Make residence_id nullable in contractor model - Add created_by_id field to track contractor creator - Update access control: personal contractors visible only to creator, residence contractors visible to all residence users - Add database migration for schema changes - Update admin panel DTOs and handlers for optional residence - Fix test utilities for new model structure 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,7 @@ package requests
|
||||
|
||||
// CreateContractorRequest represents the request to create a contractor
|
||||
type CreateContractorRequest struct {
|
||||
ResidenceID uint `json:"residence_id" binding:"required"`
|
||||
ResidenceID *uint `json:"residence_id"`
|
||||
Name string `json:"name" binding:"required,min=1,max=200"`
|
||||
Company string `json:"company" binding:"max=200"`
|
||||
Phone string `json:"phone" binding:"max=20"`
|
||||
|
||||
@@ -26,7 +26,7 @@ type ContractorUserResponse struct {
|
||||
// ContractorResponse represents a contractor in the API response
|
||||
type ContractorResponse struct {
|
||||
ID uint `json:"id"`
|
||||
ResidenceID uint `json:"residence_id"`
|
||||
ResidenceID *uint `json:"residence_id"`
|
||||
CreatedByID uint `json:"created_by_id"`
|
||||
AddedBy uint `json:"added_by"` // Alias for created_by_id (KMM compatibility)
|
||||
CreatedBy *ContractorUserResponse `json:"created_by,omitempty"`
|
||||
@@ -87,7 +87,7 @@ func NewContractorUserResponse(u *models.User) *ContractorUserResponse {
|
||||
func NewContractorResponse(c *models.Contractor) ContractorResponse {
|
||||
resp := ContractorResponse{
|
||||
ID: c.ID,
|
||||
ResidenceID: c.ResidenceID,
|
||||
ResidenceID: c.ResidenceID, // Already a pointer
|
||||
CreatedByID: c.CreatedByID,
|
||||
AddedBy: c.CreatedByID, // Alias for KMM compatibility
|
||||
Name: c.Name,
|
||||
|
||||
Reference in New Issue
Block a user