Skip to content

Commit

Permalink
Added struct for representing Github API response
Browse files Browse the repository at this point in the history
  • Loading branch information
metamemelord committed Mar 13, 2024
1 parent 22f19b3 commit c11945c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
10 changes: 10 additions & 0 deletions model/repository.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package model

type Repository struct {
Name string `json:"name"`
Description string `json:"description"`
Language string `json:"language"`
PushedAt string `json:"pushed_at"`
HtmlUrl string `json:"html_url"`
Fork bool `json:"fork"`
}
8 changes: 6 additions & 2 deletions pkg/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"log"
"net/http"
"sort"
"sync"

"github.com/metamemelord/portfolio-website/model"
Expand All @@ -12,7 +13,7 @@ import (
var githubWPMutex sync.Mutex

type Data struct {
GithubData []interface{}
GithubData []*model.Repository
WordpressData []*model.Post
}

Expand All @@ -35,12 +36,15 @@ func githubPackageRefresher() {
return
}
defer resp.Body.Close()
githubResponse := []interface{}{}
githubResponse := []*model.Repository{}
err = json.NewDecoder(resp.Body).Decode(&githubResponse)
if err != nil {
log.Println("Error while unmarshalling Github response", err)
return
}
sort.Slice(githubResponse, func(i, j int) bool {
return githubResponse[i].PushedAt > githubResponse[j].PushedAt
})
githubWPMutex.Lock()
data.GithubData = githubResponse
githubWPMutex.Unlock()
Expand Down
2 changes: 1 addition & 1 deletion src/components/Home components/Github/ProjectCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="github__card-technology-label">
<span>{{cardData.language}}</span>
</div>
<span>{{cardData.updated_at|getLastUpdateTime}}</span>
<span>{{cardData.pushed_at|getLastUpdateTime}}</span>
<a :href="cardData.html_url" target="_blank" rel="noopener noreferrer">
<button>Checkout</button>
</a>
Expand Down
10 changes: 1 addition & 9 deletions src/components/Home components/Github/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,7 @@ export default {
},
computed: {
ownedRepos() {
let ownedRepos = this.repos.filter(repo => !repo.fork);
ownedRepos.sort((repo1, repo2) => {
let key1 = moment().diff(repo1.updated_at);
let key2 = moment().diff(repo2.updated_at);
if (key1 > key2) return 1;
if (key1 < key2) return -1;
return 0;
});
return ownedRepos;
return this.repos.filter(repo => !repo.fork);
},
forkedRepos() {
return this.repos.filter(repo => repo.fork);
Expand Down

0 comments on commit c11945c

Please sign in to comment.