Refactor Notification Management and Enhance Customer Features
- Updated the notification handling logic to utilize a new SDK for sending notifications, improving the flexibility and scalability of the notification system. - Introduced new methods in the notification service for sending notifications to users and customers based on various target audience types, enhancing the notification delivery capabilities. - Added a new endpoint to assign companies to a customer, improving customer management functionalities. - Refactored the customer entity and forms to replace 'CompanyIDs' with 'Companies', ensuring consistency across the data model. - Enhanced API documentation with Swagger comments for the new endpoint and updated notification structures, ensuring clarity for API consumers.
This commit is contained in:
+15
-14
@@ -85,20 +85,21 @@ type UpdateUserRoleForm struct {
|
||||
|
||||
// Response DTOs
|
||||
type UserResponse struct {
|
||||
ID string `json:"id"`
|
||||
FullName string `json:"full_name"`
|
||||
Username string `json:"username"`
|
||||
Email string `json:"email"`
|
||||
Role string `json:"role"`
|
||||
Status string `json:"status"`
|
||||
Department *string `json:"department"`
|
||||
Position *string `json:"position"`
|
||||
Phone *string `json:"phone"`
|
||||
ProfileImage *string `json:"profile_image"`
|
||||
IsVerified bool `json:"is_verified"`
|
||||
LastLoginAt *int64 `json:"last_login_at"`
|
||||
UpdatedAt int64 `json:"updated_at"`
|
||||
CreatedAt int64 `json:"created_at"`
|
||||
ID string `json:"id"`
|
||||
FullName string `json:"full_name"`
|
||||
Username string `json:"username"`
|
||||
Email string `json:"email"`
|
||||
Role string `json:"role"`
|
||||
Status string `json:"status"`
|
||||
Department *string `json:"department"`
|
||||
Position *string `json:"position"`
|
||||
Phone *string `json:"phone"`
|
||||
ProfileImage *string `json:"profile_image"`
|
||||
IsVerified bool `json:"is_verified"`
|
||||
LastLoginAt *int64 `json:"last_login_at"`
|
||||
UpdatedAt int64 `json:"updated_at"`
|
||||
CreatedAt int64 `json:"created_at"`
|
||||
DeviceToken []string `json:"-"`
|
||||
}
|
||||
|
||||
type AuthResponse struct {
|
||||
|
||||
@@ -20,6 +20,7 @@ type Repository interface {
|
||||
GetByID(ctx context.Context, id string) (*User, error)
|
||||
GetByEmail(ctx context.Context, email string) (*User, error)
|
||||
GetByUsername(ctx context.Context, username string) (*User, error)
|
||||
GetByIDs(ctx context.Context, userIDs []string) ([]User, error)
|
||||
Search(ctx context.Context, form *SearchUsersForm, pagination *response.Pagination) ([]User, int64, error)
|
||||
}
|
||||
|
||||
@@ -215,6 +216,16 @@ func (r *userRepository) Delete(ctx context.Context, id string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetByIDs retrieves users by IDs
|
||||
func (r *userRepository) GetByIDs(ctx context.Context, userIDs []string) ([]User, error) {
|
||||
users, err := r.ormRepo.FindAll(ctx, bson.M{"_id": bson.M{"$in": userIDs}}, orm.NewPaginationBuilder().Limit(len(userIDs)).Build())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return users.Items, nil
|
||||
}
|
||||
|
||||
// List retrieves users with pagination
|
||||
func (r *userRepository) Search(ctx context.Context, form *SearchUsersForm, pagination *response.Pagination) ([]User, int64, error) {
|
||||
filter := bson.M{}
|
||||
|
||||
@@ -23,6 +23,7 @@ type Service interface {
|
||||
Update(ctx context.Context, id string, form *UpdateUserForm) (*UserResponse, error)
|
||||
UpdateStatus(ctx context.Context, id string, form *UpdateUserStatusForm) error
|
||||
GetUserByID(ctx context.Context, userID string) (*UserResponse, error)
|
||||
GetUsersByIDs(ctx context.Context, userIDs []string) (*UserListResponse, error)
|
||||
Search(ctx context.Context, form *SearchUsersForm, pagination *response.Pagination) (*UserListResponse, error)
|
||||
Delete(ctx context.Context, id string) error
|
||||
|
||||
@@ -250,6 +251,23 @@ func (s *userService) GetUserByID(ctx context.Context, id string) (*UserResponse
|
||||
return user.ToResponse(), nil
|
||||
}
|
||||
|
||||
// GetUsersByIDs retrieves users by IDs
|
||||
func (s *userService) GetUsersByIDs(ctx context.Context, userIDs []string) (*UserListResponse, error) {
|
||||
users, err := s.repository.GetByIDs(ctx, userIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var userResponses []*UserResponse
|
||||
for _, user := range users {
|
||||
userResponses = append(userResponses, user.ToResponse())
|
||||
}
|
||||
|
||||
return &UserListResponse{
|
||||
Users: userResponses,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Search searches users with search and filters
|
||||
func (s *userService) Search(ctx context.Context, form *SearchUsersForm, pagination *response.Pagination) (*UserListResponse, error) {
|
||||
// Get users
|
||||
|
||||
Reference in New Issue
Block a user