Ejemplo n.º 1
0
        public async Task <IActionResult> UpdateAsync([FromBody] Client.Users.UserPatchInfo patchInfo, CancellationToken cancellationToken)
        {
            if (patchInfo == null)
            {
                var error = ServiceErrorResponses.BodyIsMissing("UserPatchInfo");
                return(this.BadRequest(error));
            }

            var userId = User.FindFirstValue("userId");

            if (userId == null)
            {
                var error = ServiceErrorResponses.InvalidClaims("userId");
                return(this.BadRequest(error));
            }

            User modelUser;

            try
            {
                modelUser = await userRepository.PatchAsync(patchInfo, userId, cancellationToken);
            }
            catch (UserNotFoundException e)
            {
                var error = ServiceErrorResponses.NoSuchObject("User", e.Message);
                return(this.NotFound(error));
            }

            var clientUserInfo = UserConverter.ConvertToUserInfo(modelUser);

            return(Ok(clientUserInfo));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetAsync([FromRoute] string id, CancellationToken cancellationToken)
        {
            if (id == null)
            {
                var error = ServiceErrorResponses.InvalidRouteParameter("userId");
                return(this.BadRequest(error));
            }

            var modelUser = await userRepository.GetByIdAsync(id);

            if (modelUser == null)
            {
                var error = ServiceErrorResponses.NoSuchObject("User", "User not found");
                return(NotFound(error));
            }
            var clientUserInfo = UserConverter.ConvertToUserInfo(modelUser);

            return(Ok(clientUserInfo));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> GetAsync([FromRoute] string id, CancellationToken cancellationToken)
        {
            if (id == null)
            {
                var error = ServiceErrorResponses.InvalidRouteParameter("activityId");
                return(this.BadRequest(error));
            }

            var modelActivity = await activityRepository.GetByIdAsync(id);

            if (modelActivity == null)
            {
                var message = "Activity with id " + id + " not found.";
                var error   = ServiceErrorResponses.NoSuchObject("Activity", message);
                return(this.NotFound(error));
            }
            var clientActivity = ActivityConverter.Convert(modelActivity);

            return(Ok(clientActivity));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> GetAsync([FromRoute] string id, CancellationToken cancellationToken)
        {
            if (id == null)
            {
                var error = ServiceErrorResponses.InvalidRouteParameter("maraphoneId");
                return(this.BadRequest(error));
            }

            var modelMaraphone = await maraphoneRepository.GetAsync(id, cancellationToken);

            if (modelMaraphone == null)
            {
                var message = "Maraphone with id " + id + " not found.";
                var error   = ServiceErrorResponses.NoSuchObject("Maraphone", message);
                return(this.NotFound(error));
            }
            var clientMaraphone = MaraphoneConverter.Convert(modelMaraphone);

            return(Ok(clientMaraphone));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> GetAsync([FromRoute] string id, CancellationToken cancellationToken)
        {
            if (id == null)
            {
                var error = ServiceErrorResponses.InvalidRouteParameter("DocumentId");
                return(this.BadRequest(error));
            }

            var modelContent = await contentRepository.GetAsync(id);

            if (modelContent == null)
            {
                var error = ServiceErrorResponses.NoSuchObject("Content", "Not content with such id " + id);
                return(this.NotFound(error));
            }

            var clientContent = ContentConverter.Convert(modelContent);

            return(Ok(clientContent));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> CreateAsync([FromBody] Client.ActivityBuildInfo buildInfo,
                                                      CancellationToken cancellationToken)
        {
            if (buildInfo == null)
            {
                var error = ServiceErrorResponses.BodyIsMissing("ActivityCreationInfo");
                return(this.BadRequest(error));
            }
            var userId = User.FindFirstValue("userId");

            if (userId == null)
            {
                var error = ServiceErrorResponses.InvalidClaims("userId");
                return(this.BadRequest(error));
            }

            var maraphoneId = buildInfo.MaraphoneId;
            var maraphone   = await maraphoneRepository.GetAsync(maraphoneId, cancellationToken);

            if (maraphone == null)
            {
                var error = ServiceErrorResponses.NoSuchObject("Maraphone", "Maraphone not found");
                return(this.NotFound(error));
            }

            var duration = maraphone.Duration;
            var endAt    = buildInfo.StartAt + duration;

            var activityCreationInfo = new ActivityCreationInfo(buildInfo.MaraphoneId, buildInfo.Tags,
                                                                userId, buildInfo.Experts, buildInfo.StartAt, endAt);

            var modelActivity = await activityRepository.CreateAsync(activityCreationInfo, endAt, cancellationToken);

            var clientActivity = ActivityConverter.Convert(modelActivity);

            return(CreatedAtRoute(
                       "GetActivity",
                       new { id = clientActivity.Id },
                       clientActivity));
        }