Skip to content

Commit

Permalink
Add feature for viewing inactive HRs
Browse files Browse the repository at this point in the history
  • Loading branch information
bmerchant22 committed Aug 12, 2023
1 parent cde7332 commit acde24e
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/ras-backend.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions company/admin.HR.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,22 @@ func addHRHandler(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{"status": "Successfully added"})

}

func getInactiveHRsHandler(ctx *gin.Context) {
var HR []CompanyHR

cid, err := strconv.ParseUint(ctx.Param("cid"), 10, 32)
if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

err = getInactiveHR(ctx, uint(cid), &HR)

if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

ctx.JSON(http.StatusOK, HR)
}
7 changes: 6 additions & 1 deletion company/db.hr.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package company
import "github.com/gin-gonic/gin"

func getAllHRUserDB(ctx *gin.Context, HRs *[]CompanyHR) error {
tx := db.WithContext(ctx).Select("ID","CreatedAt","UpdatedAt","DeletedAt","Name","Email","Phone").Find(HRs)
tx := db.WithContext(ctx).Select("ID", "CreatedAt", "UpdatedAt", "DeletedAt", "Name", "Email", "Phone").Find(HRs)
return tx.Error
}

Expand All @@ -17,6 +17,11 @@ func addHR(ctx *gin.Context, HR *CompanyHR) error {
return tx.Error
}

func getInactiveHR(ctx *gin.Context, cid uint, HR *[]CompanyHR) error {
tx := db.WithContext(ctx).Unscoped().Where("company_id = ?", cid).Find(HR)
return tx.Error
}

func deleteHR(ctx *gin.Context, id uint) error {
tx := db.WithContext(ctx).Delete(&CompanyHR{}, "id = ?", id)
return tx.Error
Expand Down
1 change: 1 addition & 0 deletions company/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Company struct {

type CompanyHR struct {
gorm.Model
DeletedAt gorm.DeletedAt
CompanyID uint `json:"company_id"`
Company Company `gorm:"foreignkey:CompanyID" json:"-"`
Name string `json:"name"`
Expand Down
1 change: 1 addition & 0 deletions company/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func AdminRouter(r *gin.Engine) {
admin.GET("/:cid/history", ras.PlaceHolderController)
admin.PUT("/:cid/history/:hid", ras.PlaceHolderController)
admin.DELETE("/:cid/history/:hid", ras.PlaceHolderController)
admin.GET("/:cid/inactive-hrs", getInactiveHRsHandler)
}
}

Expand Down
2 changes: 1 addition & 1 deletion container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RUN go mod download && go mod verify

COPY . .

RUN cp $GOPATH/src/github.com/spo-iitk/ras-backend/secret.yml.template $GOPATH/src/github.com/spo-iitk/ras-backend/secret.yml
#RUN #cp $GOPATH/src/github.com/spo-iitk/ras-backend/secret.yml.template $GOPATH/src/github.com/spo-iitk/ras-backend/secret.yml

# Configure nginx
RUN rm /etc/nginx/sites-enabled/default
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
networks:
- default
ports:
- "80"
- "80:80"
volumes:
- ./:/go/src/github.com/spo-iitk/ras-backend
privileged: true
Expand Down

0 comments on commit acde24e

Please sign in to comment.