Cleanup
This commit is contained in:
parent
43c67d8c29
commit
17368dea9a
2 changed files with 20 additions and 23 deletions
|
@ -6,25 +6,38 @@ import (
|
|||
"net/http"
|
||||
)
|
||||
|
||||
// UserShow gets all information about a user
|
||||
// UserShow gets all informations about the current user
|
||||
func UserShow(c echo.Context) error {
|
||||
// swagger:operation GET /user user showUser
|
||||
// ---
|
||||
// summary: Shows the current user
|
||||
// consumes:
|
||||
// - application/json
|
||||
// produces:
|
||||
// - application/json
|
||||
// responses:
|
||||
// "200":
|
||||
// "$ref": "#/responses/User"
|
||||
// "400":
|
||||
// "$ref": "#/responses/Message"
|
||||
// "500":
|
||||
// "$ref": "#/responses/Message"
|
||||
|
||||
userInfos, err := models.GetCurrentUser(c)
|
||||
if err != nil {
|
||||
if models.IsErrUserDoesNotExist(err) {
|
||||
return c.JSON(http.StatusNotFound, models.Message{"The user does not exist."})
|
||||
return echo.NewHTTPError(http.StatusNotFound, "The user does not exist.")
|
||||
}
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting user infos."})
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Error getting user infos.")
|
||||
}
|
||||
|
||||
user, err := models.GetUserByID(userInfos.ID)
|
||||
if err != nil {
|
||||
if models.IsErrUserDoesNotExist(err) {
|
||||
return c.JSON(http.StatusNotFound, models.Message{"The user does not exist."})
|
||||
return echo.NewHTTPError(http.StatusNotFound, "The user does not exist.")
|
||||
}
|
||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting user infos."})
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Error getting user infos.")
|
||||
}
|
||||
// Obfuscate his password
|
||||
user.Password = ""
|
||||
|
||||
return c.JSON(http.StatusOK, user)
|
||||
}
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
package routes
|
||||
|
||||
import (
|
||||
"github.com/labstack/echo"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// SetCORSHeader sets relevant CORS headers for Cross-Site-Requests to the api
|
||||
func SetCORSHeader(c echo.Context) error {
|
||||
res := c.Response()
|
||||
res.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
res.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE")
|
||||
res.Header().Set("Access-Control-Allow-Headers", "authorization,content-type")
|
||||
res.Header().Set("Access-Control-Expose-Headers", "authorization,content-type")
|
||||
return c.String(http.StatusOK, "")
|
||||
}
|
Loading…
Reference in a new issue