You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

user.go 1.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package http
  2. import (
  3. "net/http"
  4. "github.com/gin-gonic/gin"
  5. "gitlink.org.cn/cloudream/common/consts/errorcode"
  6. "gitlink.org.cn/cloudream/common/pkgs/logger"
  7. "gitlink.org.cn/cloudream/common/sdks/storage/cdsapi"
  8. )
  9. type UserService struct {
  10. *Server
  11. }
  12. func (s *Server) User() *UserService {
  13. return &UserService{
  14. Server: s,
  15. }
  16. }
  17. func (s *UserService) Create(ctx *gin.Context) {
  18. log := logger.WithField("HTTP", "User.Create")
  19. var req cdsapi.UserCreate
  20. if err := ctx.ShouldBindJSON(&req); err != nil {
  21. log.Warnf("binding body: %s", err.Error())
  22. ctx.JSON(http.StatusBadRequest, Failed(errorcode.BadArgument, "missing argument or invalid argument"))
  23. return
  24. }
  25. user, err := s.svc.UserSvc().Create(req.Name)
  26. if err != nil {
  27. log.Warnf("create user: %s", err.Error())
  28. ctx.JSON(http.StatusOK, Failed(errorcode.OperationFailed, err.Error()))
  29. return
  30. }
  31. ctx.JSON(http.StatusOK, OK(cdsapi.UserCreateResp{User: user}))
  32. }
  33. func (s *UserService) Delete(ctx *gin.Context) {
  34. log := logger.WithField("HTTP", "User.Delete")
  35. var req cdsapi.UserDelete
  36. if err := ctx.ShouldBindJSON(&req); err != nil {
  37. log.Warnf("binding body: %s", err.Error())
  38. ctx.JSON(http.StatusBadRequest, Failed(errorcode.BadArgument, "missing argument or invalid argument"))
  39. return
  40. }
  41. if err := s.svc.UserSvc().Delete(req.UserID); err != nil {
  42. log.Warnf("delete user: %s", err.Error())
  43. ctx.JSON(http.StatusOK, Failed(errorcode.OperationFailed, err.Error()))
  44. return
  45. }
  46. ctx.JSON(http.StatusOK, OK(nil))
  47. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。