Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/main/java/com/openelements/issues/ApiEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;
import java.util.stream.Collectors;

@RestController
@CrossOrigin
public class ApiEndpoint {
Expand All @@ -22,12 +25,16 @@ public class ApiEndpoint {

private final GitHubCache issueCache;

public ApiEndpoint(@NonNull final GitHubCache issueCache) {
this.issueCache = Objects.requireNonNull(issueCache, "issueCache must not be null");
public ApiEndpoint(final GitHubCache issueCache) {
this.issueCache = issueCache;
}

@Deprecated(forRemoval = true)
private record OldIssueResponse(@NonNull String title, @NonNull String link, @NonNull String org, @NonNull String repo, @NonNull String imageUrl, @NonNull String identifier, boolean isAssigned, boolean isClosed, @NonNull List<String> labels, @NonNull List<String> languageTags) {
@GetMapping("/api/v2/contributors")
public Set<Contributor> getContributors() {
log.info("Getting contributors with additional metadata");
return issueCache.getContributors().stream()
.peek(contributor -> log.debug("Contributor: {}", contributor))
.collect(Collectors.toUnmodifiableSet());
}

/**
Expand Down
15 changes: 9 additions & 6 deletions src/main/resources/static/contributors.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ <h1 class="text-3xl font-bold mb-6 text-center">Contributors</h1>

async function fetchContributors() {
const response = await fetch('/api/v2/contributors');
const contributors = await response.json();
return contributors;
if (!response.ok) {
throw new Error('Failed to fetch contributors');
}
return response.json();
}

// Function to render issues into the table
Expand All @@ -41,9 +43,10 @@ <h1 class="text-3xl font-bold mb-6 text-center">Contributors</h1>
const listItem = document.createElement('li');
listItem.classList.add('flex', 'justify-center');
listItem.innerHTML = `<a target="_blank" href="https://github.com/${contributor.userName}">
<div class="flex flex-col justify-center">
<div class="flex flex-col justify-center items-center">
<img class="rounded-full h-32 w-32 bg-slate-600 p-0.5 grow" src="${contributor.avatarUrl}" alt="Avatar of ${contributor.userName}">
<span class="text-center">${contributor.userName}</span>
<span class="text-center mt-2 font-medium">${contributor.userName}</span>
<span class="text-center text-sm text-gray-500">${contributor.contributions} Contributions</span>
</div>
</a>
`;
Expand All @@ -55,14 +58,14 @@ <h1 class="text-3xl font-bold mb-6 text-center">Contributors</h1>
document.addEventListener('DOMContentLoaded', async () => {
const loadingElement = document.getElementById('loading');
const listElement = document.getElementById('contributors-list');
let contributors = [];
try {
contributors = await fetchContributors();
const contributors = await fetchContributors();
renderContributors(contributors);
loadingElement.classList.add('hidden');
listElement.classList.remove('hidden');
} catch (error) {
loadingElement.textContent = 'Failed to load data. Please try again later.';
console.error(error);
}
});
</script>
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
<body>

<div class="container mx-auto py-10">
<h1 class="text-4xl font-bold text-center">Welcome to OpenElements</h1>
<p class="text-center mt-4">Explore our contributors and projects.</p>

<div class="mt-10 flex justify-center">
<a href="contributors.html" class="px-6 py-3 bg-blue-500 text-white rounded hover:bg-blue-700">
View Contributors
</a>
</div>
<div class="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8">
<div class="mx-auto max-w-3xl">
<h1 class="text-3xl font-bold mb-6 text-center">Good First Issues</h1>
Expand Down