From f98e5dc063c7fc16a903208f95d23c74528e2f5b Mon Sep 17 00:00:00 2001 From: Tigor Hutasuhut Date: Fri, 16 Aug 2024 14:38:44 +0700 Subject: [PATCH] images: added list image proto --- go/.air.toml | 6 +- schemas/proto/images/v1/images.proto | 62 +++---------------- .../proto/images/v1/list_by_subreddit.proto | 16 +++++ schemas/proto/images/v1/recently_added.proto | 56 +++++++++++++++++ schemas/proto/images/v1/types.proto | 11 ++++ 5 files changed, 94 insertions(+), 57 deletions(-) create mode 100644 schemas/proto/images/v1/list_by_subreddit.proto create mode 100644 schemas/proto/images/v1/recently_added.proto diff --git a/go/.air.toml b/go/.air.toml index 3e1f90e..be1ffe3 100644 --- a/go/.air.toml +++ b/go/.air.toml @@ -1,4 +1,4 @@ -root = "." +root = ".." testdata_dir = "testdata" tmp_dir = "tmp" @@ -7,14 +7,14 @@ args_bin = ["serve"] bin = "./tmp/main" cmd = "go build -o ./tmp/main ./cmd/bluemage" delay = 1000 -exclude_dir = ["assets", "tmp", "vendor", "testdata", "gen"] +exclude_dir = ["assets", "tmp", "vendor", "testdata", "go/gen"] exclude_file = [] exclude_regex = ["_test.go"] exclude_unchanged = false follow_symlink = false full_bin = "" include_dir = [] -include_ext = ["go", "tpl", "tmpl", "html"] +include_ext = ["go", "tpl", "tmpl", "html", "proto"] include_file = [] kill_delay = "5s" log = "build-errors.log" diff --git a/schemas/proto/images/v1/images.proto b/schemas/proto/images/v1/images.proto index 2d0d78f..afeb4b3 100644 --- a/schemas/proto/images/v1/images.proto +++ b/schemas/proto/images/v1/images.proto @@ -2,61 +2,15 @@ syntax = "proto3"; package images.v1; -import "buf/validate/validate.proto"; -import "images/v1/types.proto"; +import "images/v1/recently_added.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) {} } - -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 1000. - int64 limit = 3; - // 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 { - repeated GroupedByDeviceImages groups = 1; - // after is given to the client to be used as after in the next request. - // - // Given if the request has after value set. - optional int64 after = 2; - - // before is given to the client to be used as before in the next request. - // - // Given if the request has before value set. - optional int64 before = 3; -} - -message GroupedByDeviceImages { - string device = 1; - repeated Image images = 2; -} diff --git a/schemas/proto/images/v1/list_by_subreddit.proto b/schemas/proto/images/v1/list_by_subreddit.proto new file mode 100644 index 0000000..62dc71e --- /dev/null +++ b/schemas/proto/images/v1/list_by_subreddit.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; + +package images.v1; + +import "buf/validate/validate.proto"; +import "images/v1/types.proto"; + +message ListBySubredditRequest { + string subreddit = 1 [(buf.validate.field).string.min_len = 1]; +} + +message ListBySubredditResponse { + repeated GroupedByDeviceImages devices = 1; + optional int64 after = 2; + optional int64 before = 3; +} diff --git a/schemas/proto/images/v1/recently_added.proto b/schemas/proto/images/v1/recently_added.proto new file mode 100644 index 0000000..c804e60 --- /dev/null +++ b/schemas/proto/images/v1/recently_added.proto @@ -0,0 +1,56 @@ +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; +} diff --git a/schemas/proto/images/v1/types.proto b/schemas/proto/images/v1/types.proto index ff05efd..dff9684 100644 --- a/schemas/proto/images/v1/types.proto +++ b/schemas/proto/images/v1/types.proto @@ -17,3 +17,14 @@ message Image { uint32 image_width = 12; int64 image_size = 13; } + +message GroupedByDeviceImages { + string slug = 1; + string name = 2; + repeated Image images = 3; +} + +message GroupedBySubredditDevices { + string subreddit = 1; + repeated GroupedByDeviceImages devices = 2; +}