api v1 work

This commit is contained in:
Jake Potrebic 2020-08-23 14:31:17 -07:00
parent 18589b0142
commit 9a9f7d8165
No known key found for this signature in database
GPG Key ID: 7C58557EC9C421F8
3 changed files with 19 additions and 4 deletions

View File

@ -11,6 +11,7 @@ import io.papermc.hangar.db.model.ProjectVersionsTable;
import io.papermc.hangar.db.model.ProjectsTable;
import io.papermc.hangar.db.model.UserProjectRolesTable;
import io.papermc.hangar.db.model.UsersTable;
import io.papermc.hangar.model.TagColor;
import io.papermc.hangar.model.Visibility;
import io.papermc.hangar.service.UserService;
import io.papermc.hangar.service.api.V1ApiService;
@ -42,6 +43,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.stream.Collector;
import java.util.stream.Collectors;
@ -136,13 +138,17 @@ public class Apiv1Controller extends HangarController {
}
@RequestMapping("/api/v1/tags/{tagId}")
public Object tagColor(@PathVariable Object tagId) {
return null; // TODO implement tagColor request controller
public ResponseEntity<ObjectNode> tagColor(@PathVariable("tagId") TagColor tag) {
ObjectNode tagColor = mapper.createObjectNode();
tagColor.set("id", mapper.valueToTree(tag.ordinal()));
tagColor.set("backgroundColor", mapper.valueToTree(tag.getBackground()));
tagColor.set("foregroundColor", mapper.valueToTree(tag.getForeground()));
return ResponseEntity.of(Optional.of(tagColor));
}
@RequestMapping("/api/v1/users")
public Object listUsers(@RequestParam Object limit, @RequestParam Object offset) {
return null; // TODO implement listUsers request controller
public ResponseEntity<ArrayNode> listUsers(@RequestParam(defaultValue = "0") int offset, @RequestParam(required = false) Integer limit) {
return ResponseEntity.of(Optional.of(writeUsers(v1ApiService.getUsers(offset, limit))));
}
@RequestMapping("/api/v1/users/{user}")

View File

@ -62,4 +62,8 @@ public interface V1ApiDao {
@RegisterBeanMapper(ProjectVersionTagsTable.class)
@SqlQuery("SELECT pv.id pv_id, pvt.* FROM project_version_tags pvt JOIN project_versions pv ON pv.id = pvt.version_id WHERE pv.visibility = 0 AND pv.id IN (<versionIds>)")
List<Map.Entry<Long, ProjectVersionTagsTable>> getVersionsTags(@BindList(onEmpty = EmptyHandling.NULL_STRING) List<Long> versionIds);
@RegisterBeanMapper(UsersTable.class)
@SqlQuery("SELECT * FROM users OFFSET :offset LIMIT :limit")
List<UsersTable> getUsers(int offset, Integer limit);
}

View File

@ -31,6 +31,11 @@ public class V1ApiService {
return v1ApiDao.get().getProjectsForUsers(userIds).stream().collect(Collectors.groupingBy(ProjectsTable::getOwnerId));
}
public List<UsersTable> getUsers(int offset, Integer limit) {
return v1ApiDao.get().getUsers(offset, limit);
}
// TODO better way for this?
public Map<Long, List<String>> getStarredPlugins(List<Long> userIds) {
return v1ApiDao.get().getStarredPlugins(userIds).stream()