Skip to content

Commit

Permalink
Add card_id in swipe record
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuflatland-lf committed Aug 16, 2024
1 parent 3005ba9 commit 0a047eb
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,16 @@ CREATE TABLE IF NOT EXISTS swipe_records
(
id BIGSERIAL PRIMARY KEY,
user_id BIGINT NOT NULL,
card_id BIGINT NOT NULL,
direction TEXT NOT NULL,
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE,
FOREIGN KEY (card_id) REFERENCES cards (id) ON DELETE CASCADE
);
CREATE INDEX idx_swipe_records_id ON swipe_records(id);
CREATE INDEX idx_swipe_records_user_id ON swipe_records(user_id);
CREATE INDEX idx_swipe_records_card_id ON swipe_records(card_id);

-- +goose statementbegin
-- When the updated column is not changed, assign NULL
Expand Down
1 change: 1 addition & 0 deletions backend/graph/db/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type Role struct {
type SwipeRecord struct {
ID int64 `gorm:"column:id;primaryKey" validate:"number"`
UserID int64 `gorm:"column:user_id" validate:"number"`
CardID int64 `gorm:"column:card_id" validate:"number"`
Direction string `gorm:"column:direction;not null" validate:"required"`
Created time.Time `gorm:"column:created;autoCreateTime"`
Updated time.Time `gorm:"column:updated;autoCreateTime"`
Expand Down
67 changes: 67 additions & 0 deletions backend/graph/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/graph/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ type CardGroupConnection {
type SwipeRecord {
id: ID!
userId: ID!
cardId: ID!
direction: String! @validation(format: "required")
created: Time!
updated: Time!
Expand Down
1 change: 0 additions & 1 deletion backend/graph/schema.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 21 additions & 21 deletions backend/graph/schema.resolvers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2123,7 +2123,7 @@ func TestGraphQLErrors(t *testing.T) {
testGraphQLQuery(t, e, jsonInput, expected)
})

t.Run("Upsert Dictionaly Smoke", func(t *testing.T) {
t.Run("Upsert Dictionary Smoke", func(t *testing.T) {
t.Helper()
t.Parallel()

Expand All @@ -2132,7 +2132,7 @@ func TestGraphQLErrors(t *testing.T) {
roleService := services.NewRoleService(db, 20)

ctx := context.Background()
createdGroup, _ := testutils.CreateUserAndCardGroup(ctx, userService, cardGroupService, roleService)
createdGroup, _, _ := testutils.CreateUserAndCardGroup(ctx, userService, cardGroupService, roleService)

input := model.UpsertDictionary{
Dictionary: base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf(`
Expand Down Expand Up @@ -2161,25 +2161,25 @@ New Front 2 裏面2
})

// Expected response structure
expected := `{
"data": {
"upsertDictionary": {
"nodes": [{
"id": "1",
"front": "New Front 1",
"back": "裏面1",
"interval_days": 1,
"cardGroupID": 1
}, {
"id": "2",
"front": "New Front 2",
"back": "裏面2",
"interval_days": 1,
"cardGroupID": 1
}]
}
}
}`
expected := fmt.Sprintf(`{
"data": {
"upsertDictionary": {
"nodes": [{
"id": "1",
"front": "New Front 1",
"back": "裏面1",
"interval_days": 1,
"cardGroupID": %d
}, {
"id": "2",
"front": "New Front 2",
"back": "裏面2",
"interval_days": 1,
"cardGroupID": %d
}]
}
}
}`, createdGroup.ID, createdGroup.ID)

// Perform the GraphQL query and check the results
testGraphQLQuery(t, e, jsonInput, expected, "data.upsertDictionary.nodes.id")
Expand Down

0 comments on commit 0a047eb

Please sign in to comment.