Exemplo n.º 1
0
    public Result <GetAlbumResponse> GetAdminAlbumByType(AdminAlbumType type)
    {
        if (!_adminAlbumMappings.TryGetValue(type.ToString(), out var photosetId))
        {
            return(Result <GetAlbumResponse> .Failure($"The given admin album type is not supported: {type}."));
        }

        var getPhotosetResult = _flickrClient.GetPhotoset(photosetId);

        if (getPhotosetResult.IsFailure)
        {
            return(Result <GetAlbumResponse> .From(getPhotosetResult));
        }

        var result = getPhotosetResult.Value;

        return(Result <GetAlbumResponse> .Of(new GetAlbumResponse
        {
            Id = result.Id,
            Total = result.Total,
            PageSize = result.PerPage,
            Title = result.Title,
            Photos = result.Photos.ConvertAll(x => new GetAlbumResponse.Photo
            {
                Id = x.Id,
                Title = x.Title,
                TakenAt = x.TakenAt,
                Latitude = x.Latitude,
                Longitude = x.Longitude
            })
        }));
    }
Exemplo n.º 2
0
    public IActionResult UploadImageToAdminAlbum([FromForm] UploadImageToAdminAlbumRequest request, [FromRoute] AdminAlbumType type)
    {
        var result = _adminAlbumService.UploadImageToAdminAlbum(request, type);

        return(ToApiResponse(result));
    }
Exemplo n.º 3
0
    public IActionResult GetAdminAlbumByType([FromRoute] AdminAlbumType type)
    {
        var result = _adminAlbumService.GetAdminAlbumByType(type);

        return(ToApiResponse(result));
    }
Exemplo n.º 4
0
    public Result <UploadPhotoResponse> UploadImageToAdminAlbum(UploadImageToAdminAlbumRequest request, AdminAlbumType type)
    {
        if (!_adminAlbumMappings.TryGetValue(type.ToString(), out var photosetId))
        {
            return(Result <UploadPhotoResponse> .Failure($"The given admin album type is not supported: {type}."));
        }

        Result <Core.Client.Flickr.Type.UploadPhotoResponse> uploadImageResult;

        using (var imageStream = request.Image.OpenReadStream())
        {
            uploadImageResult = _flickrClient.UploadImage(new Core.Client.Flickr.Type.UploadPhotoRequest
            {
                Title       = Guid.NewGuid().ToString(),
                Description = "",
                Tags        = new List <string>(),
                Photo       = imageStream,
                IsPublic    = false
            });
            if (uploadImageResult.IsFailure)
            {
                return(Result <UploadPhotoResponse> .From(uploadImageResult));
            }
        }

        var photo = uploadImageResult.Value;

        var addPhotoToPhotosetResult = _flickrClient.AddPhotoToPhotoset(new AddPhotoToPhotosetRequest
        {
            PhotoId    = photo.Id,
            PhotosetId = photosetId
        });

        if (addPhotoToPhotosetResult.IsFailure)
        {
            return(Result <UploadPhotoResponse> .Failure(addPhotoToPhotosetResult.FailureMessage !));
        }

        return(Result <UploadPhotoResponse> .Of(new UploadPhotoResponse
        {
            Id = photo.Id,
            Title = photo.Title,
            Latitude = photo.Latitude,
            Longitude = photo.Longitude,
            TakenAt = photo.TakenAt,
            ImageUrlLarge = photo.ImageUrlLarge
        }));
    }