syntax = "proto3";

package blog.api.v1;

option go_package = "github.com/go-kratos/kratos/examples/blog/api/v1;v1";
option java_multiple_files = true;
option java_package = "blog.api.v1";

import "google/api/annotations.proto";
// the validate rules:
// https://github.com/envoyproxy/protoc-gen-validate
import "validate/validate.proto";

service BlogService {
    rpc CreateArticle (CreateArticleRequest) returns (CreateArticleReply) {
        option (google.api.http) = {
            post: "/v1/article/"
            body: "*"
        };
    }
    rpc UpdateArticle (UpdateArticleRequest) returns (UpdateArticleReply) {
        option (google.api.http) = {
            put: "/v1/article/{id}"
            body: "*"
        };
    }
    rpc DeleteArticle (DeleteArticleRequest) returns (DeleteArticleReply) {
        option (google.api.http) = {
            delete: "/v1/article/{id}"
        };
    }
    rpc GetArticle (GetArticleRequest) returns (GetArticleReply) {
        option (google.api.http) = {
            get: "/v1/article/{id}"
        };
    }
    rpc ListArticle (ListArticleRequest) returns (ListArticleReply) {
        option (google.api.http) = {
            get: "/v1/article/"
        };
    }
}

message Article {
    int64 id = 1;
    string title = 2;
    string content = 3;
    int64 like = 4;
}

message CreateArticleRequest {
    string title = 1 [(validate.rules).string = {min_len: 5, max_len: 50}]; // the title of string must be between 5 and 50 character
    string content = 2;
}

message CreateArticleReply {
    Article Article = 1;
}

message UpdateArticleRequest {
    int64 id = 1 [(validate.rules).int64 = {gt: 0}];
    string title = 2 [(validate.rules).string = {min_len: 5, max_len: 50}]; // the title of string must be between 5 and 50 character;
    string content = 3;
}

message UpdateArticleReply {
    Article Article = 1;
}

message DeleteArticleRequest {
    int64 id = 1;
}
message DeleteArticleReply {
}

message GetArticleRequest {
    int64 id = 1;
}

message GetArticleReply {
    Article Article = 1;
}

message ListArticleRequest {
}

message ListArticleReply {
    repeated Article results = 1;
}
