Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: user search #105

Merged
merged 23 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions .github/workflows/lint.proto.yml

This file was deleted.

10 changes: 9 additions & 1 deletion .github/workflows/test.proto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
- main
pull_request:
paths:
- 'protobufs/**'
- 'buf.yaml'
- 'buf.gen.yaml'
- 'package.json'
Expand All @@ -18,7 +19,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: '22'
Expand Down Expand Up @@ -48,3 +49,10 @@ jobs:
git diff
exit 1
fi

- name: Install protolint
run: go install github.com/yoheimuta/protolint/cmd/protolint@latest

- name: Run protolint
working-directory: ./protobufs
run: protolint .
6 changes: 6 additions & 0 deletions database/migrations/013_user_search_index.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE EXTENSION IF NOT EXISTS pg_trgm;

ALTER TABLE getstronger.users
ADD COLUMN full_name_search TEXT GENERATED ALWAYS AS (lower(first_name || ' ' || last_name)) STORED NOT NULL;

CREATE INDEX idx_users_full_name_search ON getstronger.users USING gin (full_name_search gin_trgm_ops);
10 changes: 10 additions & 0 deletions protobufs/api/v1/shared.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ message User {
string first_name = 2 [(buf.validate.field).string.min_len = 1];
string last_name = 3 [(buf.validate.field).string.min_len = 1];
}

message PaginationRequest {
int32 page_limit = 1 [(buf.validate.field).int32 = { gte: 1, lte: 100 }];
bytes page_token = 2;
}

message PaginationResponse {
int64 total_results = 1;
bytes next_page_token = 2;
}
22 changes: 22 additions & 0 deletions protobufs/api/v1/users.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import "api/v1/shared.proto";
import "buf/validate/validate.proto";

service UserService {
rpc Get(GetUserRequest) returns (GetUserResponse) {
option (auth) = true;
}
rpc Follow(FollowRequest) returns (FollowResponse) {
option (auth) = true;
}
Expand All @@ -20,6 +23,16 @@ service UserService {
rpc ListFollowees(ListFolloweesRequest) returns (ListFolloweesResponse) {
option (auth) = true;
}
rpc Search(SearchRequest) returns (SearchResponse) {
option (auth) = true;
}
}

message GetUserRequest {
string id = 1 [(buf.validate.field).string.uuid = true];
}
message GetUserResponse {
User user = 1;
}

message FollowRequest {
Expand All @@ -45,3 +58,12 @@ message ListFolloweesRequest {
message ListFolloweesResponse {
repeated User followees = 1;
}

message SearchRequest {
string query = 1 [(buf.validate.field).string.min_len = 3];
PaginationRequest pagination = 2 [(buf.validate.field).required = true];
}
message SearchResponse {
repeated User users = 1;
PaginationResponse pagination = 2;
}
5 changes: 3 additions & 2 deletions protobufs/api/v1/workouts.proto
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ message CreateWorkoutResponse {
}

message ListWorkoutsRequest {
int32 page_size = 1 [(buf.validate.field).int32 = { gte: 1, lte: 100 }];
bytes page_token = 2;
repeated string user_ids = 1 [(buf.validate.field).repeated = { min_items: 1, items: { string: { uuid: true }}}];
int32 page_size = 2 [(buf.validate.field).int32 = { gte: 1, lte: 100 }];
bytes page_token = 3;
}
message ListWorkoutsResponse {
repeated Workout workouts = 1;
Expand Down
82 changes: 47 additions & 35 deletions server/pkg/orm/users.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading