images: consolidated list api to single RPC

This commit is contained in:
Tigor Hutasuhut 2024-08-16 23:13:38 +07:00
parent c30dce73dd
commit e7a7002293
3 changed files with 2 additions and 110 deletions

View file

@ -2,17 +2,8 @@ syntax = "proto3";
package images.v1;
import "images/v1/list_by_subreddit.proto";
import "images/v1/recently_added.proto";
import "images/v1/list.proto";
service ImageService {
// RecentlyAddedImages returns a list of recently added images.
//
// The returned images are grouped by device and sorted by the time they were added.
//
// Use after and before to traverse fetch more images.
//
// Maximum number of images that can be fetched at a time is 300.
rpc RecentlyAddedImages(RecentlyAddedImagesRequest) returns (RecentlyAddedImagesResponse) {}
rpc ListBySubreddit(ListBySubredditRequest) returns (ListBySubredditResponse) {}
rpc ListImages(ListImagesRequest) returns (ListImagesResponse) {}
}

View file

@ -1,43 +0,0 @@
syntax = "proto3";
package images.v1;
import "buf/validate/validate.proto";
import "images/v1/types.proto";
message ListBySubredditRequest {
option (buf.validate.message).cel = {
id: "ListBySubredditRequest.after_cannot_exist_with_before"
message: "after and before cannot be set at the same time"
expression: "this.after > 0 && this.before > 0"
};
string subreddit = 1 [(buf.validate.field).string.min_len = 1];
// devices filter the images to be fetched belonging to the given devices.
//
// If empty, images from all devices will be fetched.
repeated string devices = 2;
// limit limits the number of images to be fetched.
//
// if 0 (or not set), the default limit is 25.
//
// if set, the maximum limit is clamped to 100.
int64 limit = 3 [(buf.validate.field).int64.gte = 0];
// after lists the image after the given timestamp.
//
// using after will return images that are created after the given timestamp.
//
// cannot be set (value > 0) with before (value > 0).
int64 after = 4;
// before lists the image before the given timestamp.
//
// using before will return images that are created before the given timestamp.
//
// cannot be set (value > 0) with after (value > 0).
int64 before = 5;
}
message ListBySubredditResponse {
repeated GroupedByDeviceImages devices = 1;
optional int64 after = 2;
optional int64 before = 3;
}

View file

@ -1,56 +0,0 @@
syntax = "proto3";
package images.v1;
import "buf/validate/validate.proto";
import "images/v1/types.proto";
message RecentlyAddedImagesRequest {
option (buf.validate.message).cel = {
id: "RecentlyAddedImagesRequest.after_cannot_exist_with_before"
message: "after and before cannot be set at the same time"
expression: "this.after > 0 && this.before > 0"
};
// subreddits filter the images to be fetched belonging to the given subreddits.
//
// If empty, images from all subreddits will be fetched.
repeated string subreddits = 1;
// devices filter the images to be fetched belonging to the given devices.
//
// If empty, images from all devices will be fetched.
repeated string devices = 2;
// limit limits the number of images to be fetched.
//
// if 0 (or not set), the default limit is 100.
//
// if set, the maximum limit is clamped to 300.
int64 limit = 3 [(buf.validate.field).int64.gte = 0];
// after lists the image after the given timestamp.
//
// using after will return images that are created after the given timestamp.
//
// cannot be set (value > 0) with before (value > 0).
int64 after = 4;
// before lists the image before the given timestamp.
//
// using before will return images that are created before the given timestamp.
//
// cannot be set (value > 0) with after (value > 0).
int64 before = 5;
}
message RecentlyAddedImagesResponse {
// groups are images grouped by devices.
//
// devices are sorted alphabetically by it's NAME not slug.
repeated GroupedBySubredditDevices groups = 1;
// after is a unix epoch timestamp given to the client to be used as after in the next request.
//
// Given if the request has after value set and there are more images to be fetched.
optional int64 after = 2;
// before is a unix epoch timestamp given to the client to be used as before in the next request.
//
// Given if the request has before value set and there are more images to be fetched.
optional int64 before = 3;
}