Skip to content

Commit

Permalink
implement verifying employer emails (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Gulczyński committed Aug 23, 2023
1 parent ef98119 commit 408331a
Show file tree
Hide file tree
Showing 30 changed files with 555 additions and 55 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ migrate_down:
migrate -path internal/db/migrations -database "postgresql://devuser:admin@localhost:5432/go_gin_job_search_db?sslmode=disable" -verbose down

# generate db related go code with sqlc
# for windows: cmd.exe /c "docker run --rm -v ${PWD}:/src -w /src kjconroy/sqlc generate"
sqlc:
cmd.exe /c "docker run --rm -v ${PWD}:/src -w /src kjconroy/sqlc generate"
sqlc generate

# generate mock db for testing
mock:
Expand Down
68 changes: 68 additions & 0 deletions docs/docs.go

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

68 changes: 68 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,49 @@
}
}
},
"/employers/verify-email": {
"get": {
"description": "Verify employer email by providing verify email ID and secret code that should be sent to the user in the verification email.",
"produces": [
"application/json"
],
"tags": [
"employers"
],
"summary": "Verify employer email",
"parameters": [
{
"description": "Verify email ID and secret code from the email.",
"name": "VerifyEmployerEmailRequest",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/api.verifyEmployerEmailRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/api.verifyEmployerEmailResponse"
}
},
"400": {
"description": "Invalid request body.",
"schema": {
"$ref": "#/definitions/api.ErrorResponse"
}
},
"500": {
"description": "Any other error.",
"schema": {
"$ref": "#/definitions/api.ErrorResponse"
}
}
}
}
},
"/job-applications": {
"post": {
"security": [
Expand Down Expand Up @@ -2387,6 +2430,31 @@
}
}
},
"api.verifyEmployerEmailRequest": {
"type": "object",
"required": [
"code",
"id"
],
"properties": {
"code": {
"type": "string",
"minLength": 32
},
"id": {
"type": "integer",
"minimum": 1
}
}
},
"api.verifyEmployerEmailResponse": {
"type": "object",
"properties": {
"message": {
"type": "string"
}
}
},
"api.verifyUserEmailResponse": {
"type": "object",
"properties": {
Expand Down
46 changes: 46 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,23 @@ definitions:
skills_description:
type: string
type: object
api.verifyEmployerEmailRequest:
properties:
code:
minLength: 32
type: string
id:
minimum: 1
type: integer
required:
- code
- id
type: object
api.verifyEmployerEmailResponse:
properties:
message:
type: string
type: object
api.verifyUserEmailResponse:
properties:
message:
Expand Down Expand Up @@ -808,6 +825,35 @@ paths:
summary: Get user as employer
tags:
- employers
/employers/verify-email:
get:
description: Verify employer email by providing verify email ID and secret code
that should be sent to the user in the verification email.
parameters:
- description: Verify email ID and secret code from the email.
in: body
name: VerifyEmployerEmailRequest
required: true
schema:
$ref: '#/definitions/api.verifyEmployerEmailRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/api.verifyEmployerEmailResponse'
"400":
description: Invalid request body.
schema:
$ref: '#/definitions/api.ErrorResponse'
"500":
description: Any other error.
schema:
$ref: '#/definitions/api.ErrorResponse'
summary: Verify employer email
tags:
- employers
/job-applications:
post:
consumes:
Expand Down
41 changes: 41 additions & 0 deletions internal/api/employer.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,3 +572,44 @@ func (server *Server) getEmployerAndCompanyDetails(ctx *gin.Context) {

ctx.JSON(http.StatusOK, details)
}

type verifyEmployerEmailRequest struct {
ID int64 `form:"id" binding:"required,min=1"`
SecretCode string `form:"code" binding:"required,min=32"`
}

type verifyEmployerEmailResponse struct {
Message string `json:"message"`
}

// @Schemes
// @Summary Verify employer email
// @Description Verify employer email by providing verify email ID and secret code that should be sent to the user in the verification email.
// @Tags employers
// @Produce json
// @param VerifyEmployerEmailRequest body verifyEmployerEmailRequest true "Verify email ID and secret code from the email."
// @Success 200 {object} verifyEmployerEmailResponse
// @Failure 400 {object} ErrorResponse "Invalid request body."
// @Failure 500 {object} ErrorResponse "Any other error."
// @Router /employers/verify-email [get]
// verifyEmployerEmail handles employer email verification
func (server *Server) verifyEmployerEmail(ctx *gin.Context) {
var request verifyEmployerEmailRequest
if err := ctx.ShouldBindQuery(&request); err != nil {
ctx.JSON(http.StatusBadRequest, errorResponse(err))
return
}

txResult, err := server.store.VerifyEmployerEmailTx(ctx, db.VerifyEmailTxParams{
ID: request.ID,
SecretCode: request.SecretCode,
})
if err != nil {
ctx.JSON(http.StatusInternalServerError, errorResponse(err))
return
}

if txResult.Employer.IsEmailVerified {
ctx.JSON(http.StatusOK, verifyEmployerEmailResponse{Message: "Successfully verified email"})
}
}
Loading

0 comments on commit 408331a

Please sign in to comment.