Skip to content

Commit

Permalink
Remove giphy adapter and all usages
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiefdhurst committed Jan 8, 2025
1 parent 18cf7da commit e98836c
Show file tree
Hide file tree
Showing 27 changed files with 28 additions and 454 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ env:
GOPATH: /home/runner/work/journal/journal/go
J_ARTICLES_PER_PAGE: ''
J_DB_PATH: ''
J_GIPHY_API_KEY: ''
J_PORT: ''
J_TITLE: ''

Expand Down
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-instal

ENV GOPATH "/go"
ENV J_ARTICLES_PER_PAGE ""
ENV J_CREATE ""
ENV J_DB_PATH ""
ENV J_GIPHY_API_KEY ""
ENV J_DESCRIPTION ""
ENV J_EDIT ""
ENV J_GA_CODE ""
ENV J_PORT ""
ENV J_THEME ""
ENV J_TITLE ""

VOLUME /go/data
Expand Down
6 changes: 5 additions & 1 deletion Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ FROM golang:1.22-bookworm
LABEL org.opencontainers.image.source=https://github.com/jamiefdhurst/journal

ENV J_ARTICLES_PER_PAGE ""
ENV J_CREATE ""
ENV J_DB_PATH ""
ENV J_GIPHY_API_KEY ""
ENV J_DESCRIPTION ""
ENV J_EDIT ""
ENV J_GA_CODE ""
ENV J_PORT ""
ENV J_THEME ""
ENV J_TITLE ""

