This repository has been archived by the owner on Dec 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from swibly/feat/user-feature-handlers
feat: User handlers (incomplete)
- Loading branch information
Showing
26 changed files
with
769 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
JWT_SECRET= | ||
POSTGRES_HOST= | ||
POSTGRES_DB= | ||
POSTGRES_USER= | ||
POSTGRES_PASSWORD= | ||
# Postgres Config | ||
POSTGRES_HOST=localhost | ||
POSTGRES_DB=arkhon-db | ||
POSTGRES_USER=arkhon-db_owner | ||
POSTGRES_PASSWORD=arkhon | ||
POSTGRES_SSLMODE=disable | ||
|
||
# API Config | ||
JWT_SECRET=jwtsecret | ||
|
||
# TIP: You can generate a JWT_SECRET with the command: | ||
# openssl rand -hex 256 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bcrypt_cost: 10 # min: 4 | max: 31 | ||
jwt_secret: $JWT_SECRET |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package v1 | ||
|
||
import ( | ||
"errors" | ||
"log" | ||
"net/http" | ||
|
||
"github.com/devkcud/arkhon-foundation/arkhon-api/internal/service/usecase" | ||
"github.com/gin-gonic/gin" | ||
"gorm.io/gorm" | ||
) | ||
|
||
func newSearchRoutes(handler *gin.RouterGroup) { | ||
h := handler.Group("/search") | ||
|
||
h.GET("/user", SearchByNameHandler) | ||
} | ||
|
||
func SearchByNameHandler(ctx *gin.Context) { | ||
name := ctx.Query("name") | ||
log.Println(name) | ||
|
||
if name == "" { | ||
ctx.JSON(http.StatusBadRequest, gin.H{"error": "Cannot find by empty name"}) | ||
return | ||
} | ||
|
||
users, err := usecase.UserInstance.GetBySimilarName(name) | ||
if err != nil { | ||
if errors.Is(err, gorm.ErrRecordNotFound) { | ||
ctx.JSON(http.StatusNotFound, gin.H{"error": "No user found with that name."}) | ||
return | ||
} | ||
|
||
log.Print(err) | ||
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "Internal server error. Please, try again later."}) | ||
return | ||
} | ||
|
||
ctx.JSON(http.StatusOK, users) | ||
} |
Oops, something went wrong.