aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src/main/java/com/juick/api/Subscriptions.java
blob: 49990080a23353173298b66aba10d9a044343e8d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.juick.api;

import com.juick.User;
import com.juick.json.UserSerializer;
import com.juick.server.SubscriptionsQueries;
import com.juick.server.UserQueries;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created by vitalyster on 24.10.2016.
 */
public class Subscriptions {
    JdbcTemplate jdbc;

    public Subscriptions(JdbcTemplate jdbc) {
        this.jdbc = jdbc;
    }
    public void doGet(HttpServletRequest request, HttpServletResponse response, int vuid) throws IOException {
        User visitor = UserQueries.getUserByUID(jdbc, vuid).orElse(new User());
        if (!(visitor.getUID() > 0) && !(visitor.getUName().equals("juick"))) {
            response.sendError(403);
        }
        int uid = NumberUtils.toInt(request.getParameter("uid"), 0);
        int mid = NumberUtils.toInt(request.getParameter("mid"), 0);
        List<User> users = SubscriptionsQueries.getSubscribedUsers(jdbc, uid, mid);
        UserSerializer userSerializer = new UserSerializer();
        Main.replyJSON(request, response, userSerializer.serializeList(users));
    }
}