Fixing more stuff

This commit is contained in:
2022-02-06 18:27:30 +01:00
parent 8bc01e0984
commit e582a75d9e
13 changed files with 56 additions and 38 deletions

View File

@@ -158,7 +158,7 @@ func articlePost(w http.ResponseWriter, r *http.Request) {
} else {
articleSummary.Tags = []string{}
}
articleSummary.Link = path.Join("/", config.SubPath, "article", url.PathEscape(articleSummary.Link))
articleSummary.Link = path.Join(config.SubPath, "article", url.PathEscape(articleSummary.Link))
w.WriteHeader(http.StatusCreated)
json.NewEncoder(w).Encode(articleSummary)
@@ -272,7 +272,7 @@ func articlePatch(w http.ResponseWriter, r *http.Request) {
} else {
articleSummary.Tags = []string{}
}
articleSummary.Link = path.Join("/", config.SubPath, "article", url.PathEscape(articleSummary.Link))
articleSummary.Link = path.Join(config.SubPath, "article", url.PathEscape(articleSummary.Link))
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(articleSummary)

View File

@@ -134,7 +134,7 @@ func TestArticlePost(t *testing.T) {
},
},
Tags: []string{},
Link: "/article/testooo",
Link: "article/testooo",
},
Code: http.StatusCreated,
AfterExec: func(information *testInformation) {
@@ -229,7 +229,7 @@ func TestArticlePatch(t *testing.T) {
},
Created: created,
Tags: []string{},
Link: "/article/test-article",
Link: "article/test-article",
},
AfterExec: func(information *testInformation) {
var modified int64

View File

@@ -19,12 +19,6 @@ var assetsPayload struct {
}
func Assets(w http.ResponseWriter, r *http.Request) {
_, ok := authorizedSession(r)
if !ok {
w.WriteHeader(http.StatusUnauthorized)
return
}
switch r.Method {
case http.MethodGet:
assetsGet(w, r)
@@ -63,7 +57,7 @@ func assetsGet(w http.ResponseWriter, r *http.Request) {
request.Find(&assets)
for _, asset := range assets {
asset.Link = path.Join("/", config.SubPath, "assets", asset.Link)
asset.Link = path.Join(config.SubPath, "assets", asset.Link)
}
w.WriteHeader(http.StatusOK)
@@ -116,7 +110,7 @@ func assetsPost(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(schema.Asset{
Id: tmpDatabaseSchema.Id,
Name: tmpDatabaseSchema.Name,
Link: path.Join("/", config.SubPath, "assets", tmpDatabaseSchema.Link),
Link: path.Join(config.SubPath, "assets", tmpDatabaseSchema.Link),
})
}
}

View File

@@ -20,12 +20,12 @@ func TestAssetsGet(t *testing.T) {
{
"name": "linux",
"data": "this should be an image of tux :3",
"link": "/assets/linux",
"link": "assets/linux",
},
{
"name": "get test",
"data": "",
"link": "/assets/get-test",
"link": "assets/get-test",
},
})
@@ -47,7 +47,7 @@ func TestAssetsGet(t *testing.T) {
{
Id: 1,
Name: "linux",
Link: "/assets/linux",
Link: "assets/linux",
},
},
Code: http.StatusOK,
@@ -64,7 +64,7 @@ func TestAssetsGet(t *testing.T) {
{
Id: 1,
Name: "linux",
Link: "/assets/linux",
Link: "assets/linux",
},
},
Code: http.StatusOK,
@@ -78,12 +78,12 @@ func TestAssetsGet(t *testing.T) {
{
Id: 1,
Name: "linux",
Link: "/assets/linux",
Link: "assets/linux",
},
{
Id: 2,
Name: "get test",
Link: "/assets/get-test",
Link: "assets/get-test",
},
},
Code: http.StatusOK,
@@ -124,7 +124,7 @@ func TestAssetsPost(t *testing.T) {
ResultBody: schema.Asset{
Id: 1,
Name: "test",
Link: "/assets/test",
Link: "assets/test",
},
Code: http.StatusCreated,
},
@@ -150,7 +150,7 @@ func TestAssetsDelete(t *testing.T) {
database.GetDB().Table("assets").Create(map[string]interface{}{
"name": "example",
"data": "just a normal string",
"link": "/assets/example",
"link": "assets/example",
})
server := httptest.NewServer(http.HandlerFunc(assetsDelete))

View File

@@ -35,7 +35,7 @@ func Recent(w http.ResponseWriter, r *http.Request) {
database.GetDB().Table("author").Where("id IN (?)", database.GetDB().Table("article_author").Select("author_id").Where("article_id = ?", summary.Id)).Find(&summary.Authors)
summary.Tags = []string{}
database.GetDB().Table("article_tag").Select("tag").Where("article_id = ?", summary.Id).Find(&summary.Tags)
summary.Link = path.Join("/", config.SubPath, "article", summary.Link)
summary.Link = path.Join(config.SubPath, "article", summary.Link)
articleSummaries[i] = summary
}

View File

@@ -31,7 +31,7 @@ func TestRecent(t *testing.T) {
Tags: []string{},
Created: time.Unix(0, 0).Unix(),
Modified: time.Now().Unix(),
Link: "/article/test",
Link: "article/test",
},
{
Id: 2,
@@ -40,7 +40,7 @@ func TestRecent(t *testing.T) {
Authors: authors,
Tags: []string{},
Created: time.Now().Unix(),
Link: "/article/recent",
Link: "article/recent",
},
}

View File

@@ -72,7 +72,7 @@ func Search(w http.ResponseWriter, r *http.Request) {
database.GetDB().Table("author").Where("id IN (?)", database.GetDB().Table("article_author").Select("author_id").Where("article_id = ?", summary.Id)).Find(&summary.Authors)
summary.Tags = []string{}
database.GetDB().Table("article_tag").Select("tag").Where("article_id = ?", summary.Id).Find(&summary.Tags)
summary.Link = path.Join("/", config.SubPath, "article", summary.Link)
summary.Link = path.Join(config.SubPath, "article", summary.Link)
articleSummaries[i] = summary
}

View File

@@ -95,7 +95,7 @@ func TestSearch(t *testing.T) {
Tags: []string{
"example",
},
Link: "/article/first-article",
Link: "article/first-article",
},
},
Code: http.StatusOK,
@@ -121,7 +121,7 @@ func TestSearch(t *testing.T) {
Created: now.Unix(),
Modified: now.Add(24 * time.Hour).Unix(),
Tags: []string{},
Link: "/article/test",
Link: "article/test",
},
{
Id: 3,
@@ -135,7 +135,7 @@ func TestSearch(t *testing.T) {
Created: now.Unix(),
Modified: now.Add(12 * time.Hour).Unix(),
Tags: []string{},
Link: "/article/owo",
Link: "article/owo",
},
},
Code: http.StatusOK,
@@ -158,7 +158,7 @@ func TestSearch(t *testing.T) {
Created: now.Unix(),
Modified: now.Add(12 * time.Hour).Unix(),
Tags: []string{},
Link: "/article/owo",
Link: "article/owo",
},
},
Code: http.StatusOK,
@@ -182,7 +182,7 @@ func TestSearch(t *testing.T) {
Tags: []string{
"example",
},
Link: "/article/first-article",
Link: "article/first-article",
},
},
Code: http.StatusOK,
@@ -206,7 +206,7 @@ func TestSearch(t *testing.T) {
Tags: []string{
"example",
},
Link: "/article/first-article",
Link: "article/first-article",
},
{
Id: 2,
@@ -222,7 +222,7 @@ func TestSearch(t *testing.T) {
Created: now.Unix(),
Modified: now.Add(24 * time.Hour).Unix(),
Tags: []string{},
Link: "/article/test",
Link: "article/test",
},
},
Code: http.StatusOK,

View File

@@ -23,7 +23,7 @@ func TestTags(t *testing.T) {
"title": "Upload test",
"summary": "An example article to test the upload api endpoint",
"created": time.Now().Unix(),
"link": "/article/upload-test",
"link": "article/upload-test",
"markdown": "Oh god i have to test all this, what am i doing with my life",
"html": "<p>Oh god i have to test all this, what am i doing with my life<p>",
},