Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
feat: Add unread notifications field for user profile
Browse files Browse the repository at this point in the history
  • Loading branch information
devkcud committed Nov 5, 2024
1 parent f91be80 commit c0ca4c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion internal/model/dto/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ type UserProfile struct {
Country string `json:"country"`
Language string `json:"language"`

Permissions []string `gorm:"-" json:"permissions"`
Permissions []string `gorm:"-" json:"permissions"`
UnreadNotifications int64 `gorm:"-" json:"unread_notifications"`

ProfilePicture string `json:"pfp"`
}
Expand Down
13 changes: 10 additions & 3 deletions internal/service/repository/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import (
type userRepository struct {
db *gorm.DB

followRepo FollowRepository
permissionRepo PermissionRepository
followRepo FollowRepository
permissionRepo PermissionRepository
notificationRepo NotificationRepository
}

type UserRepository interface {
Expand All @@ -31,7 +32,7 @@ type UserRepository interface {
}

func NewUserRepository() UserRepository {
return &userRepository{db: db.Postgres, followRepo: NewFollowRepository(), permissionRepo: NewPermissionRepository()}
return &userRepository{db: db.Postgres, followRepo: NewFollowRepository(), permissionRepo: NewPermissionRepository(), notificationRepo: NewNotificationRepository()}
}

func (u userRepository) Create(createModel *model.User) error {
Expand Down Expand Up @@ -81,6 +82,12 @@ func (u userRepository) Get(searchModel *model.User) (*dto.UserProfile, error) {
}
}

if count, err := u.notificationRepo.GetUnreadCount(user.ID); err != nil {
return nil, err
} else {
user.UnreadNotifications = count
}

return user, nil
}

Expand Down

0 comments on commit c0ca4c3

Please sign in to comment.