Discover books, shows, and movies at your level. Track your progress by filling your Shelf with what you find, and share with other language learners. *No dusting required. shlf.space
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: update yes24 id to be generic

Signed-off-by: brookjeynes <me@brookjeynes.dev>

authored by

brookjeynes and committed by tangled.org 940e879c 8c18acb9

+63 -11
+11 -5
internal/server/shelf.go
··· 21 21 // TODO: test data 22 22 catalog := []types.Book{ 23 23 { 24 - Yes24Id: "124807552", 24 + PlatformID: types.PlatformYes24, 25 + ID: "124807552", 25 26 Title: "메멘과 모리", 26 27 Author: "요시타케 신스케", 27 28 Description: "'사람은 무엇을 위해 살아가는가?', '살아가는 의미와 목적이 필요한가?'에 대한 정답 없는 고민으로 괴로운 당신에게 요시타케 신스케가 전하는 세 가지 이야기.", 28 29 }, 29 30 { 30 - Yes24Id: "58552371", 31 + PlatformID: types.PlatformYes24, 32 + ID: "58552371", 31 33 Title: "세계를 건너 너에게 갈게", 32 34 Author: "이꽃님", 33 35 Description: "'나에게. 아빠가 쓰라고 해서 쓰는 거야.' 첫 문장으로 시작한 편지가 '세계를 건너 너에게 갈게.'라는 마지막 문장에 닿기까지, 두 사람의 진심이 하나의 진실을 향해 가는 동안 쌓아올린 감동은 많은 독자들에게 울음을 울게 만들었다.", 34 36 }, 35 37 } 38 + catalogView := make([]types.BookView, 2) 39 + for _, book := range catalog { 40 + catalogView = append(catalogView, book.View()) 41 + } 36 42 37 43 // TODO: test data 38 44 items := []types.ShelfItem{ 39 45 { 40 46 Type: types.ShelfItemBook, 41 - Book: &catalog[0], 47 + Book: &catalogView[0], 42 48 }, 43 49 { 44 50 Type: types.ShelfItemSpacer, ··· 48 54 }, 49 55 { 50 56 Type: types.ShelfItemBook, 51 - Book: &catalog[1], 57 + Book: &catalogView[1], 52 58 }, 53 59 { 54 60 Type: types.ShelfItemSpacer, ··· 58 64 shelf.ShelfPage(shelf.ShelfPageParams{ 59 65 User: user, 60 66 ProfileHandle: handle, 61 - Catalog: catalog, 67 + Catalog: catalogView, 62 68 Items: items, 63 69 }).Render(r.Context(), w) 64 70 }
+46 -1
internal/types/book.go
··· 1 1 package types 2 2 3 + import ( 4 + "fmt" 5 + ) 6 + 7 + const ( 8 + PlatformYes24 string = "yes24" 9 + ) 10 + 3 11 type Book struct { 4 - Yes24Id string `json:"yes24Id"` 12 + ID string `json:"id"` 13 + PlatformID string `json:"platformId"` 14 + Title string `json:"title"` 15 + Author string `json:"author"` 16 + Description string `json:"description"` 17 + } 18 + 19 + func (book Book) SpineImageURL() string { 20 + switch book.PlatformID { 21 + case PlatformYes24: 22 + return fmt.Sprintf("https://image.yes24.com/goods/%s/SIDE/XL", book.ID) 23 + } 24 + return "" 25 + } 26 + 27 + func (book Book) CoverImageURL() string { 28 + switch book.PlatformID { 29 + case PlatformYes24: 30 + return fmt.Sprintf("https://image.yes24.com/goods/%s/XL", book.ID) 31 + } 32 + return "" 33 + } 34 + 35 + // Used when the book struct is needed to be serialized for JS / templ 36 + // interactions. 37 + type BookView struct { 5 38 Title string `json:"title"` 6 39 Author string `json:"author"` 7 40 Description string `json:"description"` 41 + SpineURL string `json:"spineUrl"` 42 + CoverURL string `json:"coverUrl"` 43 + } 44 + 45 + func (book Book) View() BookView { 46 + return BookView{ 47 + Title: book.Title, 48 + Author: book.Author, 49 + Description: book.Description, 50 + SpineURL: book.SpineImageURL(), 51 + CoverURL: book.CoverImageURL(), 52 + } 8 53 }
+1 -1
internal/types/shelf.go
··· 9 9 10 10 type ShelfItem struct { 11 11 Type ShelfItemType `json:"type"` 12 - Book *Book `json:"book,omitempty"` 12 + Book *BookView `json:"book,omitempty"` 13 13 }
+1 -1
internal/views/shelf/shelf.go
··· 8 8 type ShelfPageParams struct { 9 9 User *oauth.AccountUser 10 10 ProfileHandle string 11 - Catalog []types.Book 11 + Catalog []types.BookView 12 12 Items []types.ShelfItem 13 13 }
+2 -1
internal/views/shelf/shelf.js
··· 1 1 /** 2 2 * @typedef {object} Book 3 - * @property {string} yes24Id 4 3 * @property {string} title 5 4 * @property {string} author 6 5 * @property {string} description 6 + * @property {string} spineUrl 7 + * @property {string} coverUrl 7 8 */ 8 9 9 10 /**
+2 -2
internal/views/shelf/shelf.templ
··· 45 45 @click.stop="items.splice(slot.index, 1)" 46 46 > 47 47 <img 48 - :src="`https://image.yes24.com/goods/${slot.item.book.yes24Id}/SIDE/XL`" 48 + :src="slot.item.book.spineUrl" 49 49 :alt="slot.item.book.title" 50 50 draggable="false" 51 51 /> ··· 60 60 <p x-text="slot.item.book.description"></p> 61 61 </div> 62 62 <img 63 - :src="`https://image.yes24.com/goods/${slot.item.book.yes24Id}/XL`" 63 + :src="slot.item.book.coverUrl" 64 64 :alt="slot.item.book.title" 65 65 draggable="false" 66 66 />