-
Notifications
You must be signed in to change notification settings - Fork 0
/
currentreads.go
49 lines (41 loc) · 998 Bytes
/
currentreads.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"strconv"
"github.com/google/uuid"
)
type CurrentReads struct {
BookIDs []uuid.UUID
}
func (cr *CurrentReads) String(preceding string) string {
s := ""
if preceding == "DIGITS" {
for i, b := range cr.BookIDs {
b_data, err := AllBooksLibrary.GetBookByID(b)
if err == nil {
s += strconv.Itoa(i+1) + ". " + b_data.Name + ", " + b_data.Author + "\n"
}
}
return s
}
for _, b := range cr.BookIDs {
b_data, err := AllBooksLibrary.GetBookByID(b)
if err == nil {
s += preceding + " " + b_data.Name + ", " + b_data.Author + "\n"
}
}
return s
}
func (cr *CurrentReads) ReplaceBook(index int, book uuid.UUID) {
cr.BookIDs[index] = book
}
func (cr *CurrentReads) ContainsBook(bookID uuid.UUID) bool {
for _, b := range cr.BookIDs {
if b == bookID {
return true
}
}
return false
}
func (cr *CurrentReads) AddBookToLibrary(bookID uuid.UUID) {
cr.BookIDs = append(cr.BookIDs, bookID)
}