WORKDIR /go/src/github.com/jamiefdhurst/journal
Expand Down
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,20 @@ _Please note: you will need Docker installed on your local machine._
docker run --rm -v ./data:/go/data -p 3000:3000 -it journal:latest
```

## Environment Variables
## Configuration through Environment Variables

The application uses environment variables to configure all aspects.

* `J_ARTICLES_PER_PAGE` - Articles to display per page, default `20`
* `J_CREATE` - Set to `0` to disable article creation
* `J_DB_PATH` - Path to SQLite DB - default is `$GOPATH/data/journal.db`
* `J_DESCRIPTION` - Set the HTML description of the Journal
* `J_EDIT` - Set to `0` to disable article modification
* `J_GA_CODE` - Google Analytics tag value, starts with `UA-`, or ignore to disable Google Analytics
* `J_GIPHY_API_KEY` - Set to a GIPHY API key to use, or ignore to disable GIPHY
* `J_PORT` - Port to expose over HTTP, default is `3000`
* `J_THEME` - Theme to use from within the _web/themes_ folder, defaults to `default`
* `J_TITLE` - Set the title of the Journal

To use the API key within your Docker setup, include it as follows:

```bash
docker run --rm -e J_GIPHY_API_KEY=... -v ./data:/go/data -p 3000:3000 -it journal:latest
```

## Layout

The project layout follows the standard set out in the following document:
Expand Down
4 changes: 2 additions & 2 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Contains all current post reources in reverse date order.
"slug": "example-post",
"title": "An Example Post",
"date": "2018-05-18T12:53:22Z",
"content": "<p>TEST</p><p>:gif:id:cE1qRt8nl6Neo:</p>"
"content": "<p>TEST</p>"
}
]
```
Expand All @@ -66,7 +66,7 @@ Contains the single post.
"slug": "example-post",
"title": "An Example Post",
"date": "2018-05-18T12:53:22Z",
"content": "<p>TEST</p><p>:gif:id:cE1qRt8nl6Neo:</p>"
"content": "<p>TEST</p>"
}
```

Expand Down
6 changes: 0 additions & 6 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,10 @@ type Database interface {
Query(sql string, args ...interface{}) (rows.Rows, error)
}

// GiphyAdapter Interface for API
type GiphyAdapter interface {
SearchForID(s string) (string, error)
}

// Container Define the main container for the application
type Container struct {
Configuration Configuration
Db Database
Giphy GiphyAdapter
Version string
}

Expand Down
2 changes: 1 addition & 1 deletion internal/app/controller/apiv1/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (c *Create) Run(response http.ResponseWriter, request *http.Request) {
response.WriteHeader(http.StatusBadRequest)
} else {
journal := model.Journal{ID: 0, Slug: model.Slugify(journalRequest.Title), Title: journalRequest.Title, Date: journalRequest.Date, Content: journalRequest.Content}
js := model.Journals{Container: container, Gs: model.GiphyAdapter(container)}
js := model.Journals{Container: container}
journal = js.Save(journal)
response.WriteHeader(http.StatusCreated)
encoder := json.NewEncoder(response)
Expand Down
2 changes: 1 addition & 1 deletion internal/app/controller/apiv1/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type List struct {
// Run List action
func (c *List) Run(response http.ResponseWriter, request *http.Request) {

js := model.Journals{Container: c.Super.Container.(*app.Container), Gs: model.GiphyAdapter(c.Super.Container.(*app.Container))}
js := model.Journals{Container: c.Super.Container.(*app.Container)}
journals := js.FetchAll()
response.Header().Add("Content-Type", "application/json")
encoder := json.NewEncoder(response)
Expand Down
2 changes: 1 addition & 1 deletion internal/app/controller/apiv1/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Single struct {
// Run Single action
func (c *Single) Run(response http.ResponseWriter, request *http.Request) {

js := model.Journals{Container: c.Super.Container.(*app.Container), Gs: model.GiphyAdapter(c.Super.Container.(*app.Container))}
js := model.Journals{Container: c.Super.Container.(*app.Container)}
journal := js.FindBySlug(c.Params[1])

response.Header().Add("Content-Type", "application/json")
Expand Down
2 changes: 1 addition & 1 deletion internal/app/controller/apiv1/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (c *Update) Run(response http.ResponseWriter, request *http.Request) {
return
}

js := model.Journals{Container: container, Gs: model.GiphyAdapter(container)}
js := model.Journals{Container: container}
journal := js.FindBySlug(c.Params[1])

response.Header().Add("Content-Type", "application/json")
Expand Down
2 changes: 1 addition & 1 deletion internal/app/controller/web/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (c *Edit) Run(response http.ResponseWriter, request *http.Request) {
return
}

js := model.Journals{Container: c.Super.Container.(*app.Container), Gs: model.GiphyAdapter(c.Super.Container.(*app.Container))}
js := model.Journals{Container: c.Super.Container.(*app.Container)}
c.Journal = js.FindBySlug(c.Params[1])

if c.Journal.ID == 0 {
Expand Down
2 changes: 1 addition & 1 deletion internal/app/controller/web/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Index struct {
func (c *Index) Run(response http.ResponseWriter, request *http.Request) {

container := c.Super.Container.(*app.Container)
js := model.Journals{Container: container, Gs: model.GiphyAdapter(container)}
js := model.Journals{Container: container}

paginationQuery := database.PaginationQuery{Page: 1, ResultsPerPage: container.Configuration.ArticlesPerPage}
query := request.URL.Query()
Expand Down
2 changes: 1 addition & 1 deletion internal/app/controller/web/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (c *New) Run(response http.ResponseWriter, request *http.Request) {
return
}

js := model.Journals{Container: container, Gs: model.GiphyAdapter(container)}
js := model.Journals{Container: container}
journal := model.Journal{ID: 0, Slug: model.Slugify(request.FormValue("title")), Title: request.FormValue("title"), Date: request.FormValue("date"), Content: request.FormValue("content")}
js.Save(journal)

Expand Down
2 changes: 1 addition & 1 deletion internal/app/controller/web/sitemap.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Sitemap struct {
func (c *Sitemap) Run(response http.ResponseWriter, request *http.Request) {

container := c.Super.Container.(*app.Container)
js := model.Journals{Container: container, Gs: model.GiphyAdapter(container)}
js := model.Journals{Container: container}

c.Journals = js.FetchAll()

Expand Down
4 changes: 1 addition & 3 deletions internal/app/controller/web/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ type View struct {
// Run View action
func (c *View) Run(response http.ResponseWriter, request *http.Request) {

js := model.Journals{Container: c.Super.Container.(*app.Container), Gs: model.GiphyAdapter(c.Super.Container.(*app.Container))}
js := model.Journals{Container: c.Super.Container.(*app.Container)}
c.Journal = js.FindBySlug(c.Params[1])

if c.Journal.ID == 0 {
RunBadRequest(response, request, c.Super.Container)
} else {
c.Next = js.FindNext(c.Journal.ID)
c.Prev = js.FindPrev(c.Journal.ID)
gs := model.Giphys{}
c.Journal.Content = gs.ConvertIDsToIframes(c.Journal.Content)
template, _ := template.ParseFiles(
"./web/templates/_layout/default.html.tmpl",
"./web/templates/view.html.tmpl")
Expand Down
98 changes: 0 additions & 98 deletions internal/app/model/giphy.go

This file was deleted.

67 changes: 0 additions & 67 deletions internal/app/model/giphy_test.go

This file was deleted.

Loading

0 comments on commit e98836c

Please sign in to comment.