Skip to content

Commit

Permalink
backend: removing is_literature_card
Browse files Browse the repository at this point in the history
  • Loading branch information
NickSavage committed Oct 5, 2024
1 parent 7281298 commit 3d3fde1
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 131 deletions.
12 changes: 6 additions & 6 deletions go-backend/handlers/cards.go
Original file line number Diff line number Diff line change
Expand Up @@ -847,11 +847,11 @@ func (s *Handler) UpdateCard(userID int, cardPK int, params models.EditCardParam
}

query := `
UPDATE cards SET title = $1, body = $2, link = $3, parent_id = $4, is_literature_card = $5, updated_at = NOW(), card_id = $6
UPDATE cards SET title = $1, body = $2, link = $3, parent_id = $4, updated_at = NOW(), card_id = $5
WHERE
id = $7
id = $6
`
_, err = s.DB.Exec(query, params.Title, params.Body, params.Link, parent_id, params.IsLiteratureCard, params.CardID, cardPK)
_, err = s.DB.Exec(query, params.Title, params.Body, params.Link, parent_id, params.CardID, cardPK)
if err != nil {
log.Printf("updatecard err %v", err)
return models.Card{}, err
Expand Down Expand Up @@ -880,12 +880,12 @@ func (s *Handler) CreateCard(userID int, params models.EditCardParams) (models.C
parent, err := s.QueryPartialCard(userID, getParentIdAlternating(params.CardID))
query := `
INSERT INTO cards
(title, body, link, user_id, card_id, parent_id, is_literature_card, created_at, updated_at)
VALUES ($1, $2, $3, $4, $5, $6, $7, NOW(), NOW())
(title, body, link, user_id, card_id, parent_id, created_at, updated_at)
VALUES ($1, $2, $3, $4, $5, $6, NOW(), NOW())
RETURNING id;
`
var id int
err = s.DB.QueryRow(query, params.Title, params.Body, params.Link, userID, params.CardID, parent.ID, params.IsLiteratureCard).Scan(&id)
err = s.DB.QueryRow(query, params.Title, params.Body, params.Link, userID, params.CardID, parent.ID).Scan(&id)
if err != nil {
log.Printf("updatecard err %v", err)
return models.Card{}, err
Expand Down
83 changes: 38 additions & 45 deletions go-backend/models/card.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,23 @@ import (
)

type Card struct {
ID int `json:"id"`
CardID string `json:"card_id"`
UserID int `json:"user_id"`
Title string `json:"title"`
Body string `json:"body"`
Link string `json:"link"`
IsDeleted bool `json:"is_deleted"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ParentID int `json:"parent_id"`
Parent PartialCard `json:"parent"`
Files []File `json:"files"`
Children []PartialCard `json:"children"`
References []PartialCard `json:"references"`
Keywords []Keyword `json:"keywords"`
IsLiteratureCard bool `json:"is_literature_card"`
Tags []Tag `json:"tags"`
IsFlashcard bool `json:"is_flashcard"`
Embedding pgvector.Vector
ID int `json:"id"`
CardID string `json:"card_id"`
UserID int `json:"user_id"`
Title string `json:"title"`
Body string `json:"body"`
Link string `json:"link"`
IsDeleted bool `json:"is_deleted"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ParentID int `json:"parent_id"`
Parent PartialCard `json:"parent"`
Files []File `json:"files"`
Children []PartialCard `json:"children"`
References []PartialCard `json:"references"`
Keywords []Keyword `json:"keywords"`
Tags []Tag `json:"tags"`
Embedding pgvector.Vector
}

func ScanCards(rows *sql.Rows) ([]Card, error) {
Expand Down Expand Up @@ -79,16 +77,14 @@ func ScanPartialCards(rows *sql.Rows) ([]PartialCard, error) {
}

type PartialCard struct {
ID int `json:"id"`
CardID string `json:"card_id"`
UserID int `json:"user_id"`
Title string `json:"title"`
ParentID int `json:"parent_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
IsLiteratureCard bool `json:"is_literature_card"`
Tags []Tag `json:"tags"`
IsFlashcard bool `json:"is_flashcard"`
ID int `json:"id"`
CardID string `json:"card_id"`
UserID int `json:"user_id"`
Title string `json:"title"`
ParentID int `json:"parent_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Tags []Tag `json:"tags"`
}

type Flashcard struct {
Expand All @@ -110,26 +106,23 @@ type Flashcard struct {

func ConvertCardToPartialCard(input Card) PartialCard {
return PartialCard{
ID: input.ID,
CardID: input.CardID,
UserID: input.UserID,
Title: input.Title,
ParentID: input.ParentID,
CreatedAt: input.CreatedAt,
UpdatedAt: input.UpdatedAt,
IsLiteratureCard: input.IsLiteratureCard,
Tags: input.Tags,
IsFlashcard: input.IsFlashcard,
ID: input.ID,
CardID: input.CardID,
UserID: input.UserID,
Title: input.Title,
ParentID: input.ParentID,
CreatedAt: input.CreatedAt,
UpdatedAt: input.UpdatedAt,
Tags: input.Tags,
}
}

type EditCardParams struct {
CardID string `json:"card_id"`
Title string `json:"title"`
Body string `json:"body"`
Link string `json:"link"`
IsLiteratureCard bool `json:"is_literature_card"`
IsFlashcard bool `json:"is_flashcard"`
CardID string `json:"card_id"`
Title string `json:"title"`
Body string `json:"body"`
Link string `json:"link"`
IsFlashcard bool `json:"is_flashcard"`
}

type NextIDParams struct {
Expand Down
109 changes: 47 additions & 62 deletions go-backend/tests/conftest.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ func importTestData(s *server.Server) error {

for _, card := range cards {
_, err := tx.Exec(
"INSERT INTO cards (card_id, user_id, title, body, link, created_at, updated_at, parent_id, is_literature_card) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
card.CardID, card.UserID, card.Title, card.Body, card.Link, card.CreatedAt, card.UpdatedAt, card.ParentID, card.IsLiteratureCard,
"INSERT INTO cards (card_id, user_id, title, body, link, created_at, updated_at, parent_id) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)",
card.CardID, card.UserID, card.Title, card.Body, card.Link, card.CreatedAt, card.UpdatedAt, card.ParentID,
)
if err != nil {
log.Printf("something went wrong inserting rows: %v", err)
Expand Down Expand Up @@ -265,17 +265,15 @@ func generateData() map[string]interface{} {
cards := []models.Card{}
for i := 1; i <= 20; i++ {
card := models.Card{
ID: i,
CardID: strconv.Itoa(i),
UserID: 1,
Title: randomString(20),
Body: randomString(100),
Link: fmt.Sprintf("https://%s.com", randomString(10)),
CreatedAt: randomDate(time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)),
UpdatedAt: randomDate(time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC), time.Date(2024, 12, 31, 0, 0, 0, 0, time.UTC)),
ParentID: i,
IsLiteratureCard: false,
IsFlashcard: false,
ID: i,
CardID: strconv.Itoa(i),
UserID: 1,
Title: randomString(20),
Body: randomString(100),
Link: fmt.Sprintf("https://%s.com", randomString(10)),
CreatedAt: randomDate(time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)),
UpdatedAt: randomDate(time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC), time.Date(2024, 12, 31, 0, 0, 0, 0, time.UTC)),
ParentID: i,
}
if i == 1 {
card.Body = card.Body + "\n[" + strconv.Itoa(i+1) + "]"
Expand All @@ -287,64 +285,51 @@ func generateData() map[string]interface{} {
if i == 5 {
card.CardID = "MM001"
}
if i == 6 {
card.IsFlashcard = true
}
if i == 7 {
card.IsFlashcard = true
}
if i == 8 {
card.IsFlashcard = true
}
cards = append(cards, card)
}
cards = append(cards, models.Card{
ID: 21,
CardID: "1/A",
UserID: 1,
Title: randomString(20),
Body: randomString(20),
Link: fmt.Sprintf("https://%s.com", randomString(10)),
CreatedAt: randomDate(time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)),
UpdatedAt: randomDate(time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC), time.Date(2024, 12, 31, 0, 0, 0, 0, time.UTC)),
ParentID: 1,
IsLiteratureCard: false,
ID: 21,
CardID: "1/A",
UserID: 1,
Title: randomString(20),
Body: randomString(20),
Link: fmt.Sprintf("https://%s.com", randomString(10)),
CreatedAt: randomDate(time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)),
UpdatedAt: randomDate(time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC), time.Date(2024, 12, 31, 0, 0, 0, 0, time.UTC)),
ParentID: 1,
})
cards = append(cards, models.Card{
ID: 22,
CardID: "2/A",
UserID: 1,
Title: "test card",
Body: randomString(20) + "[1]",
Link: fmt.Sprintf("https://%s.com", randomString(10)),
CreatedAt: randomDate(time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)),
UpdatedAt: randomDate(time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC), time.Date(2024, 12, 31, 0, 0, 0, 0, time.UTC)),
ParentID: 2,
IsLiteratureCard: false,
ID: 22,
CardID: "2/A",
UserID: 1,
Title: "test card",
Body: randomString(20) + "[1]",
Link: fmt.Sprintf("https://%s.com", randomString(10)),
CreatedAt: randomDate(time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)),
UpdatedAt: randomDate(time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC), time.Date(2024, 12, 31, 0, 0, 0, 0, time.UTC)),
ParentID: 2,
})
cards = append(cards, models.Card{
ID: 23,
CardID: "1",
UserID: 2,
Title: "test card",
Body: "hello world #to-read",
Link: fmt.Sprintf("https://%s.com", randomString(10)),
CreatedAt: randomDate(time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)),
UpdatedAt: randomDate(time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC), time.Date(2024, 12, 31, 0, 0, 0, 0, time.UTC)),
ParentID: 23,
IsLiteratureCard: false,
ID: 23,
CardID: "1",
UserID: 2,
Title: "test card",
Body: "hello world #to-read",
Link: fmt.Sprintf("https://%s.com", randomString(10)),
CreatedAt: randomDate(time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)),
UpdatedAt: randomDate(time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC), time.Date(2024, 12, 31, 0, 0, 0, 0, time.UTC)),
ParentID: 23,
})
cards = append(cards, models.Card{
ID: 24,
CardID: "2/A.1",
UserID: 1,
Title: "another test card",
Body: randomString(20) + "[1]",
Link: fmt.Sprintf("https://%s.com", randomString(10)),
CreatedAt: randomDate(time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)),
UpdatedAt: randomDate(time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC), time.Date(2024, 12, 31, 0, 0, 0, 0, time.UTC)),
ParentID: 22,
IsLiteratureCard: false,
ID: 24,
CardID: "2/A.1",
UserID: 1,
Title: "another test card",
Body: randomString(20) + "[1]",
Link: fmt.Sprintf("https://%s.com", randomString(10)),
CreatedAt: randomDate(time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC), time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)),
UpdatedAt: randomDate(time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC), time.Date(2024, 12, 31, 0, 0, 0, 0, time.UTC)),
ParentID: 22,
})

