Skip to content

Commit

Permalink
Create API to fetch career page images and show them on career page
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-jagruti-a committed Nov 4, 2023
1 parent 704672f commit b382666
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 878 deletions.
63 changes: 0 additions & 63 deletions career/go.mod

This file was deleted.

753 changes: 0 additions & 753 deletions career/go.sum

This file was deleted.

24 changes: 9 additions & 15 deletions career/career.go → jobs/life_perks_images.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package career
package jobs

import (
"net/http"
Expand All @@ -9,28 +9,22 @@ import (
"github.com/jmoiron/sqlx"
)

type LifeatCanopas struct {
type LifePerksImages struct {
Id int `json:"id"`
ImageUrls string `json:"imageUrls"`
Index int `json:"index"`
}

type Perks struct {
Id int `json:"id"`
ImageUrls string `json:"imageUrls"`
Index int `json:"index"`
}

type LifeRepository struct {
type LifeandPerksRepository struct {
Db *sqlx.DB
}

func New(db *sqlx.DB) *LifeRepository {
return &LifeRepository{Db: db}
func NewLifePerksImages(db *sqlx.DB) *LifeandPerksRepository {
return &LifeandPerksRepository{Db: db}
}

func (repository *LifeRepository) LifeImages(c *gin.Context) {
lifeImages := []LifeatCanopas{}
func (repository *LifeandPerksRepository) LifeImages(c *gin.Context) {
lifeImages := []LifePerksImages{}
err := repository.Db.Select(&lifeImages, "SELECT l.id, l.imageUrls, l.index FROM lifeatcanopas l")
if err != nil {
log.Error(err)
Expand All @@ -40,8 +34,8 @@ func (repository *LifeRepository) LifeImages(c *gin.Context) {
c.JSON(http.StatusOK, lifeImages)
}

func (repository *LifeRepository) PerksImages(c *gin.Context) {
perksImages := []Perks{}
func (repository *LifeandPerksRepository) PerksImages(c *gin.Context) {
perksImages := []LifePerksImages{}
err := repository.Db.Select(&perksImages, "SELECT p.id, p.imageUrls, p.index FROM perks p")
if err != nil {
log.Error(err)
Expand Down
54 changes: 27 additions & 27 deletions career/career_test.go → jobs/life_perks_images_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package career
package jobs

import (
"net/http"
Expand All @@ -11,31 +11,31 @@ import (
"github.com/stretchr/testify/assert"
)

var repo *LifeRepository
var err error
var testDB *sqlx.DB
var l_repo *LifeandPerksRepository
var l_err error
var l_testDB *sqlx.DB

func TestInit(t *testing.T) {
testDB, err = utils.TestDB()
if err != nil {
t.Errorf("Error in initializing test DB: %v", err)
func TestInitLifePerksImages(t *testing.T) {
l_testDB, l_err = utils.TestDB()
if l_err != nil {
t.Errorf("Error in initializing test DB: %v", l_err)
}

repo = New(testDB)
l_repo = NewImages(l_testDB)
}

func TestGetAllLifeImages(t *testing.T) {
utils.TruncateTables(testDB)
err = utils.CreateTables(testDB)
if err != nil {
t.Errorf("Error in initializing test DB: %v", err)
utils.TruncateTables(l_testDB)
l_err = utils.CreateTables(l_testDB)
if l_err != nil {
t.Errorf("Error in initializing test DB: %v", l_err)
}
utils.PrepareTablesData(testDB)
utils.PrepareTablesData(l_testDB)
engine := gin.New()
engine.GET("/api/lifeimages", repo.LifeImages)
req, err := http.NewRequest("GET", "/api/lifeimages", nil)
if err != nil {
t.Errorf("Error in creating request: %v", err)
engine.GET("/api/lifeimages", l_repo.LifeImages)
req, l_err := http.NewRequest("GET", "/api/lifeimages", nil)
if l_err != nil {
t.Errorf("Error in creating request: %v", l_err)
}
w := httptest.NewRecorder()
engine.ServeHTTP(w, req)
Expand All @@ -47,17 +47,17 @@ func TestGetAllLifeImages(t *testing.T) {
}

func TestGetAllPerksImages(t *testing.T) {
utils.TruncateTables(testDB)
err = utils.CreateTables(testDB)
if err != nil {
t.Errorf("Error in initializing test DB: %v", err)
utils.TruncateTables(l_testDB)
l_err = utils.CreateTables(l_testDB)
if l_err != nil {
t.Errorf("Error in initializing test DB: %v", l_err)
}
utils.PrepareTablesData(testDB)
utils.PrepareTablesData(l_testDB)
engine := gin.New()
engine.GET("/api/perkimages", repo.PerksImages)
req, err := http.NewRequest("GET", "/api/perkimages", nil)
if err != nil {
t.Errorf("Error in creating request: %v", err)
engine.GET("/api/perkimages", l_repo.PerksImages)
req, l_err := http.NewRequest("GET", "/api/perkimages", nil)
if l_err != nil {
t.Errorf("Error in creating request: %v", l_err)
}
w := httptest.NewRecorder()
engine.ServeHTTP(w, req)
Expand Down
7 changes: 3 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"blogs"
"career"
"contact"
"context"
"contribution"
Expand Down Expand Up @@ -59,7 +58,7 @@ func setupRouter() *gin.Engine {
sitemapRepo := sitemap.New(jobsRepo)
leaveRepo := leave.New(templateFS, utilsRepo)
notificationRepo := notification.New(templateFS, utilsRepo)
careerRepo := career.New(sqlDb)
lifePerksImagesRepo := jobs.NewLifePerksImages(sqlDb)

router.POST("/api/send-contact-mail", contactRepo.SendContactMail)

Expand Down Expand Up @@ -89,9 +88,9 @@ func setupRouter() *gin.Engine {
})
})

router.GET("/api/lifeimages", careerRepo.LifeImages)
router.GET("/api/lifeimages", lifePerksImagesRepo.LifeImages)

router.GET("/api/perksimages", careerRepo.PerksImages)
router.GET("/api/perksimages", lifePerksImagesRepo.PerksImages)

return router
}
Expand Down
25 changes: 12 additions & 13 deletions nuxt-frontend/components/jobs/PerksAndBenefits.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default {
title: "",
icon: "",
bgColor: "transparent",
image: ["", ""],
image: [],
description: "",
},
{
Expand All @@ -112,7 +112,7 @@ export default {
title: "",
icon: "",
bgColor: "transparent",
image: ["", ""],
image: [],
description: "",
},
{
Expand All @@ -130,7 +130,7 @@ export default {
title: "",
icon: "",
bgColor: "transparent",
image: ["", ""],
image: [],
description: "",
},
{
Expand All @@ -148,7 +148,7 @@ export default {
title: "",
icon: "",
bgColor: "transparent",
image: ["", ""],
image: [],
description: "",
},
{
Expand All @@ -166,7 +166,7 @@ export default {
title: "",
icon: "",
bgColor: "transparent",
image: ["", ""],
image: [],
description: "",
},
{
Expand All @@ -184,7 +184,7 @@ export default {
title: "",
icon: "",
bgColor: "transparent",
image: ["", ""],
image: [],
description: "",
},
{
Expand All @@ -202,7 +202,7 @@ export default {
title: "",
icon: "",
bgColor: "transparent",
image: ["", ""],
image: [],
description: "",
},
{
Expand All @@ -220,12 +220,11 @@ export default {
title: "",
icon: "",
bgColor: "transparent",
image: ["", ""],
image: [],
description: "",
},
],
isMobile: false,
slides: [],
};
},
components: {
Expand All @@ -246,13 +245,13 @@ export default {
async fetchImages() {
try {
const response = await axios.get(config.API_BASE + "/api/perksimages");
this.slides = getDiffrentWidthImages(response);
var slides = getDiffrentWidthImages(response);
this.perks.forEach((perk, index) => {
if (index % 2 === 0 && index / 2 < this.slides.length) {
if (index % 2 === 0 && index / 2 < slides.length) {
const slideIndex = Math.floor(index / 2);
perk.image = [
this.slides[slideIndex].image[0],
this.slides[slideIndex].image[1],
slides[slideIndex].image[0],
slides[slideIndex].image[1],
];
}
});
Expand Down
5 changes: 2 additions & 3 deletions nuxt-frontend/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function setGithubStars(contributions, githubRepos) {
.filter(
(repo) =>
repo.name ==
contribution.link.slice(contribution.link.lastIndexOf("/") + 1),
contribution.link.slice(contribution.link.lastIndexOf("/") + 1)
)
.map((repo) => repo.stargazers_count.toString())[0];
});
Expand Down Expand Up @@ -77,7 +77,7 @@ function getJobDates() {
currentDay <= maxDays
? startDateOfMonth
: new Date(
startDateOfMonth.setDate(startDateOfMonth.getDate() + maxDays),
startDateOfMonth.setDate(startDateOfMonth.getDate() + maxDays)
);

const datePosted = jobPosted.toISOString().split("T")[0];
Expand Down Expand Up @@ -112,5 +112,4 @@ export {
unescapeHTML,
getJobDates,
getDiffrentWidthImages,
parseImageUrls,
};

0 comments on commit b382666

Please sign in to comment.