Skip to content

Commit

Permalink
fix tests, add json fields to getJob
Browse files Browse the repository at this point in the history
  • Loading branch information
sethetter committed Jul 29, 2024
1 parent 4535609 commit 6466883
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
13 changes: 10 additions & 3 deletions pkg/data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ type Job struct {
Position string `db:"position" json:"position"`
Organization string `db:"organization" json:"organization"`
Url sql.NullString `db:"url" json:"-"`
JSONUrl *string `json:"url"`
JSONUrl *string `db:"-" json:"url"`
Description sql.NullString `db:"description" json:"-"`
DescriptionJSON *string `json:"description"`
DescriptionJSON *string `db:"-" json:"description"`
Email string `db:"email" json:"email"`
PublishedAt time.Time `db:"published_at" json:"published_at"`
}
Expand Down Expand Up @@ -76,7 +76,7 @@ func (job *Job) RenderDescription() (string, error) {
func (job *Job) Save(db *sqlx.DB) (sql.Result, error) {
return db.Exec(
"UPDATE jobs SET position = $1, organization = $2, url = $3, description = $4 WHERE id = $5",
job.Position, job.Organization, job.JSONUrl, job.DescriptionJSON, job.ID,
job.Position, job.Organization, job.Url, job.Description, job.ID,
)
}

Expand Down Expand Up @@ -122,6 +122,13 @@ func GetJob(id string, db *sqlx.DB) (Job, error) {
return job, err
}

if !job.Url.Valid {
job.JSONUrl = &job.Url.String
}
if !job.Description.Valid {
job.DescriptionJSON = &job.Description.String
}

return job, nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/server/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func (ctrl *Controller) JobsJSON(ctx *gin.Context) {
return
}

ctx.Header("Content-Type", "application/json")
ctx.JSON(200, gin.H{"items": jobs})
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/server/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ func getDbFields(thing interface{}) []string {

for i := 0; i < t.NumField(); i++ {
dbTag := t.Field(i).Tag.Get("db")
if dbTag != "" {
if dbTag != "-" {
dbFields = append(dbFields, dbTag)
}
}
Expand Down

0 comments on commit 6466883

Please sign in to comment.