Skip to content

Commit

Permalink
Add /resumes/latest endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
davidianstyle committed Feb 27, 2024
1 parent 703b29f commit 5237b23
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
13 changes: 13 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func main() {
})

// API to interact with resumés
router.GET("/resumes/latest", getLatestResume)
router.GET("/resumes", getResumes)
router.GET("/resumes/:id", getResumeByID)
router.PATCH("/resumes/:id", updateResumeByID)
Expand Down Expand Up @@ -102,6 +103,18 @@ func setupDB() error {
return nil
}

func getLatestResume(c *gin.Context) {
var latestResume Resume

// Order by year in descending order and then by the latest modification time
if err := db.Order("year desc, updated_at desc").First(&latestResume).Error; err != nil {
c.IndentedJSON(http.StatusNotFound, gin.H{"message": "No resumes found"})
return
}

c.IndentedJSON(http.StatusOK, latestResume)
}

func getResumes(c *gin.Context) {
var resumes []Resume
db.Find(&resumes)
Expand Down
26 changes: 26 additions & 0 deletions openapispec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,32 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error'
'/resumes/latest':
get:
operationId: getLatestResume
summary: Get the most recent resumé
description: API to get the most recent resumé by year. In case of a tie, returns the most recently modified one.
tags:
- resumes
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/ResumeResponse'
'404':
description: No resumes found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
default:
description: Unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
components:
schemas:
Resume:
Expand Down

0 comments on commit 5237b23

Please sign in to comment.