aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/main/java/com/juick/server/api/activity/Info.java
blob: 4cff15c102c3c3951dc7433d7e9bfa1fbe0e457b (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
36
37
38
39
40
41
42
43
44
package com.juick.server.api.activity;

import com.juick.User;
import com.juick.server.api.activity.model.ActivityObject;
import com.juick.server.api.activity.model.Person;
import com.juick.server.util.HttpNotFoundException;
import com.juick.service.UserService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.UriComponentsBuilder;

import javax.inject.Inject;

@RestController
public class Info {
    @Inject
    private UserService userService;
    @Value("${web_domain:localhost}")
    private String domain;
    @Value("${ap_base_uri:http://localhost:8080/}")
    private String baseUri;
    @Value("${img_url:http://localhost:8080/i/}")
    private String baseImagesUri;

    @GetMapping(value = "/u/{userName}", produces = ActivityObject.CONTENT_TYPE)
    public Person getUser(@PathVariable String userName) {
        User user = userService.getUserByName(userName);
        if (!user.isAnonymous()) {
            Person person = new Person();
            UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(baseUri);
            builder.path(String.format("/u/%s", userName));
            person.setId(builder.toUriString());
            person.setName(userName);
            person.setOutbox(builder.path(String.format("/u/%s/blog", userName)).toUriString());
            UriComponentsBuilder imgBuilder = UriComponentsBuilder.fromUriString(baseImagesUri);
            imgBuilder.path(String.format("/a/%d.png", user.getUid()));
            person.setIcon(imgBuilder.toUriString());
            return person;
        }
        throw new HttpNotFoundException();
    }
}