Quran API (#205)

* Add basic version of a Quran API

* remove examples json swp

* fix search translation

* add examples json
This commit is contained in:
Asim Aslam
2021-09-14 18:45:22 +01:00
committed by GitHub
parent b50d585e02
commit f0542b1a6a
14 changed files with 2530 additions and 0 deletions

1577
quran/proto/quran.pb.go Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,144 @@
// Code generated by protoc-gen-micro. DO NOT EDIT.
// source: proto/quran.proto
package quran
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)
import (
context "context"
api "github.com/micro/micro/v3/service/api"
client "github.com/micro/micro/v3/service/client"
server "github.com/micro/micro/v3/service/server"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
// Reference imports to suppress errors if they are not otherwise used.
var _ api.Endpoint
var _ context.Context
var _ client.Option
var _ server.Option
// Api Endpoints for Quran service
func NewQuranEndpoints() []*api.Endpoint {
return []*api.Endpoint{}
}
// Client API for Quran service
type QuranService interface {
Chapters(ctx context.Context, in *ChaptersRequest, opts ...client.CallOption) (*ChaptersResponse, error)
Summary(ctx context.Context, in *SummaryRequest, opts ...client.CallOption) (*SummaryResponse, error)
Verses(ctx context.Context, in *VersesRequest, opts ...client.CallOption) (*VersesResponse, error)
Search(ctx context.Context, in *SearchRequest, opts ...client.CallOption) (*SearchResponse, error)
}
type quranService struct {
c client.Client
name string
}
func NewQuranService(name string, c client.Client) QuranService {
return &quranService{
c: c,
name: name,
}
}
func (c *quranService) Chapters(ctx context.Context, in *ChaptersRequest, opts ...client.CallOption) (*ChaptersResponse, error) {
req := c.c.NewRequest(c.name, "Quran.Chapters", in)
out := new(ChaptersResponse)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *quranService) Summary(ctx context.Context, in *SummaryRequest, opts ...client.CallOption) (*SummaryResponse, error) {
req := c.c.NewRequest(c.name, "Quran.Summary", in)
out := new(SummaryResponse)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *quranService) Verses(ctx context.Context, in *VersesRequest, opts ...client.CallOption) (*VersesResponse, error) {
req := c.c.NewRequest(c.name, "Quran.Verses", in)
out := new(VersesResponse)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *quranService) Search(ctx context.Context, in *SearchRequest, opts ...client.CallOption) (*SearchResponse, error) {
req := c.c.NewRequest(c.name, "Quran.Search", in)
out := new(SearchResponse)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for Quran service
type QuranHandler interface {
Chapters(context.Context, *ChaptersRequest, *ChaptersResponse) error
Summary(context.Context, *SummaryRequest, *SummaryResponse) error
Verses(context.Context, *VersesRequest, *VersesResponse) error
Search(context.Context, *SearchRequest, *SearchResponse) error
}
func RegisterQuranHandler(s server.Server, hdlr QuranHandler, opts ...server.HandlerOption) error {
type quran interface {
Chapters(ctx context.Context, in *ChaptersRequest, out *ChaptersResponse) error
Summary(ctx context.Context, in *SummaryRequest, out *SummaryResponse) error
Verses(ctx context.Context, in *VersesRequest, out *VersesResponse) error
Search(ctx context.Context, in *SearchRequest, out *SearchResponse) error
}
type Quran struct {
quran
}
h := &quranHandler{hdlr}
return s.Handle(s.NewHandler(&Quran{h}, opts...))
}
type quranHandler struct {
QuranHandler
}
func (h *quranHandler) Chapters(ctx context.Context, in *ChaptersRequest, out *ChaptersResponse) error {
return h.QuranHandler.Chapters(ctx, in, out)
}
func (h *quranHandler) Summary(ctx context.Context, in *SummaryRequest, out *SummaryResponse) error {
return h.QuranHandler.Summary(ctx, in, out)
}
func (h *quranHandler) Verses(ctx context.Context, in *VersesRequest, out *VersesResponse) error {
return h.QuranHandler.Verses(ctx, in, out)
}
func (h *quranHandler) Search(ctx context.Context, in *SearchRequest, out *SearchResponse) error {
return h.QuranHandler.Search(ctx, in, out)
}

191
quran/proto/quran.proto Normal file
View File

@@ -0,0 +1,191 @@
syntax = "proto3";
package quran;
option go_package = "./proto;quran";
service Quran {
rpc Chapters(ChaptersRequest) returns (ChaptersResponse) {}
rpc Summary(SummaryRequest) returns (SummaryResponse) {}
rpc Verses(VersesRequest) returns (VersesResponse) {}
rpc Search(SearchRequest) returns (SearchResponse) {}
}
message Chapter {
// The id of the chapter as a number e.g 1
int32 id = 1;
// The number of verses in the chapter
int32 verses = 2;
// The simple name of the chapter
string name = 3;
// The arabic name of the chapter
string arabic_name = 4;
// The complex name of the chapter
string complex_name = 5;
// The translated name
string translated_name = 6;
// Should the chapter start with bismillah
bool prefix_bismillah = 7;
// The place of revelation
string revelation_place = 8;
// The order in which it was revealed
int32 revelation_order = 9;
// The pages from and to e.g 1, 1
repeated int32 pages = 10;
}
message Verse {
// The unique id of the verse in the whole book
int32 id = 1;
// The verse number in this chapter
int32 number = 2;
// The key of this verse (chapter:verse) e.g 1:1
string key = 3;
// The page of the Quran this verse is on
int32 page = 4;
// The arabic text for this verse
string text = 5;
// The phonetic transliteration from arabic
string transliteration = 6;
// The basic translation of the verse
string translated_text = 7;
// The alternative translations for the verse
repeated Translation translations = 8;
// The interpretations of the verse
repeated Interpretation interpretations = 9;
// The individual words within the verse (Ayah)
repeated Word words = 10;
}
message Interpretation {
// The unique id of the interpretation
int32 id = 1;
// The source of the interpretation
string source = 2;
// The translated text
string text = 3;
}
message Translation {
// The unique id of the translation
int32 id = 1;
// The source of the translation
string source = 2;
// The translated text
string text = 3;
}
message Word {
// The id of the word within the verse
int32 id = 1;
// The position of the word
int32 position = 2;
// The character type e.g word, end
string char_type = 3;
// The page number
int32 page = 4;
// The line number
int32 line = 5;
// The arabic text for this word
string text = 6;
// The QCF v2 font code
string code = 7;
// The translated text
string translation = 8;
// The transliteration text
string transliteration = 9;
}
message Result {
// The unique verse id across the Quran
int32 verse_id = 1;
// The verse key e.g 1:1
string verse_key = 2;
// The associated arabic text
string text = 3;
// The related translations to the text
repeated Translation translations = 4;
}
// List the Chapters (surahs) of the Quran
message ChaptersRequest {
// Specify the language e.g en
string language = 1;
}
message ChaptersResponse {
repeated Chapter chapters = 1;
}
// Get a summary for a given chapter (surah)
message SummaryRequest {
// The chapter id e.g 1
int32 chapter = 1;
// Specify the language e.g en
string language = 2;
}
message SummaryResponse {
// The chapter id
int32 chapter = 1;
// The short summary for the chapter
string summary = 2;
// The source of the summary
string source = 3;
// The full description for the chapter
string text = 4;
}
// Lookup the verses (ayahs) for a chapter
message VersesRequest {
// The chapter id to retrieve
int32 chapter = 1;
// The language of translation
string language = 2;
// Return the individual words with the verses
bool words = 3;
// Return the interpretation (tafsir)
bool interpret = 4;
// Return alternate translations
bool translate = 5;
// The page number to request
int32 page = 6;
// The verses per page
int32 limit = 7;
}
message VersesResponse {
// The chapter requested
int32 chapter = 1;
// The page requested
int32 page = 2;
// The total pages
int32 total_pages = 3;
// The verses on the page
repeated Verse verses = 4;
}
// Search the Quran for any form of query or questions
message SearchRequest {
// The query to ask
string query = 1;
// The language for translation
string language = 2;
// The number of results to return
int32 limit = 3;
// The pagination number
int32 page = 4;
}
message SearchResponse {
// The question asked
string query = 1;
// The total results returned
int32 total_results = 2;
// The current page
int32 page = 3;
// The total pages
int32 total_pages = 4;
// The results for the query
repeated Result results = 5;
}