Skip to content
This repository has been archived by the owner on Mar 10, 2024. It is now read-only.

Commit

Permalink
Fix article by id marshal (#24)
Browse files Browse the repository at this point in the history
* ignore_changes to cloud run from deploying from github actions

* fix service name

* fix marshalling article by ID to struct from DB
  • Loading branch information
dpgraham4401 authored Jul 24, 2023
1 parent 5117363 commit a02ed84
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cloud-run-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ on:
description: 'The name of the Cloud Run service to deploy to'
required: true
type: string
default: 'dpgraham-api'
default: 'dpgraham-server'

env:
PROJECT_ID: ${{ vars.PROJECT_ID }}
Expand Down
6 changes: 2 additions & 4 deletions .run/Run.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
<envs>
<env name="DB_HOST" value="localhost" />
<env name="DB_PASSWORD" value="password123" />
<env name="DB_USER" value="dg" />
<env name="DB_USER" value="root" />
</envs>
<kind value="DIRECTORY" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<method v="2">
<option name="RunConfigurationTask" enabled="true" run_configuration_name="Development Database" run_configuration_type="ShConfigurationType" />
</method>
<method v="2" />
</configuration>
</component>
14 changes: 13 additions & 1 deletion db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,19 @@ func (a *ArticleStore) All() ([]models.Article, error) {

func (a *ArticleStore) ByID(id int) (models.Article, error) {
article := models.Article{}
err := a.DB.QueryRow("SELECT * FROM articles WHERE id = $1", id).Scan(
err := a.DB.QueryRow(
`SELECT
id,
to_char(created_date, 'mm/dd/yyyy'),
to_char(updated_date, 'mm/dd/yyyy'),
content,
published,
title,
author
FROM
articles
WHERE
id = $1`, id).Scan(
&article.Id, &article.CreatedDate, &article.LastUpdate, &article.Content, &article.Published,
&article.Title, &article.Author)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions infra/modules/cloud-run/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
resource "google_cloud_run_v2_service" "default" {
name = var.name
location = var.region
lifecycle {
ignore_changes = [template, client, client_version, labels]
}

template {
containers {
Expand Down

0 comments on commit a02ed84

Please sign in to comment.