-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
197 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package home | ||
|
||
import ( | ||
"github.com/svera/coreander/v4/internal/index" | ||
"github.com/svera/coreander/v4/internal/result" | ||
) | ||
|
||
const highlightsAmount = 6 | ||
|
||
type Sender interface { | ||
SendDocument(address string, libraryPath string, fileName string) error | ||
From() string | ||
} | ||
|
||
// IdxReaderWriter defines a set of reading and writing operations over an index | ||
type IdxReaderWriter interface { | ||
Documents(IDs []string) (map[string]index.Document, error) | ||
Count() (uint64, error) | ||
} | ||
|
||
type highlightsRepository interface { | ||
Highlights(userID int, page int, resultsPerPage int) (result.Paginated[[]string], error) | ||
} | ||
|
||
type Config struct { | ||
LibraryPath string | ||
CoverMaxWidth int | ||
} | ||
|
||
type Controller struct { | ||
hlRepository highlightsRepository | ||
idx IdxReaderWriter | ||
sender Sender | ||
config Config | ||
} | ||
|
||
func NewController(hlRepository highlightsRepository, sender Sender, idx IdxReaderWriter, cfg Config) *Controller { | ||
return &Controller{ | ||
hlRepository: hlRepository, | ||
idx: idx, | ||
sender: sender, | ||
config: cfg, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package home | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
"github.com/svera/coreander/v4/internal/index" | ||
"github.com/svera/coreander/v4/internal/webserver/infrastructure" | ||
"github.com/svera/coreander/v4/internal/webserver/model" | ||
) | ||
|
||
func (d *Controller) Index(c *fiber.Ctx) error { | ||
emailSendingConfigured := true | ||
if _, ok := d.sender.(*infrastructure.NoEmail); ok { | ||
emailSendingConfigured = false | ||
} | ||
|
||
var session model.Session | ||
if val, ok := c.Locals("Session").(model.Session); ok { | ||
session = val | ||
} | ||
|
||
count, err := d.idx.Count() | ||
if err != nil { | ||
log.Println(err) | ||
return fiber.ErrInternalServerError | ||
} | ||
|
||
docsSortedByHighlightedDate, err := d.hlRepository.Highlights(int(session.ID), 0, highlightsAmount) | ||
if err != nil { | ||
log.Println(err) | ||
return fiber.ErrInternalServerError | ||
} | ||
|
||
docs, err := d.idx.Documents(docsSortedByHighlightedDate.Hits()) | ||
if err != nil { | ||
log.Println(err) | ||
return fiber.ErrInternalServerError | ||
} | ||
|
||
highlights := make([]index.Document, 0, len(docs)) | ||
for _, path := range docsSortedByHighlightedDate.Hits() { | ||
if _, ok := docs[path]; !ok { | ||
continue | ||
} | ||
doc := docs[path] | ||
doc.Highlighted = true | ||
highlights = append(highlights, doc) | ||
} | ||
|
||
return c.Render("index", fiber.Map{ | ||
"Count": count, | ||
"Title": "Coreander", | ||
"Highlights": highlights, | ||
"EmailSendingConfigured": emailSendingConfigured, | ||
"EmailFrom": d.sender.From(), | ||
"HomeNavbar": true, | ||
}, "layout") | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.