From db702a0bb2f1ce6fec4b84ceabe2bab98c9fd60a Mon Sep 17 00:00:00 2001 From: Elias Kohout Date: Sat, 28 Dec 2024 01:40:30 +0100 Subject: [PATCH] minor formatting --- internal/data/DefaultRepository.go | 5 +---- internal/model/article.go | 8 +++++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/internal/data/DefaultRepository.go b/internal/data/DefaultRepository.go index 208607d..1babe10 100644 --- a/internal/data/DefaultRepository.go +++ b/internal/data/DefaultRepository.go @@ -7,8 +7,7 @@ import ( ) -// TODO docstring -// Default implementation of IRepository +// Default implementation of IRepository using an IDatastore. type DefaultRepository[T IIdentifiable] struct { ds IDatastore prefix string @@ -23,7 +22,6 @@ func NewDefaultRepository[T IIdentifiable](ds IDatastore, prefix string) *Defaul // error if there already exists an entry with the same id, the json encoding // fails or the connection to the IDatastore fails. func (repo *DefaultRepository[T]) Create(t T) error { - key := repo.prefix + ":" + strconv.FormatUint(uint64(t.Id()), 10) exists, err := repo.ds.KeyExists(key) if err != nil { return err } @@ -42,7 +40,6 @@ func (repo *DefaultRepository[T]) Create(t T) error { // t. Trows an error if the json encoding fails or the connection to the // IDatastore fails. func (repo *DefaultRepository[T]) Update(t T) error { - key := repo.prefix + ":" + strconv.FormatUint(uint64(t.Id()), 10) exists, err := repo.ds.KeyExists(key) if err != nil { return err } diff --git a/internal/model/article.go b/internal/model/article.go index d2fb790..eea532f 100644 --- a/internal/model/article.go +++ b/internal/model/article.go @@ -6,6 +6,7 @@ import ( "encoding/hex" ) +// TODO docstring type Article struct { Identifier uint SourceUrl string @@ -16,17 +17,18 @@ type Article struct { } +// Generates a hash based on the source url of the article. Can be used to +// identify the article. func (article *Article) Hash() string { - /* Generates a hash based on the source url of the article. Can be used to - * identify the article. */ hash := sha256.Sum256([]byte(article.SourceUrl)) return hex.EncodeToString(hash[:]) } -// --- implementation of the IIdentifiable interface --- +// --- implement IIdentifiable interface --- +// Using the Identifier attribute as the Id. func (article *Article) Id() uint { return article.Identifier }