add skel for photos

Signed-off-by: Christian Richter <c.richter@opencloud.eu>
This commit is contained in:
Christian Richter
2025-05-08 16:26:35 +02:00
committed by Florian Schade
parent b954681c3b
commit e23b8f412b
2 changed files with 58 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
package svc
import (
"net/http"
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
"github.com/go-chi/render"
"github.com/opencloud-eu/opencloud/services/graph/pkg/errorcode"
revactx "github.com/opencloud-eu/reva/v2/pkg/ctx"
)
// GetMePhoto implements the Service interface
func (g Graph) GetMePhoto(w http.ResponseWriter, r *http.Request) {
logger := g.logger.SubloggerWithRequestID(r.Context())
logger.Debug().Msg("GetMePhoto called")
u, ok := revactx.ContextGetUser(r.Context())
if !ok {
logger.Debug().Msg("could not get user: user not in context")
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, "user not in context")
return
}
g.GetPhoto(w, r, u.GetId())
}
// GetPhoto implements the Service interface
func (g Graph) GetPhoto(w http.ResponseWriter, r *http.Request, u *userpb.UserId) {
logger := g.logger.SubloggerWithRequestID(r.Context())
logger.Debug().Msg("GetPhoto called")
// TODO: use proper default return
render.Status(r, http.StatusNotFound)
render.JSON(w, r, nil)
}
// UpdateMePhoto implements the Service interface
func (g Graph) UpdateMePhoto(w http.ResponseWriter, r *http.Request) {
logger := g.logger.SubloggerWithRequestID(r.Context())
logger.Debug().Msg("UpdateMePhoto called")
u, ok := revactx.ContextGetUser(r.Context())
if !ok {
logger.Debug().Msg("could not get user: user not in context")
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, "user not in context")
return
}
g.UpdatePhoto(w, r, u.GetId())
}
// UpdatePhoto implements the Service interface
func (g Graph) UpdatePhoto(w http.ResponseWriter, r *http.Request, u *userpb.UserId) {
logger := g.logger.SubloggerWithRequestID(r.Context())
logger.Debug().Msg("UpdatePhoto called")
// TODO: use proper default return
render.Status(r, http.StatusForbidden)
render.JSON(w, r, nil)
}

View File

@@ -293,6 +293,8 @@ func NewService(opts ...Option) (Graph, error) { //nolint:maintidx
})
r.Get("/drives", svc.GetDrives(APIVersion_1))
r.Post("/changePassword", svc.ChangeOwnPassword)
r.Get("/photo", svc.GetMePhoto)
r.Put("/photo", svc.UpdateMePhoto)
})
r.Route("/users", func(r chi.Router) {
r.Get("/", svc.GetUsers)