diff --git a/services/graph/pkg/service/v0/photo.go b/services/graph/pkg/service/v0/photo.go new file mode 100644 index 0000000000..a3cafc299d --- /dev/null +++ b/services/graph/pkg/service/v0/photo.go @@ -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) +} diff --git a/services/graph/pkg/service/v0/service.go b/services/graph/pkg/service/v0/service.go index 9881a9bdbd..24d84c48da 100644 --- a/services/graph/pkg/service/v0/service.go +++ b/services/graph/pkg/service/v0/service.go @@ -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)