Add Contact Management Functionality
- Introduced a new contact management feature, including the ability to create, retrieve, search, update, and delete contact messages. - Implemented the Contact entity, repository, service, and handler layers following Clean Architecture principles. - Added API endpoints for contact operations in Swagger documentation, ensuring comprehensive API specifications. - Enhanced error handling and validation for contact data, improving robustness and user experience. - Updated the main application to initialize the contact repository and service, integrating them into the existing system.
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
package contact
|
||||
|
||||
import (
|
||||
"tm/pkg/mongo"
|
||||
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// ContactStatus represents the status of a contact message
|
||||
type ContactStatus string
|
||||
|
||||
const (
|
||||
ContactStatusPending ContactStatus = "pending"
|
||||
ContactStatusInProgress ContactStatus = "in_progress"
|
||||
ContactStatusResolved ContactStatus = "resolved"
|
||||
ContactStatusClosed ContactStatus = "closed"
|
||||
)
|
||||
|
||||
// Contact represents a contact us message in the system
|
||||
type Contact struct {
|
||||
mongo.Model `bson:",inline"`
|
||||
FullName string `bson:"full_name" json:"full_name" validate:"required"`
|
||||
Email string `bson:"email" json:"email" validate:"required,email"`
|
||||
Phone string `bson:"phone" json:"phone" validate:"required"`
|
||||
Message string `bson:"message" json:"message" validate:"required"`
|
||||
Status ContactStatus `bson:"status" json:"status" validate:"required,oneof=pending in_progress resolved closed"`
|
||||
AdminNotes *string `bson:"admin_notes,omitempty" json:"admin_notes,omitempty"`
|
||||
ResolvedAt *int64 `bson:"resolved_at,omitempty" json:"resolved_at,omitempty"`
|
||||
ResolvedBy *string `bson:"resolved_by,omitempty" json:"resolved_by,omitempty"`
|
||||
}
|
||||
|
||||
// SetID sets the contact ID (implements IDSetter interface)
|
||||
func (c *Contact) SetID(id string) {
|
||||
c.ID, _ = bson.ObjectIDFromHex(id)
|
||||
}
|
||||
|
||||
// GetID returns the contact ID (implements IDGetter interface)
|
||||
func (c *Contact) GetID() string {
|
||||
return c.ID.Hex()
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the created timestamp (implements Timestamp interface)
|
||||
func (c *Contact) SetCreatedAt(timestamp int64) {
|
||||
c.CreatedAt = timestamp
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the updated timestamp (implements Timestamp interface)
|
||||
func (c *Contact) SetUpdatedAt(timestamp int64) {
|
||||
c.UpdatedAt = timestamp
|
||||
}
|
||||
|
||||
// GetCreatedAt returns the created timestamp (implements Timestamp interface)
|
||||
func (c *Contact) GetCreatedAt() int64 {
|
||||
return c.CreatedAt
|
||||
}
|
||||
|
||||
// GetUpdatedAt returns the updated timestamp (implements Timestamp interface)
|
||||
func (c *Contact) GetUpdatedAt() int64 {
|
||||
return c.UpdatedAt
|
||||
}
|
||||
|
||||
// IsPending returns true if the contact is pending
|
||||
func (c *Contact) IsPending() bool {
|
||||
return c.Status == ContactStatusPending
|
||||
}
|
||||
|
||||
// IsResolved returns true if the contact is resolved
|
||||
func (c *Contact) IsResolved() bool {
|
||||
return c.Status == ContactStatusResolved || c.Status == ContactStatusClosed
|
||||
}
|
||||
|
||||
// CanBeUpdated returns true if the contact can be updated
|
||||
func (c *Contact) CanBeUpdated() bool {
|
||||
return c.Status != ContactStatusClosed
|
||||
}
|
||||
Reference in New Issue
Block a user