// Path: src/main/java/org/ominidi/api/exception/ConnectionException.java
// public class ConnectionException extends RuntimeException {
//     public ConnectionException(String message) {
//         super(message);
//     }
// }
// 
// Path: src/main/java/org/ominidi/api/exception/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//     public NotFoundException(String message) {
//         super(message);
//     }
// }
// 
// Path: src/main/java/org/ominidi/api/model/Errors.java
// public final class Errors {
//     public static final String CONNECTION_PROBLEM = "Problem connecting to the feed";
// 
//     public static final String postNotFound(String id) {
//         return "Post with id " + id + " not found";
//     }
// }
// 
// Path: src/main/java/org/ominidi/domain/model/Feed.java
// @Getter
// public class Feed<Post> implements Iterable<Post> {
//     private final List<Post> posts;
//     private final String nextUrl;
//     private final String prevUrl;
//     private final Integer size;
// 
//     public Feed(List<Post> posts, String nextUrl, String prevUrl) {
//         this.posts = posts;
//         this.size = posts.size();
//         this.nextUrl = nextUrl;
//         this.prevUrl = prevUrl;
//     }
// 
//     @Override
//     public Iterator<Post> iterator() {
//         return posts.iterator();
//     }
// 
//     public Integer size() {
//         return posts.size();
//     }
// }
// 
// Path: src/main/java/org/ominidi/domain/model/Post.java
// @Getter
// public class Post {
//     private final String id;
//     private final String objectId;
//     private final String createdTime;
//     private final String type;
//     private final String link;
//     private final String permalinkUrl;
//     private final String picture;
//     private final String fullPicture;
//     private final String message;
// 
//     public Post(
//             String id,
//             String objectId,
//             String createdTime,
//             String type,
//             String link,
//             String permalinkUrl,
//             String picture,
//             String fullPicture,
//             String message
//     ) {
//         this.id = id;
//         this.objectId = objectId;
//         this.createdTime = createdTime;
//         this.type = type;
//         this.link = link;
//         this.permalinkUrl = permalinkUrl;
//         this.picture = picture;
//         this.fullPicture = fullPicture;
//         this.message = message;
//     }
// }
// 
// Path: src/main/java/org/ominidi/facebook/service/PageFeedService.java
// @Service
// public class PageFeedService implements FeedAware {
//     private ConnectionAware pageFeed;
// 
//     private FeedMapper feedMapper;
// 
//     private PostMapper postMapper;
// 
//     @Autowired
//     public PageFeedService(ConnectionAware pageFeed, FeedMapper feedMapper, PostMapper postMapper) {
//         this.pageFeed = pageFeed;
//         this.feedMapper = feedMapper;
//         this.postMapper = postMapper;
//     }
// 
//     @Override
//     public Optional<Feed<Post>> getFeed() {
//         try {
//             return Optional.of(feedMapper.fromType(pageFeed.getConnection()));
//         } catch (ConnectionException e) {
//             return Optional.empty();
//         }
//     }
// 
//     @Override
//     public Optional<Feed<Post>> getFeed(String feedUrl) {
//         try {
//             return Optional.of(feedMapper.fromType(pageFeed.getConnection(feedUrl)));
//         } catch (ConnectionException e) {
//             return Optional.empty();
//         }
//     }
// 
//     @Override
//     public Optional<Post> getPostById(String id) {
//         try {
//             return Optional.of(postMapper.fromType(pageFeed.getObject(id)));
//         } catch (ConnectionException e) {
//             return Optional.empty();
//         }
//     }
// }


import org.ominidi.api.exception.ConnectionException;
import org.ominidi.api.exception.NotFoundException;
import org.ominidi.api.model.Errors;
import org.ominidi.domain.model.Feed;
import org.ominidi.domain.model.Post;
import org.ominidi.facebook.service.PageFeedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.Optional;

package org.ominidi.api.controller;



@RestController
@RequestMapping("/api/v1")
public class FeedController {

    private PageFeedService pageFeedService;

    @Autowired
    public FeedController(PageFeedService pageFeedService) {
        this.pageFeedService = pageFeedService;
    }

