Skip to content

Commit 14561ac

Browse files
committed
update github link
1 parent e0b8ff5 commit 14561ac

File tree

13 files changed

+158
-8
lines changed

13 files changed

+158
-8
lines changed

database/queries/user.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,9 @@ UPDATE users
100100
SET
101101
is_starred = $1
102102
WHERE email = $2;
103+
104+
-- name: UpdateGitHub :exec
105+
UPDATE users
106+
SET
107+
github_profile = $1
108+
WHERE email = $2;

docs/sample.yaml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,83 @@ paths:
16401640
data:
16411641
type: string
16421642
example: "error creating request"
1643+
/auth/github:
1644+
post:
1645+
summary: Update GitHub Profile
1646+
description: Updates the GitHub profile URL of the authenticated user.
1647+
operationId: updateGithubProfile
1648+
tags:
1649+
- Authentication
1650+
requestBody:
1651+
required: true
1652+
content:
1653+
application/json:
1654+
schema:
1655+
type: object
1656+
properties:
1657+
github:
1658+
type: string
1659+
format: uri
1660+
description: The GitHub profile URL to update
1661+
required:
1662+
- github
1663+
examples:
1664+
validRequest:
1665+
value:
1666+
github: "https://github.com/example-user"
1667+
responses:
1668+
"202":
1669+
description: GitHub profile updated successfully
1670+
content:
1671+
application/json:
1672+
schema:
1673+
type: object
1674+
properties:
1675+
status:
1676+
type: string
1677+
example: success
1678+
message:
1679+
type: string
1680+
example: User github updated successfully
1681+
"400":
1682+
description: Invalid request
1683+
content:
1684+
application/json:
1685+
schema:
1686+
type: object
1687+
properties:
1688+
status:
1689+
type: string
1690+
example: fail
1691+
message:
1692+
type: string
1693+
example: Invalid request body
1694+
"401":
1695+
description: Unauthorized access
1696+
content:
1697+
application/json:
1698+
schema:
1699+
type: object
1700+
properties:
1701+
status:
1702+
type: string
1703+
example: success
1704+
message:
1705+
type: string
1706+
example: unauthorized
1707+
"500":
1708+
description: Internal server error
1709+
content:
1710+
application/json:
1711+
schema:
1712+
type: object
1713+
properties:
1714+
status:
1715+
type: string
1716+
example: fail
1717+
message:
1718+
type: string
1719+
example: DB error [failed to update the github_link]
16431720
/info/me:
16441721
get:
16451722
tags:

pkg/controller/me.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,51 @@ import (
1313
"github.com/labstack/echo/v4"
1414
)
1515

16+
func UpdateGithubProfile(c echo.Context) error {
17+
ctx := c.Request().Context()
18+
19+
user, ok := c.Get("user").(db.User)
20+
if !ok {
21+
return c.JSON(http.StatusUnauthorized, &models.Response{
22+
Status: "success",
23+
Message: "unauthorized",
24+
})
25+
}
26+
27+
var req models.UpdateGithub
28+
if err := c.Bind(&req); err != nil {
29+
logger.Warnf(err.Error())
30+
return c.JSON(http.StatusBadRequest, &models.Response{
31+
Status: "fail",
32+
Message: "Invalid request body",
33+
})
34+
}
35+
36+
if err := utils.Validate.Struct(req); err != nil {
37+
return c.JSON(http.StatusBadRequest, &models.Response{
38+
Status: "fail",
39+
Data: utils.FormatValidationErrors(err),
40+
})
41+
}
42+
43+
err := utils.Queries.UpdateGitHub(ctx, db.UpdateGitHubParams{
44+
GithubProfile: &req.Github,
45+
Email: user.Email,
46+
})
47+
48+
if err != nil {
49+
return c.JSON(http.StatusInternalServerError, &models.Response{
50+
Status: "fail",
51+
Message: "DB error [failed to update the github_link]",
52+
})
53+
}
54+
55+
return c.JSON(http.StatusAccepted, &models.Response{
56+
Status: "success",
57+
Message: "User github updated successfully",
58+
})
59+
}
60+
1661
func GetDetails(c echo.Context) error {
1762
ctx := c.Request().Context()
1863
user, ok := c.Get("user").(db.User)

pkg/db/db.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/db/export.sql.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/db/ideas.sql.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/db/models.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/db/score.sql.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/db/submission.sql.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/db/teams.sql.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)