Skip to content

Commit

Permalink
fix: search
Browse files Browse the repository at this point in the history
  • Loading branch information
vovangy committed Apr 9, 2024
1 parent faf0105 commit cca4ee0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions internal/pkg/adverts/repo/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"database/sql"
"fmt"
"log"

"github.com/satori/uuid"
)
Expand Down Expand Up @@ -918,15 +919,16 @@ func (r *AdvertRepo) GetRectangleAdverts(ctx context.Context, advertFilter model
}

if advertFilter.RoomCount != 0 {
queryBaseAdvert += "SELECT * FROM (" + queryBaseAdvert + ") AS subqueryforroomcountcalculate WHERE rcount = $" + fmt.Sprint(i) + " "
queryBaseAdvert = "SELECT * FROM (" + queryBaseAdvert + ") AS subqueryforroomcountcalculate WHERE rcount = $" + fmt.Sprint(i) + " "
argsForQuery = append(argsForQuery, advertFilter.RoomCount)
i++
}

queryCount := "SELECT COUNT(*) FROM (" + queryBaseAdvert + ") AS subqueryforpaginate;"
queryCount := "SELECT COUNT(*) FROM (" + queryBaseAdvert + ") AS subqueryforpaginate"
queryBaseAdvert += " ORDER BY datecreation DESC LIMIT $" + fmt.Sprint(i) + " OFFSET $" + fmt.Sprint(i+1) + ";"
rowCountQuery := r.db.QueryRowContext(ctx, queryCount, append([]interface{}{advertFilter.MinPrice, advertFilter.MaxPrice, advertFilter.Address}, argsForQuery...)...)

log.Println(queryCount)
if err := rowCountQuery.Scan(&pageInfo.TotalElements); err != nil {
return nil, err
}
Expand Down

0 comments on commit cca4ee0

Please sign in to comment.