Skip to content

Commit

Permalink
Fixing the branch so it works again
Browse files Browse the repository at this point in the history
Making sure that the images point to the new
updated image directory. Also, fixed the error
reporting for the image GET endpoint where the
image isn't on the DB.
  • Loading branch information
matheusgomes28 committed Apr 29, 2024
1 parent 9cddc4d commit 364c20b
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 152 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func addCachableHandler(e *gin.Engine, method string, endpoint string, generator
if err != nil {
log.Error().Msgf("could not generate html: %v", err)
// TODO : Need a proper error page
c.JSON(http.StatusInternalServerError, common.ErrorRes("could not render HTML", err))
// c.JSON(http.StatusInternalServerError, common.ErrorRes("could not render HTML", err))
return
}

Expand Down
3 changes: 2 additions & 1 deletion app/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"bytes"
"fmt"
"net/http"

"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -37,7 +38,7 @@ func postHandler(c *gin.Context, app_settings common.AppSettings, database datab
if err != nil || post_binding.Id < 0 {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid post ID"})

return nil, err
return nil, fmt.Errorf("invalid post id")
}

// Get the post with the ID
Expand Down
16 changes: 8 additions & 8 deletions common/app_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ type Shortcode struct {
}

type AppSettings struct {
DatabaseAddress string `toml:"database_address"`
DatabasePort int `toml:"database_port"`
DatabaseUser string `toml:"database_user"`
DatabasePassword string `toml:"database_password"`
DatabaseName string `toml:"database_name"`
WebserverPort int `toml:"webserver_port"`
ImageDirectory string `toml:"image_dir"`
AppNavbar Navbar `toml:"navbar"`
DatabaseAddress string `toml:"database_address"`
DatabasePort int `toml:"database_port"`
DatabaseUser string `toml:"database_user"`
DatabasePassword string `toml:"database_password"`
DatabaseName string `toml:"database_name"`
WebserverPort int `toml:"webserver_port"`
ImageDirectory string `toml:"image_dir"`
AppNavbar Navbar `toml:"navbar"`
Shortcodes []Shortcode `toml:"shortcodes"`
}

Expand Down
2 changes: 1 addition & 1 deletion database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (db SqlDatabase) GetImage(image_id string) (image common.Image, err error)
return common.Image{}, err
}
defer func() {
err = errors.Join(rows.Close())
err = errors.Join(err, rows.Close())
}()

rows.Next()
Expand Down
4 changes: 2 additions & 2 deletions plugins/image_shortcode.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
function HandleShortcode(arguments)
if #arguments == 1 then
local image_src = string.format("/media/%s", arguments[1])
local image_src = string.format("/data/images/%s", arguments[1])
return string.format("![image](%s)", image_src)
elseif #arguments == 2 then
local image_src = string.format("/media/%s", arguments[1])
local image_src = string.format("/data/images/%s", arguments[1])
return string.format("![%s](%s)", arguments[2], image_src)
else
return ""
Expand Down
16 changes: 8 additions & 8 deletions tests/app_tests/app_settings/app_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestCorrectToml(t *testing.T) {
{Name: "Contact", Href: "/contact", Title: "Contacts page"},
},
},
Shortcodes: []Shortcode{},
Shortcodes: []common.Shortcode{},
}
bytes, err := toml.Marshal(expected)
assert.Nil(t, err)
Expand All @@ -61,19 +61,19 @@ func TestCorrectToml(t *testing.T) {
func TestMissingDatabaseAddress(t *testing.T) {

missing_database_address := struct {
DatabaseUser string `toml:"database_user"`
DatabasePassword string `toml:"database_password"`
DatabaseName string `toml:"database_name"`
WebserverPort string `toml:"webserver_port"`
DatabasePort string `toml:"database_port"`
Shortcodes []Shortcode `toml:"shortcodes"`
DatabaseUser string `toml:"database_user"`
DatabasePassword string `toml:"database_password"`
DatabaseName string `toml:"database_name"`
WebserverPort string `toml:"webserver_port"`
DatabasePort string `toml:"database_port"`
Shortcodes []common.Shortcode `toml:"shortcodes"`
}{
DatabaseUser: "test_database_user",
DatabasePassword: "test_database_password",
DatabaseName: "test_database_name",
WebserverPort: "99999",
DatabasePort: "666",
Shortcodes: []Shortcode{},
Shortcodes: []common.Shortcode{},
}

bytes, err := toml.Marshal(missing_database_address)
Expand Down
2 changes: 2 additions & 0 deletions tests/app_tests/endpoint_tests/posts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ func TestPostFailurePostDoesntExist(t *testing.T) {

router.ServeHTTP(responseRecorder, request)

fmt.Printf("Value for the request: %d", responseRecorder.Code)

require.Equal(t, http.StatusNotFound, responseRecorder.Code)
}

Expand Down
94 changes: 0 additions & 94 deletions tests/helpers/helpers.go

This file was deleted.

35 changes: 0 additions & 35 deletions tests/helpers/images.go

This file was deleted.

4 changes: 2 additions & 2 deletions urchin_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
database_address = "localhost"

# User to access datbaase
database_user = "urchin"
database_user = "root"

# Password for the database user
database_password = "urchinpw"
database_password = "root"

# port
database_port = 3306
Expand Down

0 comments on commit 364c20b

Please sign in to comment.