Skip to content
This repository has been archived by the owner on Apr 12, 2023. It is now read-only.

Commit

Permalink
feat: release stable version 3.0.0 (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
erwindosianipar authored Mar 22, 2022
1 parent e7ef247 commit b584007
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 27 deletions.
58 changes: 48 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,60 @@
![Uptime Robot ratio (7 days)](https://img.shields.io/uptimerobot/ratio/7/m786403864-a6328db4aa0b4270dadbe851)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Ferwindosianipar%2Fapi-alkitab.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Ferwindosianipar%2Fapi-alkitab?ref=badge_shield)

## Demo: [https://api-alkitab.herokuapp.com](https://api-alkitab.herokuapp.com)
## 🚧🚧 KODE SUMBER INI TIDAK DIKEMBANGKAN LAGI 🚧🚧

Versi tetap dari kode sumber ini adalah V3 dan kode sumber ini tidak akan dikembangkan lagi namun **masih dapat digunakan**. Untuk kode sumber yang masih dilanjutkan pengembangannya dipindahkan ke [Repository Biblika](https://github.com/biblika/biblika-api) yang lebih cepat karena menggunakan gRPC dan *response* lebih sederhana.

## [https://api-alkitab.herokuapp.com](https://api-alkitab.herokuapp.com)

API Alkitab Indonesia adalah sebuah *third-party backend* Alkitab yang sumber bacaannya berasal dari [sabda.org](https://sabda.org).

[sabda.org](https://sabda.org) adalah sebuah Yayasan Kristen non-profit dan non-komersial yang bergerak dalam bidang pelayanan media komputer dan internet di Indonesia.
[sabda.org](https://sabda.org) adalah sebuah Yayasan Kristen non-profit dan non-komersial yang bergerak dalam bidang pelayanan media komputer dan Internet di Indonesia.

## Dokumentasi

Versi saat (**v2.2.1**) telah memiliki tiga fitur utama untuk menampilkan list pasal, ayat, dan pasal Alkitab.
Versi saat (**v3.0.0**) telah memiliki tiga fitur utama untuk menampilkan list pasal, ayat dengan judul, dan pasal Alkitab.

### Passage List

Untuk menampilkan passage list perjanjian lama dan baru
### Passage Content V3

#### Base URL

Version | URL
-- | --
v2 | [https://api-alkitab.herokuapp.com/v2/passage/list](https://api-alkitab.herokuapp.com/v2/passage/list)
v3 | [https://api-alkitab.herokuapp.com/v3/passage/Yoh/1?ver=tb](https://api-alkitab.herokuapp.com/v3/passage/Yoh/1?ver=tb)

#### Example

Version | Method | URL
-- | -- | --
v3 | GET | [https://api-alkitab.herokuapp.com/v3/passage/{**chapter**}/{**chapter**}?ver={**ver**}](https://api-alkitab.herokuapp.com/v3/passage/Yoh/1?ver=tb)

#### Response

``` bash
{
"title": "Yohanes 1:1-51",
"book_number": 43,
"chapter": 1,
"verses": [
{
"verse": 0,
"type": "title",
"content": "Firman yang telah menjadi manusia"
},
{
"verse": 1,
"type": "text",
"content": "Pada mulanya adalah Firman; Firman itu bersama-sama dengan Allah dan Firman itu adalah Allah."
},
....
]
}
```

### Passage List

Untuk menampilkan passage list perjanjian lama dan baru

#### Example

Expand All @@ -53,7 +88,8 @@ v2 | GET | [https://api-alkitab.herokuapp.com/v2/passage/list](https://api-alkit
"abbreviation": "Kel",
"book_name": "Keluaran",
"total_chapter": 40
}
},
...
]
}
```
Expand Down Expand Up @@ -97,7 +133,8 @@ v1 | GET | [https://api-alkitab.herokuapp.com/v1/passage/Yoh/1](https://api-alki
{
"verse": 2,
"content": "Ia pada mulanya bersama-sama dengan Allah."
}
},
...
]
}
```
Expand All @@ -124,7 +161,8 @@ v1 | GET | [https://api-alkitab.herokuapp.com/v1/passage/Yoh/1](https://api-alki
{
"number": 2,
"text": "Ia pada mulanya bersama-sama dengan Allah."
}
},
...
]
}
}
Expand Down
Binary file modified bin/api-alkitab
Binary file not shown.
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,8 @@ github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn
github.com/spf13/viper v1.7.1 h1:pM5oEahlgWv/WnHXpgbKz7iLIxRf65tye2Ci+XFK5sk=
github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand Down Expand Up @@ -244,13 +241,11 @@ golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201118182958-a01c418693c7 h1:Z991aAXPjz0tLnj74pVXW3eWJ5lHMIBvbRfMq4M2jHA=
golang.org/x/sys v0.0.0-20201118182958-a01c418693c7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.4 h1:0YWbFKbhXG/wIiuHDSKpS0Iy7FSA+u45VtBMfQcFTTc=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand All @@ -272,7 +267,6 @@ golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgw
golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc h1:NCy3Ohtk6Iny5V/reW2Ktypo4zIpWBdRJ1uFMjBxdg8=
golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
Expand Down
34 changes: 30 additions & 4 deletions passage/handler/passage_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ func SetupHandler(r *mux.Router, passageService passage.PassageService) {

v2.HandleFunc("/passage/{passage}/{chapter}", utils.HandleCORS(passageHandler.passageChapterV2)).Methods(http.MethodGet)
v2.HandleFunc("/passage/{passage}/{chapter}/{verse}", utils.HandleCORS(passageHandler.passageChapterVerseV2)).Methods(http.MethodGet)

// MARK: - V3

var v3 = r.PathPrefix("/v3").Subrouter()

v3.HandleFunc("/passage/{passage}/{chapter}", utils.HandleCORS(passageHandler.passageChapterV3)).Methods(http.MethodGet)
}

func (h *PassageHandler) passageChapter(w http.ResponseWriter, r *http.Request) {
Expand All @@ -50,7 +56,6 @@ func (h *PassageHandler) passageChapter(w http.ResponseWriter, r *http.Request)
}

utils.ResponseMessage(w, http.StatusOK, response)
return
}

func (h *PassageHandler) passageChapterVerse(w http.ResponseWriter, r *http.Request) {
Expand All @@ -75,7 +80,6 @@ func (h *PassageHandler) passageChapterVerse(w http.ResponseWriter, r *http.Requ
}

utils.ResponseMessage(w, http.StatusOK, response)
return
}

func (h *PassageHandler) passageChapterV2(w http.ResponseWriter, r *http.Request) {
Expand All @@ -100,7 +104,6 @@ func (h *PassageHandler) passageChapterV2(w http.ResponseWriter, r *http.Request
}

utils.ResponseMessage(w, http.StatusBadRequest, utils.Message(http.StatusBadRequest, utils.ErrorVersionType))
return
}

func (h *PassageHandler) passageChapterVerseV2(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -131,5 +134,28 @@ func (h *PassageHandler) passageChapterVerseV2(w http.ResponseWriter, r *http.Re
}

utils.ResponseMessage(w, http.StatusBadRequest, utils.Message(http.StatusBadRequest, utils.ErrorVersionType))
return
}

func (h *PassageHandler) passageChapterV3(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
ver := r.URL.Query().Get("ver")

if ver == "" || ver == "tb" || ver == "bis" || ver == "net" {
chapter, err := strconv.Atoi(params["chapter"])
if err != nil {
utils.ResponseMessage(w, http.StatusBadRequest, utils.Message(http.StatusBadRequest, utils.ChapterMustValid))
return
}

response, err := h.passageService.PassageChapterV3(params["passage"], chapter, ver)
if err != nil {
utils.ResponseMessage(w, http.StatusInternalServerError, utils.Message(http.StatusInternalServerError, err.Error()))
return
}

utils.ResponseData(w, http.StatusOK, response)
return
}

utils.ResponseMessage(w, http.StatusBadRequest, utils.Message(http.StatusBadRequest, utils.ErrorVersionType))
}
13 changes: 13 additions & 0 deletions passage/models/passage_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,16 @@ type PassageV2 struct {
Chapter int `xml:"book>chapter>chap" json:"chapter"`
Verses []VerseV2 `xml:"book>chapter>verses>verse" json:"verses"`
}

type VerseV3 struct {
Number int `xml:"number" json:"verse"`
Title string `xml:"title" json:"type"`
Text string `xml:"text" json:"content"`
}

type PassageV3 struct {
Title string `xml:"title" json:"title"`
BookID int `xml:"book>book_id" json:"book_number"`
Chapter int `xml:"book>chapter>chap" json:"chapter"`
Verses []VerseV3 `xml:"book>chapter>verses>verse" json:"verses"`
}
2 changes: 2 additions & 0 deletions passage/passage_repository_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ type PassageRepository interface {

PassageChapterV2(passage string, chapter int, ver string) (*models.PassageV2, error)
PassageChapterVerseV2(passage string, chapter int, verse int, ver string) (*models.PassageV2, error)

PassageChapterV3(passage string, chapter int, ver string) (*models.PassageV3, error)
}
2 changes: 2 additions & 0 deletions passage/passage_service_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ type PassageService interface {

PassageChapterV2(passage string, chapter int, ver string) (*models.PassageV2, error)
PassageChapterVerseV2(passage string, chapter int, verse int, ver string) (*models.PassageV2, error)

PassageChapterV3(passage string, chapter int, ver string) (*models.PassageV3, error)
}
58 changes: 58 additions & 0 deletions passage/repository/passage_repository_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,64 @@ func (u *PassageRepositoryImpl) PassageChapterVerseV2(passage string, chapter in
return nil, errors.New(utils.ErrorSomethingWentWrong)
}

// PassageChapterV3 exported to fetch data passage and chapter for v3
func (u *PassageRepositoryImpl) PassageChapterV3(passage string, chapter int, ver string) (*models.PassageV3, error) {
params := fmt.Sprintf("?passage=%s+%v", passage, chapter)
if ver != "" {
params = fmt.Sprintf("?passage=%s+%v&ver=%s", passage, chapter, ver)
}

resp, err := http.Get(u.baseURL + params)
if err != nil {
logrus.Error("[repository][PassageChapterV3][Get]", err)
return nil, errors.New(utils.ErrorCallAPI)
}
defer resp.Body.Close()

if resp.StatusCode == http.StatusOK {
bytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
logrus.Error("[repository][PassageChapterV3][ReadAll]", err)
return nil, errors.New(utils.ErrorReadResponseData)
}

data := &models.PassageV3{}
err = xml.Unmarshal(bytes, data)
if err != nil {
logrus.Error("[repository][PassageChapterV3][Unmarshal]", err)
return nil, errors.New(utils.ErrorDecodeResponse)
}

var response []models.VerseV3
for _, v := range data.Verses {
if len(v.Title) > 0 {
response = append(response, models.VerseV3{
Number: 0,
Title: "title",
Text: v.Title,
})
}
response = append(response, models.VerseV3{
Number: v.Number,
Title: "text",
Text: v.Text,
})
}

resp := models.PassageV3{
Title: data.Title,
BookID: data.BookID,
Chapter: data.Chapter,
Verses: response,
}

return &resp, nil
}

logrus.Error("[repository][PassageChapterV3][statusCode]", resp.StatusCode)
return nil, errors.New(utils.ErrorSomethingWentWrong)
}

// CreatePassageRepository exported to initialize passage repository
func CreatePassageRepository(baseURL string) passage.PassageRepository {
return &PassageRepositoryImpl{baseURL}
Expand Down
10 changes: 10 additions & 0 deletions passage/service/passage_service_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ func (u *PassageService) PassageChapterVerseV2(passage string, chapter int, vers
return response, nil
}

// PassageChapterV3 exported to get data from passage and chapter v3 repository
func (u *PassageService) PassageChapterV3(passage string, chapter int, ver string) (*models.PassageV3, error) {
response, err := u.passageRepository.PassageChapterV3(passage, chapter, ver)
if err != nil {
return nil, err
}

return response, nil
}

// CreatePassageService exported to initialize service passage service
func CreatePassageService(passageRepository passage.PassageRepository) passage.PassageService {
return &PassageService{passageRepository}
Expand Down
14 changes: 7 additions & 7 deletions utils/message_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package utils

// Utils message use to reduce hardcoded text in code
const (
ErrorSomethingWentWrong = "Error something went wrong"
ErrorCallAPI = "Error to call API"
ErrorReadResponseData = "Error read response data"
ErrorDecodeResponse = "Error decode response"
ChapterMustValid = "Chapter only accept a valid number, docs https://api-alkitab.herokuapp.com"
VerseMustValid = "Verse only accept a valid number, docs https://api-alkitab.herokuapp.com"
ErrorVersionType = "Version only accept tb/bis/net value, docs https://api-alkitab.herokuapp.com"
ErrorSomethingWentWrong = "error something went wrong"
ErrorCallAPI = "error to call API"
ErrorReadResponseData = "error read response data"
ErrorDecodeResponse = "error decode response"
ChapterMustValid = "chapter only accept a valid number, docs https://api-alkitab.herokuapp.com"
VerseMustValid = "verse only accept a valid number, docs https://api-alkitab.herokuapp.com"
ErrorVersionType = "version only accept tb/bis/net value, docs https://api-alkitab.herokuapp.com"
)

0 comments on commit b584007

Please sign in to comment.