-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create API to fetch career page images and show them on career page
- Loading branch information
1 parent
342e40e
commit 42e983b
Showing
62 changed files
with
307 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package jobs | ||
|
||
import ( | ||
"net/http" | ||
|
||
log "github.com/sirupsen/logrus" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/jmoiron/sqlx" | ||
) | ||
|
||
type LifePerksImages struct { | ||
Id int `json:"id"` | ||
ImageUrls string `json:"image_urls"` | ||
Index int `json:"index"` | ||
} | ||
|
||
type LifeandPerksRepository struct { | ||
Db *sqlx.DB | ||
} | ||
|
||
func NewLifePerksImages(db *sqlx.DB) *LifeandPerksRepository { | ||
return &LifeandPerksRepository{Db: db} | ||
} | ||
|
||
func (repository *LifeandPerksRepository) LifeImages(c *gin.Context) { | ||
lifeImages := []LifePerksImages{} | ||
err := repository.Db.Select(&lifeImages, "SELECT l.id, l.image_urls, l.index FROM lifeatcanopas l") | ||
if err != nil { | ||
log.Error(err) | ||
c.AbortWithStatus(http.StatusInternalServerError) | ||
return | ||
} | ||
c.JSON(http.StatusOK, lifeImages) | ||
} | ||
|
||
func (repository *LifeandPerksRepository) PerksImages(c *gin.Context) { | ||
perksImages := []LifePerksImages{} | ||
err := repository.Db.Select(&perksImages, "SELECT p.id, p.image_urls, p.index FROM perks p") | ||
if err != nil { | ||
log.Error(err) | ||
c.AbortWithStatus(http.StatusInternalServerError) | ||
return | ||
} | ||
c.JSON(http.StatusOK, perksImages) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package jobs | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
"utils" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/jmoiron/sqlx" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var l_repo *LifeandPerksRepository | ||
var l_err error | ||
var l_testDB *sqlx.DB | ||
|
||
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) | ||
} | ||
|
||
l_repo = NewLifePerksImages(l_testDB) | ||
} | ||
|
||
func TestGetAllLifeImages(t *testing.T) { | ||
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(l_testDB) | ||
engine := gin.New() | ||
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) | ||
|
||
assert.EqualValues(t, http.StatusOK, w.Code) | ||
got := utils.GotArrayData(w, t) | ||
expected := []interface{}{expectedLifeImages()} | ||
assert.Equal(t, expected, got) | ||
} | ||
|
||
func TestGetAllPerksImages(t *testing.T) { | ||
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(l_testDB) | ||
engine := gin.New() | ||
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) | ||
|
||
assert.EqualValues(t, http.StatusOK, w.Code) | ||
got := utils.GotArrayData(w, t) | ||
expected := []interface{}{expectedPerkImages()} | ||
assert.Equal(t, expected, got) | ||
} | ||
func expectedLifeImages() map[string]interface{} { | ||
lifeImages := make(map[string]interface{}) | ||
lifeImages["id"] = 1.0 | ||
lifeImages["image_urls"] = "https://canopas-website.s3.ap-south-1.amazonaws.com/lifeCanopas/1-400.webp,https://canopas-website.s3.ap-south-1.amazonaws.com/lifeCanopas/1-800.webp,https://canopas-website.s3.ap-south-1.amazonaws.com/lifeCanopas/1-1600.webp" | ||
lifeImages["index"] = 0.0 | ||
return lifeImages | ||
} | ||
func expectedPerkImages() map[string]interface{} { | ||
perkImages := make(map[string]interface{}) | ||
perkImages["id"] = 1.0 | ||
perkImages["image_urls"] = "https://canopas-website.s3.ap-south-1.amazonaws.com/lifeCanopas/1-400.webp,https://canopas-website.s3.ap-south-1.amazonaws.com/lifeCanopas/1-800.webp" | ||
perkImages["index"] = 0.0 | ||
return perkImages | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.