diff --git a/api/comments/v1/comments.proto b/api/comments/v1/comments.proto new file mode 100644 index 0000000..5d47c3d --- /dev/null +++ b/api/comments/v1/comments.proto @@ -0,0 +1,102 @@ +syntax = "proto3"; + +import "google/protobuf/empty.proto"; +import "validate/validate.proto"; +import "google/api/annotations.proto"; +import "protoc-gen-openapiv2/options/annotations.proto"; + +option go_package = "route256/pkg/api/comments/v1;comments"; + +option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { + info: { + title: "Comments Service"; + version: "1.0.0"; + }; + schemes: HTTP; + schemes: HTTPS; + consumes: "application/json"; + produces: "application/json"; +}; + + +message Comment { + int64 id = 1 [(validate.rules).int64 = {gt: 0}]; + int64 user_id = 2 [(validate.rules).int64 = {gt: 0}]; + int64 sku = 3 [(validate.rules).int64 = {gt: 0}]; + string text = 4 [(validate.rules).string = {min_len:1, max_len:255}]; + string created_at = 5; // RFC3339 with ms +} + +message CreateCommentRequest { + int64 user_id = 1 [(validate.rules).int64 = {gt: 0}]; + int64 sku = 2 [(validate.rules).int64 = {gt: 0}]; + string text = 3 [(validate.rules).string = {min_len:1, max_len:255}]; +} +message CreateCommentResponse { Comment comment = 1; } + +message GetCommentRequest { + int64 id = 1 [(validate.rules).int64 = {gt:0}]; +} +message GetCommentResponse { Comment comment = 1; } + +message UpdateCommentRequest { + int64 id = 1 [(validate.rules).int64 = {gt:0}]; + int64 user_id = 2 [(validate.rules).int64 = {gt: 0}]; + string text = 3 [(validate.rules).string = {min_len:1, max_len:255}]; +} +message UpdateCommentResponse { Comment comment = 1; } + +message ListBySkuRequest { + int64 sku = 1 [(validate.rules).int64 = {gt:0}]; +} +message ListBySkuResponse { repeated Comment comments = 1; } + +message ListByUserRequest { + int64 user_id = 1 [(validate.rules).int64 = {gt:0}]; +} +message ListByUserResponse { repeated Comment comments = 1; } + +service Comments { + option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_tag) = { + description: "Comment Service" + external_docs: { + url: "https://github.com/grpc-ecosystem/grpc-gateway/blob/main/examples/internal/proto/examplepb/a_bit_of_everything.proto"; + description: "Find out more about grpc-gateway"; + } + }; + + rpc Add(CreateCommentRequest) returns (CreateCommentResponse) { + option (google.api.http) = { + post: "/comment/add" + body: "*" + }; + } + + rpc GetById(GetCommentRequest) returns (GetCommentResponse) { + option (google.api.http) = { + post: "/comment/get-by-id" + body: "*" + }; + } + + rpc Edit(UpdateCommentRequest) returns (UpdateCommentResponse) { + option (google.api.http) = { + post: "/comment/edit" + body: "*" + }; + } + + rpc ListBySku(ListBySkuRequest) returns (ListBySkuResponse) { + option (google.api.http) = { + post: "/comment/list-by-sku" + body: "*" + }; + } + + rpc ListByUser(ListByUserRequest) returns (ListByUserResponse) { + option (google.api.http) = { + post: "/comment/list-by-user" + body: "*" + }; + } +} \ No newline at end of file diff --git a/api/openapiv2/comments/v1/comments.swagger.json b/api/openapiv2/comments/v1/comments.swagger.json new file mode 100644 index 0000000..6db66c9 --- /dev/null +++ b/api/openapiv2/comments/v1/comments.swagger.json @@ -0,0 +1,350 @@ +{ + "swagger": "2.0", + "info": { + "title": "Comments Service", + "version": "1.0.0" + }, + "tags": [ + { + "name": "Comments", + "description": "Comment Service", + "externalDocs": { + "description": "Find out more about grpc-gateway", + "url": "https://github.com/grpc-ecosystem/grpc-gateway/blob/main/examples/internal/proto/examplepb/a_bit_of_everything.proto" + } + } + ], + "schemes": [ + "http", + "https" + ], + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "paths": { + "/comment/add": { + "post": { + "operationId": "Comments_Add", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/CreateCommentResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/CreateCommentRequest" + } + } + ], + "tags": [ + "Comments" + ] + } + }, + "/comment/edit": { + "post": { + "operationId": "Comments_Edit", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/UpdateCommentResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/UpdateCommentRequest" + } + } + ], + "tags": [ + "Comments" + ] + } + }, + "/comment/get-by-id": { + "post": { + "operationId": "Comments_GetById", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/GetCommentResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/GetCommentRequest" + } + } + ], + "tags": [ + "Comments" + ] + } + }, + "/comment/list-by-sku": { + "post": { + "operationId": "Comments_ListBySku", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/ListBySkuResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/ListBySkuRequest" + } + } + ], + "tags": [ + "Comments" + ] + } + }, + "/comment/list-by-user": { + "post": { + "operationId": "Comments_ListByUser", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/ListByUserResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/rpcStatus" + } + } + }, + "parameters": [ + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/ListByUserRequest" + } + } + ], + "tags": [ + "Comments" + ] + } + } + }, + "definitions": { + "Comment": { + "type": "object", + "properties": { + "id": { + "type": "string", + "format": "int64" + }, + "userId": { + "type": "string", + "format": "int64" + }, + "sku": { + "type": "string", + "format": "int64" + }, + "text": { + "type": "string" + }, + "createdAt": { + "type": "string", + "title": "RFC3339 with ms" + } + } + }, + "CreateCommentRequest": { + "type": "object", + "properties": { + "userId": { + "type": "string", + "format": "int64" + }, + "sku": { + "type": "string", + "format": "int64" + }, + "text": { + "type": "string" + } + } + }, + "CreateCommentResponse": { + "type": "object", + "properties": { + "comment": { + "$ref": "#/definitions/Comment" + } + } + }, + "GetCommentRequest": { + "type": "object", + "properties": { + "id": { + "type": "string", + "format": "int64" + } + } + }, + "GetCommentResponse": { + "type": "object", + "properties": { + "comment": { + "$ref": "#/definitions/Comment" + } + } + }, + "ListBySkuRequest": { + "type": "object", + "properties": { + "sku": { + "type": "string", + "format": "int64" + } + } + }, + "ListBySkuResponse": { + "type": "object", + "properties": { + "comments": { + "type": "array", + "items": { + "type": "object", + "$ref": "#/definitions/Comment" + } + } + } + }, + "ListByUserRequest": { + "type": "object", + "properties": { + "userId": { + "type": "string", + "format": "int64" + } + } + }, + "ListByUserResponse": { + "type": "object", + "properties": { + "comments": { + "type": "array", + "items": { + "type": "object", + "$ref": "#/definitions/Comment" + } + } + } + }, + "UpdateCommentRequest": { + "type": "object", + "properties": { + "id": { + "type": "string", + "format": "int64" + }, + "userId": { + "type": "string", + "format": "int64" + }, + "text": { + "type": "string" + } + } + }, + "UpdateCommentResponse": { + "type": "object", + "properties": { + "comment": { + "$ref": "#/definitions/Comment" + } + } + }, + "protobufAny": { + "type": "object", + "properties": { + "@type": { + "type": "string" + } + }, + "additionalProperties": {} + }, + "rpcStatus": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + }, + "details": { + "type": "array", + "items": { + "type": "object", + "$ref": "#/definitions/protobufAny" + } + } + } + } + } +} diff --git a/comments/Makefile b/comments/Makefile index 0d2ff98..f661621 100644 --- a/comments/Makefile +++ b/comments/Makefile @@ -1,12 +1,41 @@ -BINDIR=${CURDIR}/bin +BINDIR=${CURDIR}/../bin PACKAGE=route256/comments +MIGRATIONS_FOLDER := ./db/migrations/ +LOCAL_DB_NAME := route256 +LOCAL_DB_DSN := postgresql://user:password@localhost:5433/route256?sslmode=disable + +PROD_USER := loms-user +PROD_PASS := loms-password +PROD_DB := postgres-master + +PROD_MIGRATIONS := ./comments/db/migrations/ + +build: bindir + echo "build comments" + go build -o ${BINDIR}/comments cmd/server/main.go + bindir: mkdir -p ${BINDIR} -build: bindir - echo "build comments" - - +# Used for CI run-migrations: - echo "run migrations" + $(GOOSE) -dir $(PROD_MIGRATIONS) postgres "postgresql://$(PROD_USER):$(PROD_PASS)@$(PROD_DB):5432/comments_db?sslmode=disable" up + +db-create-migration: + $(BINDIR)/goose -dir $(MIGRATIONS_FOLDER) create -s $(n) sql + +db-migrate: + $(BINDIR)/goose -dir $(MIGRATIONS_FOLDER) postgres "$(LOCAL_DB_DSN)" up + +db-migrate-down: + $(BINDIR)/goose -dir $(MIGRATIONS_FOLDER) postgres "$(LOCAL_DB_DSN)" down + +db-reset-local: + psql -c "drop database if exists \"$(LOCAL_DB_NAME)\"" + psql -c "create database \"$(LOCAL_DB_NAME)\"" + make db-migrate + +.PHONY: generate-sqlc +generate-sqlc: + $(BINDIR)/sqlc generate diff --git a/comments/db/migrations/00001_create_comments.sql b/comments/db/migrations/00001_create_comments.sql new file mode 100644 index 0000000..ba74046 --- /dev/null +++ b/comments/db/migrations/00001_create_comments.sql @@ -0,0 +1,10 @@ +CREATE TABLE comments ( + id BIGSERIAL PRIMARY KEY, + user_id BIGINT NOT NULL, + sku BIGINT NOT NULL, + text VARCHAR(255) NOT NULL, + created_at TIMESTAMP(3) NOT NULL DEFAULT now() +); + +CREATE INDEX ON comments(sku, created_at DESC, user_id ASC); +CREATE INDEX ON comments(user_id, created_at DESC); diff --git a/comments/go.mod b/comments/go.mod index 2e5d8d7..36d7edb 100644 --- a/comments/go.mod +++ b/comments/go.mod @@ -1,3 +1,16 @@ module route256/comments go 1.23.1 + +require github.com/go-playground/validator/v10 v10.27.0 + +require ( + github.com/gabriel-vasile/mimetype v1.4.8 // indirect + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect + github.com/leodido/go-urn v1.4.0 // indirect + golang.org/x/crypto v0.33.0 // indirect + golang.org/x/net v0.34.0 // indirect + golang.org/x/sys v0.30.0 // indirect + golang.org/x/text v0.22.0 // indirect +) diff --git a/comments/go.sum b/comments/go.sum new file mode 100644 index 0000000..21426e3 --- /dev/null +++ b/comments/go.sum @@ -0,0 +1,28 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM= +github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8= +github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.27.0 h1:w8+XrWVMhGkxOaaowyKH35gFydVHOvC0/uWoy2Fzwn4= +github.com/go-playground/validator/v10 v10.27.0/go.mod h1:I5QpIEbmr8On7W0TktmJAumgzX4CA1XNl4ZmDuVHKKo= +github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= +github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus= +golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M= +golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0= +golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k= +golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= +golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= +golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/comments/infra/db/postgres/tx.go b/comments/infra/db/postgres/tx.go new file mode 100644 index 0000000..5244abd --- /dev/null +++ b/comments/infra/db/postgres/tx.go @@ -0,0 +1,87 @@ +package postgres + +// From https://gitlab.ozon.dev/go/classroom-18/students/week-4-workshop/-/blob/master/internal/infra/postgres/tx.go + +import ( + "context" + + "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgxpool" + "github.com/opentracing/opentracing-go" +) + +// Tx транзакция. +type Tx pgx.Tx + +type txKey struct{} + +func ctxWithTx(ctx context.Context, tx pgx.Tx) context.Context { + return context.WithValue(ctx, txKey{}, tx) +} + +func TxFromCtx(ctx context.Context) (pgx.Tx, bool) { + tx, ok := ctx.Value(txKey{}).(pgx.Tx) + + return tx, ok +} + +type TxManager struct { + write *pgxpool.Pool + read *pgxpool.Pool +} + +func NewTxManager(write, read *pgxpool.Pool) *TxManager { + return &TxManager{ + write: write, + read: read, + } +} + +// WithTransaction выполняет fn в транзакции с дефолтным уровнем изоляции. +func (m *TxManager) WriteWithTransaction(ctx context.Context, fn func(ctx context.Context) error) (err error) { + return m.withTx(ctx, m.write, pgx.TxOptions{}, fn) +} + +func (m *TxManager) ReadWithTransaction(ctx context.Context, fn func(ctx context.Context) error) (err error) { + return m.withTx(ctx, m.read, pgx.TxOptions{}, fn) +} + +// WithTransaction выполняет fn в транзакции с уровнем изоляции RepeatableRead. +func (m *TxManager) WriteWithRepeatableRead(ctx context.Context, fn func(ctx context.Context) error) (err error) { + return m.withTx(ctx, m.write, pgx.TxOptions{IsoLevel: pgx.RepeatableRead}, fn) +} + +func (m *TxManager) ReadWithRepeatableRead(ctx context.Context, fn func(ctx context.Context) error) (err error) { + return m.withTx(ctx, m.read, pgx.TxOptions{IsoLevel: pgx.RepeatableRead}, fn) +} + +// WithTx выполняет fn в транзакции. +func (m *TxManager) withTx(ctx context.Context, pool *pgxpool.Pool, options pgx.TxOptions, fn func(ctx context.Context) error) (err error) { + var span opentracing.Span + span, ctx = opentracing.StartSpanFromContext(ctx, "Transaction") + defer span.Finish() + + tx, err := pool.BeginTx(ctx, options) + if err != nil { + return + } + ctx = ctxWithTx(ctx, tx) + + defer func() { + if p := recover(); p != nil { + // a panic occurred, rollback and repanic + _ = tx.Rollback(ctx) + panic(p) + } else if err != nil { + // something went wrong, rollback + _ = tx.Rollback(ctx) + } else { + // all good, commit + err = tx.Commit(ctx) + } + }() + + err = fn(ctx) + + return +} diff --git a/comments/infra/repository/sqlc/db.go b/comments/infra/repository/sqlc/db.go new file mode 100644 index 0000000..2725108 --- /dev/null +++ b/comments/infra/repository/sqlc/db.go @@ -0,0 +1,32 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.29.0 + +package sqlc + +import ( + "context" + + "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgconn" +) + +type DBTX interface { + Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error) + Query(context.Context, string, ...interface{}) (pgx.Rows, error) + QueryRow(context.Context, string, ...interface{}) pgx.Row +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} + +func (q *Queries) WithTx(tx pgx.Tx) *Queries { + return &Queries{ + db: tx, + } +} diff --git a/comments/infra/repository/sqlc/models.go b/comments/infra/repository/sqlc/models.go new file mode 100644 index 0000000..d0bd2d3 --- /dev/null +++ b/comments/infra/repository/sqlc/models.go @@ -0,0 +1,17 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.29.0 + +package sqlc + +import ( + "github.com/jackc/pgx/v5/pgtype" +) + +type Comment struct { + ID int64 + UserID int64 + Sku int64 + Text string + CreatedAt pgtype.Timestamp +} diff --git a/comments/infra/repository/sqlc/querier.go b/comments/infra/repository/sqlc/querier.go new file mode 100644 index 0000000..d281693 --- /dev/null +++ b/comments/infra/repository/sqlc/querier.go @@ -0,0 +1,19 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.29.0 + +package sqlc + +import ( + "context" +) + +type Querier interface { + GetCommentByID(ctx context.Context, id int64) (*Comment, error) + InsertComment(ctx context.Context, arg *InsertCommentParams) (*Comment, error) + ListCommentsBySku(ctx context.Context, sku int64) ([]*Comment, error) + ListCommentsByUser(ctx context.Context, userID int64) ([]*Comment, error) + UpdateComment(ctx context.Context, arg *UpdateCommentParams) (*Comment, error) +} + +var _ Querier = (*Queries)(nil) diff --git a/comments/infra/repository/sqlc/query.sql b/comments/infra/repository/sqlc/query.sql new file mode 100644 index 0000000..e1fd8f1 --- /dev/null +++ b/comments/infra/repository/sqlc/query.sql @@ -0,0 +1,24 @@ +-- name: InsertComment :one +INSERT INTO comments (user_id, sku, text) VALUES ($1, $2, $3) +RETURNING id, user_id, sku, text, created_at; + +-- name: GetCommentByID :one +SELECT id, user_id, sku, text, created_at FROM comments WHERE id = $1; + +-- name: UpdateComment :one +UPDATE comments +SET text = $2 +WHERE id = $1 +RETURNING id, user_id, sku, text, created_at; + +-- name: ListCommentsBySku :many +SELECT id, user_id, sku, text, created_at +FROM comments +WHERE sku = $1 +ORDER BY created_at DESC, user_id ASC; + +-- name: ListCommentsByUser :many +SELECT id, user_id, sku, text, created_at +FROM comments +WHERE user_id = $1 +ORDER BY created_at DESC; diff --git a/comments/infra/repository/sqlc/query.sql.go b/comments/infra/repository/sqlc/query.sql.go new file mode 100644 index 0000000..601f3c9 --- /dev/null +++ b/comments/infra/repository/sqlc/query.sql.go @@ -0,0 +1,142 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.29.0 +// source: query.sql + +package sqlc + +import ( + "context" +) + +const getCommentByID = `-- name: GetCommentByID :one +SELECT id, user_id, sku, text, created_at FROM comments WHERE id = $1 +` + +func (q *Queries) GetCommentByID(ctx context.Context, id int64) (*Comment, error) { + row := q.db.QueryRow(ctx, getCommentByID, id) + var i Comment + err := row.Scan( + &i.ID, + &i.UserID, + &i.Sku, + &i.Text, + &i.CreatedAt, + ) + return &i, err +} + +const insertComment = `-- name: InsertComment :one +INSERT INTO comments (user_id, sku, text) VALUES ($1, $2, $3) +RETURNING id, user_id, sku, text, created_at +` + +type InsertCommentParams struct { + UserID int64 + Sku int64 + Text string +} + +func (q *Queries) InsertComment(ctx context.Context, arg *InsertCommentParams) (*Comment, error) { + row := q.db.QueryRow(ctx, insertComment, arg.UserID, arg.Sku, arg.Text) + var i Comment + err := row.Scan( + &i.ID, + &i.UserID, + &i.Sku, + &i.Text, + &i.CreatedAt, + ) + return &i, err +} + +const listCommentsBySku = `-- name: ListCommentsBySku :many +SELECT id, user_id, sku, text, created_at +FROM comments +WHERE sku = $1 +ORDER BY created_at DESC, user_id ASC +` + +func (q *Queries) ListCommentsBySku(ctx context.Context, sku int64) ([]*Comment, error) { + rows, err := q.db.Query(ctx, listCommentsBySku, sku) + if err != nil { + return nil, err + } + defer rows.Close() + var items []*Comment + for rows.Next() { + var i Comment + if err := rows.Scan( + &i.ID, + &i.UserID, + &i.Sku, + &i.Text, + &i.CreatedAt, + ); err != nil { + return nil, err + } + items = append(items, &i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const listCommentsByUser = `-- name: ListCommentsByUser :many +SELECT id, user_id, sku, text, created_at +FROM comments +WHERE user_id = $1 +ORDER BY created_at DESC +` + +func (q *Queries) ListCommentsByUser(ctx context.Context, userID int64) ([]*Comment, error) { + rows, err := q.db.Query(ctx, listCommentsByUser, userID) + if err != nil { + return nil, err + } + defer rows.Close() + var items []*Comment + for rows.Next() { + var i Comment + if err := rows.Scan( + &i.ID, + &i.UserID, + &i.Sku, + &i.Text, + &i.CreatedAt, + ); err != nil { + return nil, err + } + items = append(items, &i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const updateComment = `-- name: UpdateComment :one +UPDATE comments +SET text = $2 +WHERE id = $1 +RETURNING id, user_id, sku, text, created_at +` + +type UpdateCommentParams struct { + ID int64 + Text string +} + +func (q *Queries) UpdateComment(ctx context.Context, arg *UpdateCommentParams) (*Comment, error) { + row := q.db.QueryRow(ctx, updateComment, arg.ID, arg.Text) + var i Comment + err := row.Scan( + &i.ID, + &i.UserID, + &i.Sku, + &i.Text, + &i.CreatedAt, + ) + return &i, err +} diff --git a/comments/infra/repository/sqlc/repository.go b/comments/infra/repository/sqlc/repository.go new file mode 100644 index 0000000..e6fb2d7 --- /dev/null +++ b/comments/infra/repository/sqlc/repository.go @@ -0,0 +1,148 @@ +package sqlc + +import ( + "context" + "errors" + "sort" + + "route256/comments/internal/domain/entity" + "route256/comments/internal/domain/model" + + "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgxpool" + "github.com/rs/zerolog/log" +) + +type commentsRepo struct { + shard1 *pgxpool.Pool + shard2 *pgxpool.Pool +} + +func NewCommentsRepository(shard1, shard2 *pgxpool.Pool) *commentsRepo { + return &commentsRepo{ + shard1: shard1, + shard2: shard2, + } +} + +func (r *commentsRepo) pickShard(sku int64) *pgxpool.Pool { + if sku%2 == 0 { + return r.shard1 + } + + return r.shard2 +} + +func (r *commentsRepo) GetCommentByID(ctx context.Context, id int64) (*Comment, error) { + q1 := New(r.shard1) + c, err := q1.GetCommentByID(ctx, id) + switch { + case err == nil: + return c, nil + case errors.Is(err, pgx.ErrNoRows): + log.Trace().Msgf("comment with id %d not found in shard 1", id) + default: + return nil, err + } + + q2 := New(r.shard2) + c2, err2 := q2.GetCommentByID(ctx, id) + switch { + case err2 == nil: + return c2, nil + case errors.Is(err2, pgx.ErrNoRows): + return nil, model.ErrCommentNotFound + default: + return nil, err2 + } +} + +func (r *commentsRepo) InsertComment(ctx context.Context, comment *entity.Comment) (*Comment, error) { + shard := r.pickShard(comment.SKU) + q := New(shard) + + req := &InsertCommentParams{ + UserID: comment.UserID, + Sku: comment.SKU, + Text: comment.Text, + } + + c, err := q.InsertComment(ctx, req) + if err != nil { + return nil, err + } + + return c, nil +} + +func (r *commentsRepo) ListCommentsBySku(ctx context.Context, sku int64) ([]*Comment, error) { + shard := r.pickShard(sku) + q := New(shard) + + list, err := q.ListCommentsBySku(ctx, sku) + if err != nil { + return nil, err + } + + out := make([]*Comment, len(list)) + copy(out, list) + + return out, nil +} + +func (r *commentsRepo) ListCommentsByUser(ctx context.Context, userID int64) ([]*Comment, error) { + q1 := New(r.shard1) + l1, err1 := q1.ListCommentsByUser(ctx, userID) + if err1 != nil { + return nil, err1 + } + + q2 := New(r.shard2) + l2, err2 := q2.ListCommentsByUser(ctx, userID) + if err2 != nil { + return nil, err2 + } + + merged := make([]*Comment, 0, len(l1)+len(l2)) + merged = append(merged, l1...) + merged = append(merged, l2...) + + sort.Slice(merged, func(i, j int) bool { + if merged[i].CreatedAt.Time.Equal(merged[j].CreatedAt.Time) { + return merged[i].UserID < merged[j].UserID + } + + return merged[i].CreatedAt.Time.After(merged[j].CreatedAt.Time) + }) + + return merged, nil +} + +func (r *commentsRepo) UpdateComment(ctx context.Context, comment *entity.Comment) (*Comment, error) { + req := &UpdateCommentParams{ + ID: comment.ID, + Text: comment.Text, + } + + q1 := New(r.shard1) + c, err := q1.UpdateComment(ctx, req) + switch { + case err == nil: + return c, nil + case errors.Is(err, pgx.ErrNoRows): + log.Trace().Msgf("comment with id %d not found in shard 1", req.ID) + default: + return nil, err + } + + q2 := New(r.shard2) + c2, err2 := q2.UpdateComment(ctx, req) + switch { + case err2 == nil: + return c2, nil + case errors.Is(err2, pgx.ErrNoRows): + return nil, model.ErrCommentNotFound + default: + return nil, err2 + } +} diff --git a/comments/internal/domain/entity/comment.go b/comments/internal/domain/entity/comment.go new file mode 100644 index 0000000..3928785 --- /dev/null +++ b/comments/internal/domain/entity/comment.go @@ -0,0 +1,9 @@ +package entity + +type Comment struct { + ID int64 + UserID int64 + SKU int64 + CreatedAt string + Text string +} diff --git a/comments/internal/domain/model/comment.go b/comments/internal/domain/model/comment.go new file mode 100644 index 0000000..f3d9fb6 --- /dev/null +++ b/comments/internal/domain/model/comment.go @@ -0,0 +1,22 @@ +package model + +import ( + "fmt" + "time" +) + +type Comment struct { + ID int64 `validate:"gt=0"` + UserID int64 `validate:"gt=0"` + SKU int64 `validate:"gt=0"` + CreatedAt time.Time + Text string `validate:"lte=255,gt=0"` +} + +func (c *Comment) Validate() error { + if err := validate.Struct(c); err != nil { + return fmt.Errorf("invalid requested values: %w", err) + } + + return nil +} diff --git a/comments/internal/domain/model/errors.go b/comments/internal/domain/model/errors.go new file mode 100644 index 0000000..682bb65 --- /dev/null +++ b/comments/internal/domain/model/errors.go @@ -0,0 +1,5 @@ +package model + +import "errors" + +var ErrCommentNotFound = errors.New("comment not found") diff --git a/comments/internal/domain/model/validate.go b/comments/internal/domain/model/validate.go new file mode 100644 index 0000000..993e32c --- /dev/null +++ b/comments/internal/domain/model/validate.go @@ -0,0 +1,9 @@ +package model + +import "github.com/go-playground/validator/v10" + +var validate *validator.Validate + +func init() { + validate = validator.New() +} diff --git a/comments/internal/domain/service/service.go b/comments/internal/domain/service/service.go new file mode 100644 index 0000000..deb6ee1 --- /dev/null +++ b/comments/internal/domain/service/service.go @@ -0,0 +1,3 @@ +package service + +// TODO diff --git a/comments/sqlc.yaml b/comments/sqlc.yaml new file mode 100644 index 0000000..32c4298 --- /dev/null +++ b/comments/sqlc.yaml @@ -0,0 +1,15 @@ +version: "2" +sql: + - engine: "postgresql" + queries: "infra/repository/sqlc/query.sql" + schema: "db/migrations" + gen: + go: + package: "sqlc" + out: "infra/repository/sqlc" + sql_package: "pgx/v5" + emit_interface: true + emit_pointers_for_null_types: true + emit_result_struct_pointers: true + emit_params_struct_pointers: true + omit_unused_structs: true diff --git a/docker-compose.yaml b/docker-compose.yaml index 7bace30..dc1113a 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -75,6 +75,28 @@ services: ports: - "5434:5432" + postgres-comments-shard-1: + image: gitlab-registry.ozon.dev/go/classroom-18/students/base/postgres:16 + environment: + POSTGRES_DB: comments_db + POSTGRES_USER: comments-user-1 + POSTGRES_PASSWORD: comments-password-1 + ports: + - "5432:5432" + volumes: + - shard1-data:/var/lib/postgresql/data + + postgres-comments-shard-2: + image: gitlab-registry.ozon.dev/go/classroom-18/students/base/postgres:16 + environment: + POSTGRES_DB: comments_db + POSTGRES_USER: comments-user-2 + POSTGRES_PASSWORD: comments-password-2 + ports: + - "5432:5432" + volumes: + - shard2-data:/var/lib/postgresql/data + kafka-ui: container_name: kafka-ui image: provectuslabs/kafka-ui:latest diff --git a/make/generate.mk b/make/generate.mk index 06fe317..a83cf3c 100644 --- a/make/generate.mk +++ b/make/generate.mk @@ -97,3 +97,6 @@ notifier-generate: comments-generate: $(call generate,comments) + mkdir -p "api/openapiv2" + $(foreach f,$(shell find api/comments/v1 -type f -name '*.proto'),$(call proto_gen,$(f),comments)) + cd comments && go mod tidy diff --git a/pkg/api/comments/v1/comments.pb.go b/pkg/api/comments/v1/comments.pb.go new file mode 100644 index 0000000..fbf8dc8 --- /dev/null +++ b/pkg/api/comments/v1/comments.pb.go @@ -0,0 +1,927 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.1 +// protoc v6.30.0 +// source: comments/v1/comments.proto + +package comments + +import ( + _ "github.com/envoyproxy/protoc-gen-validate/validate" + _ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/options" + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + _ "google.golang.org/protobuf/types/known/emptypb" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type Comment struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + UserId int64 `protobuf:"varint,2,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` + Sku int64 `protobuf:"varint,3,opt,name=sku,proto3" json:"sku,omitempty"` + Text string `protobuf:"bytes,4,opt,name=text,proto3" json:"text,omitempty"` + CreatedAt string `protobuf:"bytes,5,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"` // RFC3339 with ms +} + +func (x *Comment) Reset() { + *x = Comment{} + if protoimpl.UnsafeEnabled { + mi := &file_comments_v1_comments_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Comment) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Comment) ProtoMessage() {} + +func (x *Comment) ProtoReflect() protoreflect.Message { + mi := &file_comments_v1_comments_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Comment.ProtoReflect.Descriptor instead. +func (*Comment) Descriptor() ([]byte, []int) { + return file_comments_v1_comments_proto_rawDescGZIP(), []int{0} +} + +func (x *Comment) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *Comment) GetUserId() int64 { + if x != nil { + return x.UserId + } + return 0 +} + +func (x *Comment) GetSku() int64 { + if x != nil { + return x.Sku + } + return 0 +} + +func (x *Comment) GetText() string { + if x != nil { + return x.Text + } + return "" +} + +func (x *Comment) GetCreatedAt() string { + if x != nil { + return x.CreatedAt + } + return "" +} + +type CreateCommentRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + UserId int64 `protobuf:"varint,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` + Sku int64 `protobuf:"varint,2,opt,name=sku,proto3" json:"sku,omitempty"` + Text string `protobuf:"bytes,3,opt,name=text,proto3" json:"text,omitempty"` +} + +func (x *CreateCommentRequest) Reset() { + *x = CreateCommentRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_comments_v1_comments_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CreateCommentRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateCommentRequest) ProtoMessage() {} + +func (x *CreateCommentRequest) ProtoReflect() protoreflect.Message { + mi := &file_comments_v1_comments_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CreateCommentRequest.ProtoReflect.Descriptor instead. +func (*CreateCommentRequest) Descriptor() ([]byte, []int) { + return file_comments_v1_comments_proto_rawDescGZIP(), []int{1} +} + +func (x *CreateCommentRequest) GetUserId() int64 { + if x != nil { + return x.UserId + } + return 0 +} + +func (x *CreateCommentRequest) GetSku() int64 { + if x != nil { + return x.Sku + } + return 0 +} + +func (x *CreateCommentRequest) GetText() string { + if x != nil { + return x.Text + } + return "" +} + +type CreateCommentResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Comment *Comment `protobuf:"bytes,1,opt,name=comment,proto3" json:"comment,omitempty"` +} + +func (x *CreateCommentResponse) Reset() { + *x = CreateCommentResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_comments_v1_comments_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CreateCommentResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateCommentResponse) ProtoMessage() {} + +func (x *CreateCommentResponse) ProtoReflect() protoreflect.Message { + mi := &file_comments_v1_comments_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CreateCommentResponse.ProtoReflect.Descriptor instead. +func (*CreateCommentResponse) Descriptor() ([]byte, []int) { + return file_comments_v1_comments_proto_rawDescGZIP(), []int{2} +} + +func (x *CreateCommentResponse) GetComment() *Comment { + if x != nil { + return x.Comment + } + return nil +} + +type GetCommentRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (x *GetCommentRequest) Reset() { + *x = GetCommentRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_comments_v1_comments_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetCommentRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetCommentRequest) ProtoMessage() {} + +func (x *GetCommentRequest) ProtoReflect() protoreflect.Message { + mi := &file_comments_v1_comments_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetCommentRequest.ProtoReflect.Descriptor instead. +func (*GetCommentRequest) Descriptor() ([]byte, []int) { + return file_comments_v1_comments_proto_rawDescGZIP(), []int{3} +} + +func (x *GetCommentRequest) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +type GetCommentResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Comment *Comment `protobuf:"bytes,1,opt,name=comment,proto3" json:"comment,omitempty"` +} + +func (x *GetCommentResponse) Reset() { + *x = GetCommentResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_comments_v1_comments_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetCommentResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetCommentResponse) ProtoMessage() {} + +func (x *GetCommentResponse) ProtoReflect() protoreflect.Message { + mi := &file_comments_v1_comments_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetCommentResponse.ProtoReflect.Descriptor instead. +func (*GetCommentResponse) Descriptor() ([]byte, []int) { + return file_comments_v1_comments_proto_rawDescGZIP(), []int{4} +} + +func (x *GetCommentResponse) GetComment() *Comment { + if x != nil { + return x.Comment + } + return nil +} + +type UpdateCommentRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + UserId int64 `protobuf:"varint,2,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` + Text string `protobuf:"bytes,3,opt,name=text,proto3" json:"text,omitempty"` +} + +func (x *UpdateCommentRequest) Reset() { + *x = UpdateCommentRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_comments_v1_comments_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateCommentRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateCommentRequest) ProtoMessage() {} + +func (x *UpdateCommentRequest) ProtoReflect() protoreflect.Message { + mi := &file_comments_v1_comments_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateCommentRequest.ProtoReflect.Descriptor instead. +func (*UpdateCommentRequest) Descriptor() ([]byte, []int) { + return file_comments_v1_comments_proto_rawDescGZIP(), []int{5} +} + +func (x *UpdateCommentRequest) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *UpdateCommentRequest) GetUserId() int64 { + if x != nil { + return x.UserId + } + return 0 +} + +func (x *UpdateCommentRequest) GetText() string { + if x != nil { + return x.Text + } + return "" +} + +type UpdateCommentResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Comment *Comment `protobuf:"bytes,1,opt,name=comment,proto3" json:"comment,omitempty"` +} + +func (x *UpdateCommentResponse) Reset() { + *x = UpdateCommentResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_comments_v1_comments_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateCommentResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateCommentResponse) ProtoMessage() {} + +func (x *UpdateCommentResponse) ProtoReflect() protoreflect.Message { + mi := &file_comments_v1_comments_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateCommentResponse.ProtoReflect.Descriptor instead. +func (*UpdateCommentResponse) Descriptor() ([]byte, []int) { + return file_comments_v1_comments_proto_rawDescGZIP(), []int{6} +} + +func (x *UpdateCommentResponse) GetComment() *Comment { + if x != nil { + return x.Comment + } + return nil +} + +type ListBySkuRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Sku int64 `protobuf:"varint,1,opt,name=sku,proto3" json:"sku,omitempty"` +} + +func (x *ListBySkuRequest) Reset() { + *x = ListBySkuRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_comments_v1_comments_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ListBySkuRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ListBySkuRequest) ProtoMessage() {} + +func (x *ListBySkuRequest) ProtoReflect() protoreflect.Message { + mi := &file_comments_v1_comments_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ListBySkuRequest.ProtoReflect.Descriptor instead. +func (*ListBySkuRequest) Descriptor() ([]byte, []int) { + return file_comments_v1_comments_proto_rawDescGZIP(), []int{7} +} + +func (x *ListBySkuRequest) GetSku() int64 { + if x != nil { + return x.Sku + } + return 0 +} + +type ListBySkuResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Comments []*Comment `protobuf:"bytes,1,rep,name=comments,proto3" json:"comments,omitempty"` +} + +func (x *ListBySkuResponse) Reset() { + *x = ListBySkuResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_comments_v1_comments_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ListBySkuResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ListBySkuResponse) ProtoMessage() {} + +func (x *ListBySkuResponse) ProtoReflect() protoreflect.Message { + mi := &file_comments_v1_comments_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ListBySkuResponse.ProtoReflect.Descriptor instead. +func (*ListBySkuResponse) Descriptor() ([]byte, []int) { + return file_comments_v1_comments_proto_rawDescGZIP(), []int{8} +} + +func (x *ListBySkuResponse) GetComments() []*Comment { + if x != nil { + return x.Comments + } + return nil +} + +type ListByUserRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + UserId int64 `protobuf:"varint,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` +} + +func (x *ListByUserRequest) Reset() { + *x = ListByUserRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_comments_v1_comments_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ListByUserRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ListByUserRequest) ProtoMessage() {} + +func (x *ListByUserRequest) ProtoReflect() protoreflect.Message { + mi := &file_comments_v1_comments_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ListByUserRequest.ProtoReflect.Descriptor instead. +func (*ListByUserRequest) Descriptor() ([]byte, []int) { + return file_comments_v1_comments_proto_rawDescGZIP(), []int{9} +} + +func (x *ListByUserRequest) GetUserId() int64 { + if x != nil { + return x.UserId + } + return 0 +} + +type ListByUserResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Comments []*Comment `protobuf:"bytes,1,rep,name=comments,proto3" json:"comments,omitempty"` +} + +func (x *ListByUserResponse) Reset() { + *x = ListByUserResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_comments_v1_comments_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ListByUserResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ListByUserResponse) ProtoMessage() {} + +func (x *ListByUserResponse) ProtoReflect() protoreflect.Message { + mi := &file_comments_v1_comments_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ListByUserResponse.ProtoReflect.Descriptor instead. +func (*ListByUserResponse) Descriptor() ([]byte, []int) { + return file_comments_v1_comments_proto_rawDescGZIP(), []int{10} +} + +func (x *ListByUserResponse) GetComments() []*Comment { + if x != nil { + return x.Comments + } + return nil +} + +var File_comments_v1_comments_proto protoreflect.FileDescriptor + +var file_comments_v1_comments_proto_rawDesc = []byte{ + 0x0a, 0x1a, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x76, 0x31, 0x2f, 0x63, 0x6f, + 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1b, 0x67, 0x6f, + 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, + 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x17, 0x76, 0x61, 0x6c, 0x69, 0x64, + 0x61, 0x74, 0x65, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, + 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x2d, 0x67, 0x65, 0x6e, 0x2d, 0x6f, 0x70, 0x65, + 0x6e, 0x61, 0x70, 0x69, 0x76, 0x32, 0x2f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x61, + 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x22, 0x9e, 0x01, 0x0a, 0x07, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x17, 0x0a, 0x02, + 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x07, 0xfa, 0x42, 0x04, 0x22, 0x02, 0x20, + 0x00, 0x52, 0x02, 0x69, 0x64, 0x12, 0x20, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x42, 0x07, 0xfa, 0x42, 0x04, 0x22, 0x02, 0x20, 0x00, 0x52, + 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x19, 0x0a, 0x03, 0x73, 0x6b, 0x75, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x03, 0x42, 0x07, 0xfa, 0x42, 0x04, 0x22, 0x02, 0x20, 0x00, 0x52, 0x03, 0x73, + 0x6b, 0x75, 0x12, 0x1e, 0x0a, 0x04, 0x74, 0x65, 0x78, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, + 0x42, 0x0a, 0xfa, 0x42, 0x07, 0x72, 0x05, 0x10, 0x01, 0x18, 0xff, 0x01, 0x52, 0x04, 0x74, 0x65, + 0x78, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, + 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, + 0x74, 0x22, 0x73, 0x0a, 0x14, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x43, 0x6f, 0x6d, 0x6d, 0x65, + 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x07, 0x75, 0x73, 0x65, + 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x07, 0xfa, 0x42, 0x04, 0x22, + 0x02, 0x20, 0x00, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x19, 0x0a, 0x03, 0x73, + 0x6b, 0x75, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x42, 0x07, 0xfa, 0x42, 0x04, 0x22, 0x02, 0x20, + 0x00, 0x52, 0x03, 0x73, 0x6b, 0x75, 0x12, 0x1e, 0x0a, 0x04, 0x74, 0x65, 0x78, 0x74, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x09, 0x42, 0x0a, 0xfa, 0x42, 0x07, 0x72, 0x05, 0x10, 0x01, 0x18, 0xff, 0x01, + 0x52, 0x04, 0x74, 0x65, 0x78, 0x74, 0x22, 0x3b, 0x0a, 0x15, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, + 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, + 0x22, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x08, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, + 0x65, 0x6e, 0x74, 0x22, 0x2c, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, + 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x17, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x03, 0x42, 0x07, 0xfa, 0x42, 0x04, 0x22, 0x02, 0x20, 0x00, 0x52, 0x02, 0x69, + 0x64, 0x22, 0x38, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x22, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, + 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x65, + 0x6e, 0x74, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x71, 0x0a, 0x14, 0x55, + 0x70, 0x64, 0x61, 0x74, 0x65, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x12, 0x17, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, + 0x07, 0xfa, 0x42, 0x04, 0x22, 0x02, 0x20, 0x00, 0x52, 0x02, 0x69, 0x64, 0x12, 0x20, 0x0a, 0x07, + 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x42, 0x07, 0xfa, + 0x42, 0x04, 0x22, 0x02, 0x20, 0x00, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1e, + 0x0a, 0x04, 0x74, 0x65, 0x78, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0a, 0xfa, 0x42, + 0x07, 0x72, 0x05, 0x10, 0x01, 0x18, 0xff, 0x01, 0x52, 0x04, 0x74, 0x65, 0x78, 0x74, 0x22, 0x3b, + 0x0a, 0x15, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x22, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, + 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x65, + 0x6e, 0x74, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x2d, 0x0a, 0x10, 0x4c, + 0x69, 0x73, 0x74, 0x42, 0x79, 0x53, 0x6b, 0x75, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x19, 0x0a, 0x03, 0x73, 0x6b, 0x75, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x07, 0xfa, 0x42, + 0x04, 0x22, 0x02, 0x20, 0x00, 0x52, 0x03, 0x73, 0x6b, 0x75, 0x22, 0x39, 0x0a, 0x11, 0x4c, 0x69, + 0x73, 0x74, 0x42, 0x79, 0x53, 0x6b, 0x75, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, + 0x24, 0x0a, 0x08, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, + 0x0b, 0x32, 0x08, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x08, 0x63, 0x6f, 0x6d, + 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x35, 0x0a, 0x11, 0x4c, 0x69, 0x73, 0x74, 0x42, 0x79, 0x55, + 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x07, 0x75, 0x73, + 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x07, 0xfa, 0x42, 0x04, + 0x22, 0x02, 0x20, 0x00, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, 0x3a, 0x0a, 0x12, + 0x4c, 0x69, 0x73, 0x74, 0x42, 0x79, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x24, 0x0a, 0x08, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x01, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x08, + 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x32, 0xde, 0x04, 0x0a, 0x08, 0x43, 0x6f, 0x6d, + 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x4d, 0x0a, 0x03, 0x41, 0x64, 0x64, 0x12, 0x15, 0x2e, 0x43, + 0x72, 0x65, 0x61, 0x74, 0x65, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x43, 0x6f, 0x6d, 0x6d, + 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x17, 0x82, 0xd3, 0xe4, + 0x93, 0x02, 0x11, 0x22, 0x0c, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x2f, 0x61, 0x64, + 0x64, 0x3a, 0x01, 0x2a, 0x12, 0x51, 0x0a, 0x07, 0x47, 0x65, 0x74, 0x42, 0x79, 0x49, 0x64, 0x12, + 0x12, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1d, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x17, + 0x22, 0x12, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x2f, 0x67, 0x65, 0x74, 0x2d, 0x62, + 0x79, 0x2d, 0x69, 0x64, 0x3a, 0x01, 0x2a, 0x12, 0x4f, 0x0a, 0x04, 0x45, 0x64, 0x69, 0x74, 0x12, + 0x15, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x43, + 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x18, + 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x12, 0x22, 0x0d, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, + 0x2f, 0x65, 0x64, 0x69, 0x74, 0x3a, 0x01, 0x2a, 0x12, 0x53, 0x0a, 0x09, 0x4c, 0x69, 0x73, 0x74, + 0x42, 0x79, 0x53, 0x6b, 0x75, 0x12, 0x11, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x42, 0x79, 0x53, 0x6b, + 0x75, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x42, + 0x79, 0x53, 0x6b, 0x75, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1f, 0x82, 0xd3, + 0xe4, 0x93, 0x02, 0x19, 0x22, 0x14, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x2f, 0x6c, + 0x69, 0x73, 0x74, 0x2d, 0x62, 0x79, 0x2d, 0x73, 0x6b, 0x75, 0x3a, 0x01, 0x2a, 0x12, 0x57, 0x0a, + 0x0a, 0x4c, 0x69, 0x73, 0x74, 0x42, 0x79, 0x55, 0x73, 0x65, 0x72, 0x12, 0x12, 0x2e, 0x4c, 0x69, + 0x73, 0x74, 0x42, 0x79, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x13, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x42, 0x79, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x20, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1a, 0x22, 0x15, 0x2f, 0x63, + 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x2f, 0x6c, 0x69, 0x73, 0x74, 0x2d, 0x62, 0x79, 0x2d, 0x75, + 0x73, 0x65, 0x72, 0x3a, 0x01, 0x2a, 0x1a, 0xb0, 0x01, 0x92, 0x41, 0xac, 0x01, 0x12, 0x0f, 0x43, + 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x1a, 0x98, + 0x01, 0x0a, 0x20, 0x46, 0x69, 0x6e, 0x64, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x6d, 0x6f, 0x72, 0x65, + 0x20, 0x61, 0x62, 0x6f, 0x75, 0x74, 0x20, 0x67, 0x72, 0x70, 0x63, 0x2d, 0x67, 0x61, 0x74, 0x65, + 0x77, 0x61, 0x79, 0x12, 0x74, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2d, 0x65, 0x63, 0x6f, + 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2d, 0x67, 0x61, 0x74, 0x65, + 0x77, 0x61, 0x79, 0x2f, 0x62, 0x6c, 0x6f, 0x62, 0x2f, 0x6d, 0x61, 0x69, 0x6e, 0x2f, 0x65, 0x78, + 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x70, 0x62, 0x2f, + 0x61, 0x5f, 0x62, 0x69, 0x74, 0x5f, 0x6f, 0x66, 0x5f, 0x65, 0x76, 0x65, 0x72, 0x79, 0x74, 0x68, + 0x69, 0x6e, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x42, 0x6d, 0x5a, 0x25, 0x72, 0x6f, 0x75, + 0x74, 0x65, 0x32, 0x35, 0x36, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, + 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, + 0x74, 0x73, 0x92, 0x41, 0x43, 0x12, 0x19, 0x0a, 0x10, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, + 0x73, 0x20, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x32, 0x05, 0x31, 0x2e, 0x30, 0x2e, 0x30, + 0x2a, 0x02, 0x01, 0x02, 0x32, 0x10, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x2f, 0x6a, 0x73, 0x6f, 0x6e, 0x3a, 0x10, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x2f, 0x6a, 0x73, 0x6f, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_comments_v1_comments_proto_rawDescOnce sync.Once + file_comments_v1_comments_proto_rawDescData = file_comments_v1_comments_proto_rawDesc +) + +func file_comments_v1_comments_proto_rawDescGZIP() []byte { + file_comments_v1_comments_proto_rawDescOnce.Do(func() { + file_comments_v1_comments_proto_rawDescData = protoimpl.X.CompressGZIP(file_comments_v1_comments_proto_rawDescData) + }) + return file_comments_v1_comments_proto_rawDescData +} + +var file_comments_v1_comments_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_comments_v1_comments_proto_goTypes = []interface{}{ + (*Comment)(nil), // 0: Comment + (*CreateCommentRequest)(nil), // 1: CreateCommentRequest + (*CreateCommentResponse)(nil), // 2: CreateCommentResponse + (*GetCommentRequest)(nil), // 3: GetCommentRequest + (*GetCommentResponse)(nil), // 4: GetCommentResponse + (*UpdateCommentRequest)(nil), // 5: UpdateCommentRequest + (*UpdateCommentResponse)(nil), // 6: UpdateCommentResponse + (*ListBySkuRequest)(nil), // 7: ListBySkuRequest + (*ListBySkuResponse)(nil), // 8: ListBySkuResponse + (*ListByUserRequest)(nil), // 9: ListByUserRequest + (*ListByUserResponse)(nil), // 10: ListByUserResponse +} +var file_comments_v1_comments_proto_depIdxs = []int32{ + 0, // 0: CreateCommentResponse.comment:type_name -> Comment + 0, // 1: GetCommentResponse.comment:type_name -> Comment + 0, // 2: UpdateCommentResponse.comment:type_name -> Comment + 0, // 3: ListBySkuResponse.comments:type_name -> Comment + 0, // 4: ListByUserResponse.comments:type_name -> Comment + 1, // 5: Comments.Add:input_type -> CreateCommentRequest + 3, // 6: Comments.GetById:input_type -> GetCommentRequest + 5, // 7: Comments.Edit:input_type -> UpdateCommentRequest + 7, // 8: Comments.ListBySku:input_type -> ListBySkuRequest + 9, // 9: Comments.ListByUser:input_type -> ListByUserRequest + 2, // 10: Comments.Add:output_type -> CreateCommentResponse + 4, // 11: Comments.GetById:output_type -> GetCommentResponse + 6, // 12: Comments.Edit:output_type -> UpdateCommentResponse + 8, // 13: Comments.ListBySku:output_type -> ListBySkuResponse + 10, // 14: Comments.ListByUser:output_type -> ListByUserResponse + 10, // [10:15] is the sub-list for method output_type + 5, // [5:10] is the sub-list for method input_type + 5, // [5:5] is the sub-list for extension type_name + 5, // [5:5] is the sub-list for extension extendee + 0, // [0:5] is the sub-list for field type_name +} + +func init() { file_comments_v1_comments_proto_init() } +func file_comments_v1_comments_proto_init() { + if File_comments_v1_comments_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_comments_v1_comments_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Comment); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_comments_v1_comments_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CreateCommentRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_comments_v1_comments_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CreateCommentResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_comments_v1_comments_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetCommentRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_comments_v1_comments_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetCommentResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_comments_v1_comments_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UpdateCommentRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_comments_v1_comments_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UpdateCommentResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_comments_v1_comments_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ListBySkuRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_comments_v1_comments_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ListBySkuResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_comments_v1_comments_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ListByUserRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_comments_v1_comments_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ListByUserResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_comments_v1_comments_proto_rawDesc, + NumEnums: 0, + NumMessages: 11, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_comments_v1_comments_proto_goTypes, + DependencyIndexes: file_comments_v1_comments_proto_depIdxs, + MessageInfos: file_comments_v1_comments_proto_msgTypes, + }.Build() + File_comments_v1_comments_proto = out.File + file_comments_v1_comments_proto_rawDesc = nil + file_comments_v1_comments_proto_goTypes = nil + file_comments_v1_comments_proto_depIdxs = nil +} diff --git a/pkg/api/comments/v1/comments.pb.gw.go b/pkg/api/comments/v1/comments.pb.gw.go new file mode 100644 index 0000000..10fb004 --- /dev/null +++ b/pkg/api/comments/v1/comments.pb.gw.go @@ -0,0 +1,471 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: comments/v1/comments.proto + +/* +Package comments is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package comments + +import ( + "context" + "io" + "net/http" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = metadata.Join + +func request_Comments_Add_0(ctx context.Context, marshaler runtime.Marshaler, client CommentsClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq CreateCommentRequest + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Add(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Comments_Add_0(ctx context.Context, marshaler runtime.Marshaler, server CommentsServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq CreateCommentRequest + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Add(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Comments_GetById_0(ctx context.Context, marshaler runtime.Marshaler, client CommentsClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetCommentRequest + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.GetById(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Comments_GetById_0(ctx context.Context, marshaler runtime.Marshaler, server CommentsServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetCommentRequest + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.GetById(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Comments_Edit_0(ctx context.Context, marshaler runtime.Marshaler, client CommentsClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq UpdateCommentRequest + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Edit(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Comments_Edit_0(ctx context.Context, marshaler runtime.Marshaler, server CommentsServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq UpdateCommentRequest + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Edit(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Comments_ListBySku_0(ctx context.Context, marshaler runtime.Marshaler, client CommentsClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ListBySkuRequest + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.ListBySku(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Comments_ListBySku_0(ctx context.Context, marshaler runtime.Marshaler, server CommentsServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ListBySkuRequest + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.ListBySku(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Comments_ListByUser_0(ctx context.Context, marshaler runtime.Marshaler, client CommentsClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ListByUserRequest + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.ListByUser(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Comments_ListByUser_0(ctx context.Context, marshaler runtime.Marshaler, server CommentsServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ListByUserRequest + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.ListByUser(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterCommentsHandlerServer registers the http handlers for service Comments to "mux". +// UnaryRPC :call CommentsServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterCommentsHandlerFromEndpoint instead. +func RegisterCommentsHandlerServer(ctx context.Context, mux *runtime.ServeMux, server CommentsServer) error { + + mux.Handle("POST", pattern_Comments_Add_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/.Comments/Add", runtime.WithHTTPPathPattern("/comment/add")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Comments_Add_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_Comments_Add_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_Comments_GetById_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/.Comments/GetById", runtime.WithHTTPPathPattern("/comment/get-by-id")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Comments_GetById_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_Comments_GetById_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_Comments_Edit_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/.Comments/Edit", runtime.WithHTTPPathPattern("/comment/edit")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Comments_Edit_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_Comments_Edit_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_Comments_ListBySku_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/.Comments/ListBySku", runtime.WithHTTPPathPattern("/comment/list-by-sku")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Comments_ListBySku_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_Comments_ListBySku_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_Comments_ListByUser_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/.Comments/ListByUser", runtime.WithHTTPPathPattern("/comment/list-by-user")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Comments_ListByUser_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_Comments_ListByUser_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterCommentsHandlerFromEndpoint is same as RegisterCommentsHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterCommentsHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.DialContext(ctx, endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterCommentsHandler(ctx, mux, conn) +} + +// RegisterCommentsHandler registers the http handlers for service Comments to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterCommentsHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterCommentsHandlerClient(ctx, mux, NewCommentsClient(conn)) +} + +// RegisterCommentsHandlerClient registers the http handlers for service Comments +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "CommentsClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "CommentsClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "CommentsClient" to call the correct interceptors. +func RegisterCommentsHandlerClient(ctx context.Context, mux *runtime.ServeMux, client CommentsClient) error { + + mux.Handle("POST", pattern_Comments_Add_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/.Comments/Add", runtime.WithHTTPPathPattern("/comment/add")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Comments_Add_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_Comments_Add_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_Comments_GetById_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/.Comments/GetById", runtime.WithHTTPPathPattern("/comment/get-by-id")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Comments_GetById_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_Comments_GetById_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_Comments_Edit_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/.Comments/Edit", runtime.WithHTTPPathPattern("/comment/edit")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Comments_Edit_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_Comments_Edit_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_Comments_ListBySku_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/.Comments/ListBySku", runtime.WithHTTPPathPattern("/comment/list-by-sku")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Comments_ListBySku_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_Comments_ListBySku_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("POST", pattern_Comments_ListByUser_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/.Comments/ListByUser", runtime.WithHTTPPathPattern("/comment/list-by-user")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Comments_ListByUser_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_Comments_ListByUser_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Comments_Add_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"comment", "add"}, "")) + + pattern_Comments_GetById_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"comment", "get-by-id"}, "")) + + pattern_Comments_Edit_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"comment", "edit"}, "")) + + pattern_Comments_ListBySku_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"comment", "list-by-sku"}, "")) + + pattern_Comments_ListByUser_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"comment", "list-by-user"}, "")) +) + +var ( + forward_Comments_Add_0 = runtime.ForwardResponseMessage + + forward_Comments_GetById_0 = runtime.ForwardResponseMessage + + forward_Comments_Edit_0 = runtime.ForwardResponseMessage + + forward_Comments_ListBySku_0 = runtime.ForwardResponseMessage + + forward_Comments_ListByUser_0 = runtime.ForwardResponseMessage +) diff --git a/pkg/api/comments/v1/comments.pb.validate.go b/pkg/api/comments/v1/comments.pb.validate.go new file mode 100644 index 0000000..8c0097c --- /dev/null +++ b/pkg/api/comments/v1/comments.pb.validate.go @@ -0,0 +1,1452 @@ +// Code generated by protoc-gen-validate. DO NOT EDIT. +// source: comments/v1/comments.proto + +package comments + +import ( + "bytes" + "errors" + "fmt" + "net" + "net/mail" + "net/url" + "regexp" + "sort" + "strings" + "time" + "unicode/utf8" + + "google.golang.org/protobuf/types/known/anypb" +) + +// ensure the imports are used +var ( + _ = bytes.MinRead + _ = errors.New("") + _ = fmt.Print + _ = utf8.UTFMax + _ = (*regexp.Regexp)(nil) + _ = (*strings.Reader)(nil) + _ = net.IPv4len + _ = time.Duration(0) + _ = (*url.URL)(nil) + _ = (*mail.Address)(nil) + _ = anypb.Any{} + _ = sort.Sort +) + +// Validate checks the field values on Comment with the rules defined in the +// proto definition for this message. If any rules are violated, the first +// error encountered is returned, or nil if there are no violations. +func (m *Comment) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on Comment with the rules defined in the +// proto definition for this message. If any rules are violated, the result is +// a list of violation errors wrapped in CommentMultiError, or nil if none found. +func (m *Comment) ValidateAll() error { + return m.validate(true) +} + +func (m *Comment) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if m.GetId() <= 0 { + err := CommentValidationError{ + field: "Id", + reason: "value must be greater than 0", + } + if !all { + return err + } + errors = append(errors, err) + } + + if m.GetUserId() <= 0 { + err := CommentValidationError{ + field: "UserId", + reason: "value must be greater than 0", + } + if !all { + return err + } + errors = append(errors, err) + } + + if m.GetSku() <= 0 { + err := CommentValidationError{ + field: "Sku", + reason: "value must be greater than 0", + } + if !all { + return err + } + errors = append(errors, err) + } + + if l := utf8.RuneCountInString(m.GetText()); l < 1 || l > 255 { + err := CommentValidationError{ + field: "Text", + reason: "value length must be between 1 and 255 runes, inclusive", + } + if !all { + return err + } + errors = append(errors, err) + } + + // no validation rules for CreatedAt + + if len(errors) > 0 { + return CommentMultiError(errors) + } + + return nil +} + +// CommentMultiError is an error wrapping multiple validation errors returned +// by Comment.ValidateAll() if the designated constraints aren't met. +type CommentMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m CommentMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m CommentMultiError) AllErrors() []error { return m } + +// CommentValidationError is the validation error returned by Comment.Validate +// if the designated constraints aren't met. +type CommentValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e CommentValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e CommentValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e CommentValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e CommentValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e CommentValidationError) ErrorName() string { return "CommentValidationError" } + +// Error satisfies the builtin error interface +func (e CommentValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sComment.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = CommentValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = CommentValidationError{} + +// Validate checks the field values on CreateCommentRequest with the rules +// defined in the proto definition for this message. If any rules are +// violated, the first error encountered is returned, or nil if there are no violations. +func (m *CreateCommentRequest) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on CreateCommentRequest with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// CreateCommentRequestMultiError, or nil if none found. +func (m *CreateCommentRequest) ValidateAll() error { + return m.validate(true) +} + +func (m *CreateCommentRequest) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if m.GetUserId() <= 0 { + err := CreateCommentRequestValidationError{ + field: "UserId", + reason: "value must be greater than 0", + } + if !all { + return err + } + errors = append(errors, err) + } + + if m.GetSku() <= 0 { + err := CreateCommentRequestValidationError{ + field: "Sku", + reason: "value must be greater than 0", + } + if !all { + return err + } + errors = append(errors, err) + } + + if l := utf8.RuneCountInString(m.GetText()); l < 1 || l > 255 { + err := CreateCommentRequestValidationError{ + field: "Text", + reason: "value length must be between 1 and 255 runes, inclusive", + } + if !all { + return err + } + errors = append(errors, err) + } + + if len(errors) > 0 { + return CreateCommentRequestMultiError(errors) + } + + return nil +} + +// CreateCommentRequestMultiError is an error wrapping multiple validation +// errors returned by CreateCommentRequest.ValidateAll() if the designated +// constraints aren't met. +type CreateCommentRequestMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m CreateCommentRequestMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m CreateCommentRequestMultiError) AllErrors() []error { return m } + +// CreateCommentRequestValidationError is the validation error returned by +// CreateCommentRequest.Validate if the designated constraints aren't met. +type CreateCommentRequestValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e CreateCommentRequestValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e CreateCommentRequestValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e CreateCommentRequestValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e CreateCommentRequestValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e CreateCommentRequestValidationError) ErrorName() string { + return "CreateCommentRequestValidationError" +} + +// Error satisfies the builtin error interface +func (e CreateCommentRequestValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sCreateCommentRequest.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = CreateCommentRequestValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = CreateCommentRequestValidationError{} + +// Validate checks the field values on CreateCommentResponse with the rules +// defined in the proto definition for this message. If any rules are +// violated, the first error encountered is returned, or nil if there are no violations. +func (m *CreateCommentResponse) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on CreateCommentResponse with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// CreateCommentResponseMultiError, or nil if none found. +func (m *CreateCommentResponse) ValidateAll() error { + return m.validate(true) +} + +func (m *CreateCommentResponse) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if all { + switch v := interface{}(m.GetComment()).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, CreateCommentResponseValidationError{ + field: "Comment", + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, CreateCommentResponseValidationError{ + field: "Comment", + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(m.GetComment()).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return CreateCommentResponseValidationError{ + field: "Comment", + reason: "embedded message failed validation", + cause: err, + } + } + } + + if len(errors) > 0 { + return CreateCommentResponseMultiError(errors) + } + + return nil +} + +// CreateCommentResponseMultiError is an error wrapping multiple validation +// errors returned by CreateCommentResponse.ValidateAll() if the designated +// constraints aren't met. +type CreateCommentResponseMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m CreateCommentResponseMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m CreateCommentResponseMultiError) AllErrors() []error { return m } + +// CreateCommentResponseValidationError is the validation error returned by +// CreateCommentResponse.Validate if the designated constraints aren't met. +type CreateCommentResponseValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e CreateCommentResponseValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e CreateCommentResponseValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e CreateCommentResponseValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e CreateCommentResponseValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e CreateCommentResponseValidationError) ErrorName() string { + return "CreateCommentResponseValidationError" +} + +// Error satisfies the builtin error interface +func (e CreateCommentResponseValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sCreateCommentResponse.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = CreateCommentResponseValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = CreateCommentResponseValidationError{} + +// Validate checks the field values on GetCommentRequest with the rules defined +// in the proto definition for this message. If any rules are violated, the +// first error encountered is returned, or nil if there are no violations. +func (m *GetCommentRequest) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on GetCommentRequest with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// GetCommentRequestMultiError, or nil if none found. +func (m *GetCommentRequest) ValidateAll() error { + return m.validate(true) +} + +func (m *GetCommentRequest) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if m.GetId() <= 0 { + err := GetCommentRequestValidationError{ + field: "Id", + reason: "value must be greater than 0", + } + if !all { + return err + } + errors = append(errors, err) + } + + if len(errors) > 0 { + return GetCommentRequestMultiError(errors) + } + + return nil +} + +// GetCommentRequestMultiError is an error wrapping multiple validation errors +// returned by GetCommentRequest.ValidateAll() if the designated constraints +// aren't met. +type GetCommentRequestMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m GetCommentRequestMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m GetCommentRequestMultiError) AllErrors() []error { return m } + +// GetCommentRequestValidationError is the validation error returned by +// GetCommentRequest.Validate if the designated constraints aren't met. +type GetCommentRequestValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e GetCommentRequestValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e GetCommentRequestValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e GetCommentRequestValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e GetCommentRequestValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e GetCommentRequestValidationError) ErrorName() string { + return "GetCommentRequestValidationError" +} + +// Error satisfies the builtin error interface +func (e GetCommentRequestValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sGetCommentRequest.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = GetCommentRequestValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = GetCommentRequestValidationError{} + +// Validate checks the field values on GetCommentResponse with the rules +// defined in the proto definition for this message. If any rules are +// violated, the first error encountered is returned, or nil if there are no violations. +func (m *GetCommentResponse) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on GetCommentResponse with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// GetCommentResponseMultiError, or nil if none found. +func (m *GetCommentResponse) ValidateAll() error { + return m.validate(true) +} + +func (m *GetCommentResponse) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if all { + switch v := interface{}(m.GetComment()).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, GetCommentResponseValidationError{ + field: "Comment", + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, GetCommentResponseValidationError{ + field: "Comment", + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(m.GetComment()).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return GetCommentResponseValidationError{ + field: "Comment", + reason: "embedded message failed validation", + cause: err, + } + } + } + + if len(errors) > 0 { + return GetCommentResponseMultiError(errors) + } + + return nil +} + +// GetCommentResponseMultiError is an error wrapping multiple validation errors +// returned by GetCommentResponse.ValidateAll() if the designated constraints +// aren't met. +type GetCommentResponseMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m GetCommentResponseMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m GetCommentResponseMultiError) AllErrors() []error { return m } + +// GetCommentResponseValidationError is the validation error returned by +// GetCommentResponse.Validate if the designated constraints aren't met. +type GetCommentResponseValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e GetCommentResponseValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e GetCommentResponseValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e GetCommentResponseValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e GetCommentResponseValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e GetCommentResponseValidationError) ErrorName() string { + return "GetCommentResponseValidationError" +} + +// Error satisfies the builtin error interface +func (e GetCommentResponseValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sGetCommentResponse.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = GetCommentResponseValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = GetCommentResponseValidationError{} + +// Validate checks the field values on UpdateCommentRequest with the rules +// defined in the proto definition for this message. If any rules are +// violated, the first error encountered is returned, or nil if there are no violations. +func (m *UpdateCommentRequest) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on UpdateCommentRequest with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// UpdateCommentRequestMultiError, or nil if none found. +func (m *UpdateCommentRequest) ValidateAll() error { + return m.validate(true) +} + +func (m *UpdateCommentRequest) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if m.GetId() <= 0 { + err := UpdateCommentRequestValidationError{ + field: "Id", + reason: "value must be greater than 0", + } + if !all { + return err + } + errors = append(errors, err) + } + + if m.GetUserId() <= 0 { + err := UpdateCommentRequestValidationError{ + field: "UserId", + reason: "value must be greater than 0", + } + if !all { + return err + } + errors = append(errors, err) + } + + if l := utf8.RuneCountInString(m.GetText()); l < 1 || l > 255 { + err := UpdateCommentRequestValidationError{ + field: "Text", + reason: "value length must be between 1 and 255 runes, inclusive", + } + if !all { + return err + } + errors = append(errors, err) + } + + if len(errors) > 0 { + return UpdateCommentRequestMultiError(errors) + } + + return nil +} + +// UpdateCommentRequestMultiError is an error wrapping multiple validation +// errors returned by UpdateCommentRequest.ValidateAll() if the designated +// constraints aren't met. +type UpdateCommentRequestMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m UpdateCommentRequestMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m UpdateCommentRequestMultiError) AllErrors() []error { return m } + +// UpdateCommentRequestValidationError is the validation error returned by +// UpdateCommentRequest.Validate if the designated constraints aren't met. +type UpdateCommentRequestValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e UpdateCommentRequestValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e UpdateCommentRequestValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e UpdateCommentRequestValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e UpdateCommentRequestValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e UpdateCommentRequestValidationError) ErrorName() string { + return "UpdateCommentRequestValidationError" +} + +// Error satisfies the builtin error interface +func (e UpdateCommentRequestValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sUpdateCommentRequest.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = UpdateCommentRequestValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = UpdateCommentRequestValidationError{} + +// Validate checks the field values on UpdateCommentResponse with the rules +// defined in the proto definition for this message. If any rules are +// violated, the first error encountered is returned, or nil if there are no violations. +func (m *UpdateCommentResponse) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on UpdateCommentResponse with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// UpdateCommentResponseMultiError, or nil if none found. +func (m *UpdateCommentResponse) ValidateAll() error { + return m.validate(true) +} + +func (m *UpdateCommentResponse) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if all { + switch v := interface{}(m.GetComment()).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, UpdateCommentResponseValidationError{ + field: "Comment", + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, UpdateCommentResponseValidationError{ + field: "Comment", + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(m.GetComment()).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return UpdateCommentResponseValidationError{ + field: "Comment", + reason: "embedded message failed validation", + cause: err, + } + } + } + + if len(errors) > 0 { + return UpdateCommentResponseMultiError(errors) + } + + return nil +} + +// UpdateCommentResponseMultiError is an error wrapping multiple validation +// errors returned by UpdateCommentResponse.ValidateAll() if the designated +// constraints aren't met. +type UpdateCommentResponseMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m UpdateCommentResponseMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m UpdateCommentResponseMultiError) AllErrors() []error { return m } + +// UpdateCommentResponseValidationError is the validation error returned by +// UpdateCommentResponse.Validate if the designated constraints aren't met. +type UpdateCommentResponseValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e UpdateCommentResponseValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e UpdateCommentResponseValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e UpdateCommentResponseValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e UpdateCommentResponseValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e UpdateCommentResponseValidationError) ErrorName() string { + return "UpdateCommentResponseValidationError" +} + +// Error satisfies the builtin error interface +func (e UpdateCommentResponseValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sUpdateCommentResponse.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = UpdateCommentResponseValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = UpdateCommentResponseValidationError{} + +// Validate checks the field values on ListBySkuRequest with the rules defined +// in the proto definition for this message. If any rules are violated, the +// first error encountered is returned, or nil if there are no violations. +func (m *ListBySkuRequest) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on ListBySkuRequest with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// ListBySkuRequestMultiError, or nil if none found. +func (m *ListBySkuRequest) ValidateAll() error { + return m.validate(true) +} + +func (m *ListBySkuRequest) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if m.GetSku() <= 0 { + err := ListBySkuRequestValidationError{ + field: "Sku", + reason: "value must be greater than 0", + } + if !all { + return err + } + errors = append(errors, err) + } + + if len(errors) > 0 { + return ListBySkuRequestMultiError(errors) + } + + return nil +} + +// ListBySkuRequestMultiError is an error wrapping multiple validation errors +// returned by ListBySkuRequest.ValidateAll() if the designated constraints +// aren't met. +type ListBySkuRequestMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m ListBySkuRequestMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m ListBySkuRequestMultiError) AllErrors() []error { return m } + +// ListBySkuRequestValidationError is the validation error returned by +// ListBySkuRequest.Validate if the designated constraints aren't met. +type ListBySkuRequestValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e ListBySkuRequestValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e ListBySkuRequestValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e ListBySkuRequestValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e ListBySkuRequestValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e ListBySkuRequestValidationError) ErrorName() string { return "ListBySkuRequestValidationError" } + +// Error satisfies the builtin error interface +func (e ListBySkuRequestValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sListBySkuRequest.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = ListBySkuRequestValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = ListBySkuRequestValidationError{} + +// Validate checks the field values on ListBySkuResponse with the rules defined +// in the proto definition for this message. If any rules are violated, the +// first error encountered is returned, or nil if there are no violations. +func (m *ListBySkuResponse) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on ListBySkuResponse with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// ListBySkuResponseMultiError, or nil if none found. +func (m *ListBySkuResponse) ValidateAll() error { + return m.validate(true) +} + +func (m *ListBySkuResponse) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + for idx, item := range m.GetComments() { + _, _ = idx, item + + if all { + switch v := interface{}(item).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, ListBySkuResponseValidationError{ + field: fmt.Sprintf("Comments[%v]", idx), + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, ListBySkuResponseValidationError{ + field: fmt.Sprintf("Comments[%v]", idx), + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(item).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return ListBySkuResponseValidationError{ + field: fmt.Sprintf("Comments[%v]", idx), + reason: "embedded message failed validation", + cause: err, + } + } + } + + } + + if len(errors) > 0 { + return ListBySkuResponseMultiError(errors) + } + + return nil +} + +// ListBySkuResponseMultiError is an error wrapping multiple validation errors +// returned by ListBySkuResponse.ValidateAll() if the designated constraints +// aren't met. +type ListBySkuResponseMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m ListBySkuResponseMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m ListBySkuResponseMultiError) AllErrors() []error { return m } + +// ListBySkuResponseValidationError is the validation error returned by +// ListBySkuResponse.Validate if the designated constraints aren't met. +type ListBySkuResponseValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e ListBySkuResponseValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e ListBySkuResponseValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e ListBySkuResponseValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e ListBySkuResponseValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e ListBySkuResponseValidationError) ErrorName() string { + return "ListBySkuResponseValidationError" +} + +// Error satisfies the builtin error interface +func (e ListBySkuResponseValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sListBySkuResponse.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = ListBySkuResponseValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = ListBySkuResponseValidationError{} + +// Validate checks the field values on ListByUserRequest with the rules defined +// in the proto definition for this message. If any rules are violated, the +// first error encountered is returned, or nil if there are no violations. +func (m *ListByUserRequest) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on ListByUserRequest with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// ListByUserRequestMultiError, or nil if none found. +func (m *ListByUserRequest) ValidateAll() error { + return m.validate(true) +} + +func (m *ListByUserRequest) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if m.GetUserId() <= 0 { + err := ListByUserRequestValidationError{ + field: "UserId", + reason: "value must be greater than 0", + } + if !all { + return err + } + errors = append(errors, err) + } + + if len(errors) > 0 { + return ListByUserRequestMultiError(errors) + } + + return nil +} + +// ListByUserRequestMultiError is an error wrapping multiple validation errors +// returned by ListByUserRequest.ValidateAll() if the designated constraints +// aren't met. +type ListByUserRequestMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m ListByUserRequestMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m ListByUserRequestMultiError) AllErrors() []error { return m } + +// ListByUserRequestValidationError is the validation error returned by +// ListByUserRequest.Validate if the designated constraints aren't met. +type ListByUserRequestValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e ListByUserRequestValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e ListByUserRequestValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e ListByUserRequestValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e ListByUserRequestValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e ListByUserRequestValidationError) ErrorName() string { + return "ListByUserRequestValidationError" +} + +// Error satisfies the builtin error interface +func (e ListByUserRequestValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sListByUserRequest.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = ListByUserRequestValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = ListByUserRequestValidationError{} + +// Validate checks the field values on ListByUserResponse with the rules +// defined in the proto definition for this message. If any rules are +// violated, the first error encountered is returned, or nil if there are no violations. +func (m *ListByUserResponse) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on ListByUserResponse with the rules +// defined in the proto definition for this message. If any rules are +// violated, the result is a list of violation errors wrapped in +// ListByUserResponseMultiError, or nil if none found. +func (m *ListByUserResponse) ValidateAll() error { + return m.validate(true) +} + +func (m *ListByUserResponse) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + for idx, item := range m.GetComments() { + _, _ = idx, item + + if all { + switch v := interface{}(item).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, ListByUserResponseValidationError{ + field: fmt.Sprintf("Comments[%v]", idx), + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, ListByUserResponseValidationError{ + field: fmt.Sprintf("Comments[%v]", idx), + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(item).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return ListByUserResponseValidationError{ + field: fmt.Sprintf("Comments[%v]", idx), + reason: "embedded message failed validation", + cause: err, + } + } + } + + } + + if len(errors) > 0 { + return ListByUserResponseMultiError(errors) + } + + return nil +} + +// ListByUserResponseMultiError is an error wrapping multiple validation errors +// returned by ListByUserResponse.ValidateAll() if the designated constraints +// aren't met. +type ListByUserResponseMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m ListByUserResponseMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m ListByUserResponseMultiError) AllErrors() []error { return m } + +// ListByUserResponseValidationError is the validation error returned by +// ListByUserResponse.Validate if the designated constraints aren't met. +type ListByUserResponseValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e ListByUserResponseValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e ListByUserResponseValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e ListByUserResponseValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e ListByUserResponseValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e ListByUserResponseValidationError) ErrorName() string { + return "ListByUserResponseValidationError" +} + +// Error satisfies the builtin error interface +func (e ListByUserResponseValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sListByUserResponse.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = ListByUserResponseValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = ListByUserResponseValidationError{} diff --git a/pkg/api/comments/v1/comments_grpc.pb.go b/pkg/api/comments/v1/comments_grpc.pb.go new file mode 100644 index 0000000..664bb74 --- /dev/null +++ b/pkg/api/comments/v1/comments_grpc.pb.go @@ -0,0 +1,249 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v6.30.0 +// source: comments/v1/comments.proto + +package comments + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +// CommentsClient is the client API for Comments service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type CommentsClient interface { + Add(ctx context.Context, in *CreateCommentRequest, opts ...grpc.CallOption) (*CreateCommentResponse, error) + GetById(ctx context.Context, in *GetCommentRequest, opts ...grpc.CallOption) (*GetCommentResponse, error) + Edit(ctx context.Context, in *UpdateCommentRequest, opts ...grpc.CallOption) (*UpdateCommentResponse, error) + ListBySku(ctx context.Context, in *ListBySkuRequest, opts ...grpc.CallOption) (*ListBySkuResponse, error) + ListByUser(ctx context.Context, in *ListByUserRequest, opts ...grpc.CallOption) (*ListByUserResponse, error) +} + +type commentsClient struct { + cc grpc.ClientConnInterface +} + +func NewCommentsClient(cc grpc.ClientConnInterface) CommentsClient { + return &commentsClient{cc} +} + +func (c *commentsClient) Add(ctx context.Context, in *CreateCommentRequest, opts ...grpc.CallOption) (*CreateCommentResponse, error) { + out := new(CreateCommentResponse) + err := c.cc.Invoke(ctx, "/Comments/Add", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *commentsClient) GetById(ctx context.Context, in *GetCommentRequest, opts ...grpc.CallOption) (*GetCommentResponse, error) { + out := new(GetCommentResponse) + err := c.cc.Invoke(ctx, "/Comments/GetById", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *commentsClient) Edit(ctx context.Context, in *UpdateCommentRequest, opts ...grpc.CallOption) (*UpdateCommentResponse, error) { + out := new(UpdateCommentResponse) + err := c.cc.Invoke(ctx, "/Comments/Edit", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *commentsClient) ListBySku(ctx context.Context, in *ListBySkuRequest, opts ...grpc.CallOption) (*ListBySkuResponse, error) { + out := new(ListBySkuResponse) + err := c.cc.Invoke(ctx, "/Comments/ListBySku", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *commentsClient) ListByUser(ctx context.Context, in *ListByUserRequest, opts ...grpc.CallOption) (*ListByUserResponse, error) { + out := new(ListByUserResponse) + err := c.cc.Invoke(ctx, "/Comments/ListByUser", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// CommentsServer is the server API for Comments service. +// All implementations must embed UnimplementedCommentsServer +// for forward compatibility +type CommentsServer interface { + Add(context.Context, *CreateCommentRequest) (*CreateCommentResponse, error) + GetById(context.Context, *GetCommentRequest) (*GetCommentResponse, error) + Edit(context.Context, *UpdateCommentRequest) (*UpdateCommentResponse, error) + ListBySku(context.Context, *ListBySkuRequest) (*ListBySkuResponse, error) + ListByUser(context.Context, *ListByUserRequest) (*ListByUserResponse, error) + mustEmbedUnimplementedCommentsServer() +} + +// UnimplementedCommentsServer must be embedded to have forward compatible implementations. +type UnimplementedCommentsServer struct { +} + +func (UnimplementedCommentsServer) Add(context.Context, *CreateCommentRequest) (*CreateCommentResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Add not implemented") +} +func (UnimplementedCommentsServer) GetById(context.Context, *GetCommentRequest) (*GetCommentResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetById not implemented") +} +func (UnimplementedCommentsServer) Edit(context.Context, *UpdateCommentRequest) (*UpdateCommentResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Edit not implemented") +} +func (UnimplementedCommentsServer) ListBySku(context.Context, *ListBySkuRequest) (*ListBySkuResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ListBySku not implemented") +} +func (UnimplementedCommentsServer) ListByUser(context.Context, *ListByUserRequest) (*ListByUserResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ListByUser not implemented") +} +func (UnimplementedCommentsServer) mustEmbedUnimplementedCommentsServer() {} + +// UnsafeCommentsServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to CommentsServer will +// result in compilation errors. +type UnsafeCommentsServer interface { + mustEmbedUnimplementedCommentsServer() +} + +func RegisterCommentsServer(s grpc.ServiceRegistrar, srv CommentsServer) { + s.RegisterService(&Comments_ServiceDesc, srv) +} + +func _Comments_Add_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateCommentRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CommentsServer).Add(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/Comments/Add", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CommentsServer).Add(ctx, req.(*CreateCommentRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Comments_GetById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetCommentRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CommentsServer).GetById(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/Comments/GetById", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CommentsServer).GetById(ctx, req.(*GetCommentRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Comments_Edit_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateCommentRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CommentsServer).Edit(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/Comments/Edit", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CommentsServer).Edit(ctx, req.(*UpdateCommentRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Comments_ListBySku_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ListBySkuRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CommentsServer).ListBySku(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/Comments/ListBySku", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CommentsServer).ListBySku(ctx, req.(*ListBySkuRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Comments_ListByUser_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ListByUserRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CommentsServer).ListByUser(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/Comments/ListByUser", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CommentsServer).ListByUser(ctx, req.(*ListByUserRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// Comments_ServiceDesc is the grpc.ServiceDesc for Comments service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Comments_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "Comments", + HandlerType: (*CommentsServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Add", + Handler: _Comments_Add_Handler, + }, + { + MethodName: "GetById", + Handler: _Comments_GetById_Handler, + }, + { + MethodName: "Edit", + Handler: _Comments_Edit_Handler, + }, + { + MethodName: "ListBySku", + Handler: _Comments_ListBySku_Handler, + }, + { + MethodName: "ListByUser", + Handler: _Comments_ListByUser_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "comments/v1/comments.proto", +}