chore: finish profile
This commit is contained in:
@@ -23,6 +23,10 @@ type newPassword struct {
|
||||
Password string `json:"password" binding:"required,min=8"`
|
||||
}
|
||||
|
||||
type newTelegram struct {
|
||||
Telegram string `json:"telegram" binding:"required,min=3,max=64"`
|
||||
}
|
||||
|
||||
func (h *Handler) UpdateUsernameById(c *gin.Context) {
|
||||
var u newUsername
|
||||
|
||||
@@ -73,3 +77,36 @@ func (h *Handler) UpdatePasswordById(c *gin.Context) {
|
||||
|
||||
c.JSON(http.StatusOK, user)
|
||||
}
|
||||
|
||||
func (h *Handler) GetTelegramById(c *gin.Context) {
|
||||
id, ok := c.MustGet("id").(string)
|
||||
if !ok {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "id invalide"})
|
||||
return
|
||||
}
|
||||
user, err := h.store.GetTelegram(id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "requête invalide"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"telegram": user.Telegram})
|
||||
}
|
||||
|
||||
func (h *Handler) SetTelegramById(c *gin.Context) {
|
||||
var t newTelegram
|
||||
if err := c.ShouldBindJSON(&t); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "requête invalide"})
|
||||
return
|
||||
}
|
||||
id, ok := c.MustGet("id").(string)
|
||||
if !ok {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "id invalide"})
|
||||
return
|
||||
}
|
||||
user, err := h.store.SetTelegram(id, t.Telegram)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "erreur serveur"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"telegram": user.Telegram})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user