backlinks := []models.Backlink{}
Expand Down
8 changes: 0 additions & 8 deletions zettelkasten-front/src/models/Card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ export interface PartialCard {
parent_id: number;
created_at: Date;
updated_at: Date;
is_literature_card: boolean;
tags: Tag[];
is_flashcard: boolean;
}

export interface Card {
Expand All @@ -30,9 +28,7 @@ export interface Card {
files: File[];
children: PartialCard[];
references: PartialCard[];
is_literature_card: boolean;
tags: Tag[];
is_flashcard: boolean;
}

export const defaultPartialCard: PartialCard = {
Expand All @@ -43,9 +39,7 @@ export const defaultPartialCard: PartialCard = {
parent_id: -1,
created_at: new Date(0),
updated_at: new Date(0),
is_literature_card: false,
tags: [],
is_flashcard: false,
};

export const defaultCard: Card = {
Expand All @@ -63,9 +57,7 @@ export const defaultCard: Card = {
files: [],
children: [],
references: [],
is_literature_card: false,
tags: [],
is_flashcard: false,
};

export interface NextIdResponse {
Expand Down
8 changes: 0 additions & 8 deletions zettelkasten-front/src/tests/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ const samplePartialCardData: PartialCard[] = [
created_at: new Date(),
updated_at: new Date(),
parent_id: 1,
is_literature_card: false,
tags: [],
is_flashcard: false,
},
{
id: 2,
Expand All @@ -156,9 +154,7 @@ const samplePartialCardData: PartialCard[] = [
created_at: new Date(),
updated_at: new Date(),
parent_id: 2,
is_literature_card: false,
tags: [],
is_flashcard: false,
},
];

Expand All @@ -178,9 +174,7 @@ const sampleCardData: Card[] = [
references: [],
files: [],
is_deleted: false,
is_literature_card: false,
tags: [],
is_flashcard: false,
},
{
id: 2,
Expand All @@ -197,8 +191,6 @@ const sampleCardData: Card[] = [
references: [],
files: [],
is_deleted: false,
is_literature_card: false,
tags: [],
is_flashcard: false,
},
];
2 changes: 0 additions & 2 deletions zettelkasten-front/src/utils/cards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ export function convertCardToPartialCard(card: Card): PartialCard {
parent_id: card.parent_id,
created_at: card.created_at,
updated_at: card.updated_at,
is_literature_card: card.is_literature_card,
tags: card.tags,
is_flashcard: card.is_flashcard,
};
}

Expand Down

0 comments on commit 3d3fde1

Please sign in to comment.