diff --git a/cmd/main.go b/cmd/main.go
index 28fd106..bffbdcf 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -21,6 +21,7 @@ func initGin() {
r.GET("/ping", internal.Ping)
r.GET("/get-all-articles", internal.AuthCheck, internal.GetAllArticles)
+ r.GET("/articles/:id", internal.AuthCheck, internal.GetArticle)
r.POST("/add-article", internal.AuthCheck, internal.AddArticle)
r.DELETE("/delete-article", internal.AuthCheck, internal.DeleteArticle)
diff --git a/internal/articles.go b/internal/articles.go
index 7a0625f..7c92a9d 100644
--- a/internal/articles.go
+++ b/internal/articles.go
@@ -38,6 +38,19 @@ func GetAllArticles(c *gin.Context) {
c.JSON(http.StatusOK, articles)
}
+func GetArticle(c *gin.Context) {
+ articleID := c.Params.ByName("id")
+ articles, err := getDocuments(ARTICLES_LOCATION,
+ bson.D{{Key: "id_name", Value: articleID}})
+ if err != nil {
+ SendErrorMessageToClient(c, err.Error())
+ return
+ }
+ var parsedArticle Article
+ bson.Unmarshal(articles[0], &parsedArticle)
+ c.JSON(http.StatusOK, parsedArticle)
+}
+
func IsArticleIdAlreadyUsed(id string) bool {
documents, _ := getDocuments(ARTICLES_LOCATION, bson.D{})
for i := 0; i < len(documents); i++ {
@@ -96,5 +109,6 @@ func DeleteArticle(c *gin.Context) {
return
}
- SendOkMessageToClient(c, fmt.Sprintf("%d articles were successfully deleted!", deleteCount))
+ SendOkMessageToClient(c,
+ fmt.Sprintf("%d articles were successfully deleted!", deleteCount))
}
diff --git a/web/admin-gui/src/views/Home.vue b/web/admin-gui/src/views/Home.vue
index 4fd8a30..88de10e 100644
--- a/web/admin-gui/src/views/Home.vue
+++ b/web/admin-gui/src/views/Home.vue
@@ -45,6 +45,14 @@ function deleteArticle(articleID: String) {
.then(result => console.log(result))
}
+function getArticle(articleID: String) {
+ fetch(`http://localhost:8080/articles/${articleID}`, {
+ headers: {"Authorization" : `Basic ${btoa(`${username.value}:${password.value}`)}`},
+ })
+ .then(response => response.json())
+ .then(result => console.log(result))
+}
+
function auth(type: string, username: string, password: string) {
fetch(`http://localhost:8080/${type}`, {
method: "POST",
@@ -63,8 +71,9 @@ function auth(type: string, username: string, password: string) {
-
-
+
+
+