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

Commit

Permalink
Merge pull request #100 from swibly/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
devkcud authored Nov 2, 2024
2 parents 848ac0d + 36f1225 commit afb3aa0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
14 changes: 9 additions & 5 deletions internal/service/repository/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,13 @@ func (cr *componentRepository) Search(issuerID uint, search *dto.SearchComponent
regexp_like(u.first_name, ?, 'i') OR
regexp_like(u.last_name, ?, 'i') OR
regexp_like(u.username, ?, 'i')
)`, *search.Name, *search.Name, *search.Name, *search.Name, *search.Name)
)`,
utils.RegexPrepareName(*search.Name),
utils.RegexPrepareName(*search.Name),
utils.RegexPrepareName(*search.Name),
utils.RegexPrepareName(*search.Name),
utils.RegexPrepareName(*search.Name),
)

// TODO: Create ranking system
}
Expand All @@ -504,14 +510,12 @@ func (cr *componentRepository) Search(issuerID uint, search *dto.SearchComponent
query = query.Order("c.created_at " + orderDirection)
} else if search.OrderModifiedDate {
query = query.Order("c.updated_at " + orderDirection)
} else if search.MostHolders {
query = query.Order("(SELECT COUNT(*) FROM component_holders ch WHERE ch.component_id = c.id) " + orderDirection)
} else {
query = query.Order("c.created_at " + orderDirection)
}

if search.MostHolders {
query = query.Order("(SELECT COUNT(*) FROM component_holders ch WHERE ch.component_id = c.id) " + orderDirection)
}

return cr.paginateComponents(query, page, perPage)
}

Expand Down
12 changes: 4 additions & 8 deletions internal/service/repository/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,16 +749,12 @@ func (pr *projectRepository) Search(issuerID uint, search *dto.SearchProject, pa
query = query.Order("p.created_at " + orderDirection)
} else if search.OrderModifiedDate {
query = query.Order("p.updated_at " + orderDirection)
} else {
query = query.Order("p.created_at " + orderDirection)
}

if search.MostFavorites {
} else if search.MostFavorites {
query = query.Order("total_favorites " + orderDirection)
}

if search.MostClones {
} else if search.MostClones {
query = query.Order("total_clones " + orderDirection)
} else {
query = query.Order("p.created_at " + orderDirection)
}

return pr.paginateProjects(query, page, perPage)
Expand Down
16 changes: 10 additions & 6 deletions internal/service/repository/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/swibly/swibly-api/pkg/aws"
"github.com/swibly/swibly-api/pkg/db"
"github.com/swibly/swibly-api/pkg/pagination"
"github.com/swibly/swibly-api/pkg/utils"
"gorm.io/gorm"
)

Expand Down Expand Up @@ -88,7 +89,12 @@ func (u userRepository) Search(issuerID uint, search *dto.SearchUser, page, perp
Where("show_profile = TRUE")

if search.Name != nil {
query = query.Where("regexp_like(first_name, ?, 'i') OR regexp_like(last_name, ?, 'i') OR regexp_like(username, ?, 'i')", *search.Name, *search.Name, *search.Name)
query = query.Where(
"regexp_like(first_name, ?, 'i') OR regexp_like(last_name, ?, 'i') OR regexp_like(username, ?, 'i')",
utils.RegexPrepareName(*search.Name),
utils.RegexPrepareName(*search.Name),
utils.RegexPrepareName(*search.Name),
)

// TODO: Create ranking system
}
Expand All @@ -113,18 +119,16 @@ func (u userRepository) Search(issuerID uint, search *dto.SearchUser, page, perp
query = query.Order("created_at " + orderDirection)
} else if search.OrderModifiedDate {
query = query.Order("updated_at " + orderDirection)
} else {
query = query.Order("created_at DESC")
}

if search.MostFollowers {
} else if search.MostFollowers {
query = query.Joins(`
LEFT JOIN (
SELECT following_id, COUNT(*) AS follower_count
FROM followers
GROUP BY following_id
) follower_counts ON follower_counts.following_id = users.id`).
Order("follower_count" + orderDirection + "NULLS LAST")
} else {
query = query.Order("created_at " + orderDirection)
}

return pagination.Generate[dto.UserProfile](query, page, perpage)
Expand Down

0 comments on commit afb3aa0

Please sign in to comment.