    @GetMapping(value = "/feed", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Feed<Post> getFeed(@RequestParam(value = "u", required = false) Optional<String> feedUrl) {
        Optional<Feed<Post>> result = feedUrl.isPresent()
                ? pageFeedService.getFeed(feedUrl.get())
                : pageFeedService.getFeed();

        return result.orElseThrow(() -> new ConnectionException(Errors.CONNECTION_PROBLEM));
    }


// Path: src/main/java/org/ominidi/api/exception/ConnectionException.java
// public class ConnectionException extends RuntimeException {
//     public ConnectionException(String message) {
//         super(message);
//     }
// }
// 
// Path: src/main/java/org/ominidi/api/exception/NotFoundException.java
// public class NotFoundException extends RuntimeException {
//     public NotFoundException(String message) {
//         super(message);
//     }
// }
// 
// Path: src/main/java/org/ominidi/api/model/Errors.java
// public final class Errors {
//     public static final String CONNECTION_PROBLEM = "Problem connecting to the feed";
// 
//     public static final String postNotFound(String id) {
//         return "Post with id " + id + " not found";
//     }
// }
// 
// Path: src/main/java/org/ominidi/domain/model/Feed.java
// @Getter
// public class Feed<Post> implements Iterable<Post> {
//     private final List<Post> posts;
//     private final String nextUrl;
//     private final String prevUrl;
//     private final Integer size;
// 
//     public Feed(List<Post> posts, String nextUrl, String prevUrl) {
//         this.posts = posts;
//         this.size = posts.size();
//         this.nextUrl = nextUrl;
//         this.prevUrl = prevUrl;
//     }
// 
//     @Override
//     public Iterator<Post> iterator() {
//         return posts.iterator();
//     }
// 
//     public Integer size() {
//         return posts.size();
//     }
// }
// 
// Path: src/main/java/org/ominidi/domain/model/Post.java
// @Getter
// public class Post {
//     private final String id;
//     private final String objectId;
//     private final String createdTime;
//     private final String type;
//     private final String link;
//     private final String permalinkUrl;
//     private final String picture;
//     private final String fullPicture;
//     private final String message;
// 
//     public Post(
//             String id,
//             String objectId,
//             String createdTime,
//             String type,
//             String link,
//             String permalinkUrl,
//             String picture,
//             String fullPicture,
//             String message
//     ) {
//         this.id = id;
//         this.objectId = objectId;
//         this.createdTime = createdTime;
//         this.type = type;
//         this.link = link;
//         this.permalinkUrl = permalinkUrl;
//         this.picture = picture;
//         this.fullPicture = fullPicture;
//         this.message = message;
//     }
// }
// 
// Path: src/main/java/org/ominidi/facebook/service/PageFeedService.java
// @Service
// public class PageFeedService implements FeedAware {
//     private ConnectionAware pageFeed;
// 
//     private FeedMapper feedMapper;
// 
//     private PostMapper postMapper;
// 
//     @Autowired
//     public PageFeedService(ConnectionAware pageFeed, FeedMapper feedMapper, PostMapper postMapper) {
//         this.pageFeed = pageFeed;
//         this.feedMapper = feedMapper;
//         this.postMapper = postMapper;
//     }
// 
//     @Override
//     public Optional<Feed<Post>> getFeed() {
//         try {
//             return Optional.of(feedMapper.fromType(pageFeed.getConnection()));
//         } catch (ConnectionException e) {
//             return Optional.empty();
//         }
//     }
// 
//     @Override
//     public Optional<Feed<Post>> getFeed(String feedUrl) {
//         try {
//             return Optional.of(feedMapper.fromType(pageFeed.getConnection(feedUrl)));
//         } catch (ConnectionException e) {
//             return Optional.empty();
//         }
//     }
// 
//     @Override
//     public Optional<Post> getPostById(String id) {
//         try {
//             return Optional.of(postMapper.fromType(pageFeed.getObject(id)));
//         } catch (ConnectionException e) {
//             return Optional.empty();
//         }
//     }
// }


// Path: src/main/java/org/ominidi/api/controller/FeedController.java
import org.ominidi.api.exception.ConnectionException;
import org.ominidi.api.exception.NotFoundException;
import org.ominidi.api.model.Errors;
import org.ominidi.domain.model.Feed;
import org.ominidi.domain.model.Post;
import org.ominidi.facebook.service.PageFeedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.Optional;

package org.ominidi.api.controller;



@RestController
@RequestMapping("/api/v1")
public class FeedController {

    private PageFeedService pageFeedService;

    @Autowired
    public FeedController(PageFeedService pageFeedService) {
        this.pageFeedService = pageFeedService;
    }

    @GetMapping(value = "/feed", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Feed<Post> getFeed(@RequestParam(value = "u", required = false) Optional<String> feedUrl) {
        Optional<Feed<Post>> result = feedUrl.isPresent()
                ? pageFeedService.getFeed(feedUrl.get())
                : pageFeedService.getFeed();

        return result.orElseThrow(() -> new ConnectionException(Errors.CONNECTION_PROBLEM));
    }


    @GetMapping(value = "/post/{id}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
