Skip to content

Commit

Permalink
Merge pull request #148 from yashlm/CompanyHistory
Browse files Browse the repository at this point in the history
Added Company HIstory in Master Database(Company) section
  • Loading branch information
Krishnansh5 authored Feb 9, 2024
2 parents fd3973d + 02abb9d commit b1aee0a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
27 changes: 26 additions & 1 deletion rc/admin.company.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package rc
import (
"net/http"
"strconv"

"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"github.com/spo-iitk/ras-backend/middleware"
Expand Down Expand Up @@ -137,3 +136,29 @@ func deleteCompanyHandler(ctx *gin.Context) {

ctx.JSON(http.StatusOK, gin.H{"status": "Company Deleted from this RC"})
}

func getCompanyHistoryHandler(ctx *gin.Context) {
var companyHistory []CompanyHistory
cid, err := strconv.ParseUint(ctx.Param("cid"), 10, 32)
if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

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

var historyResponse []CompanyHistoryResponse
for _, history := range companyHistory {
historyResponse = append(historyResponse, CompanyHistoryResponse{
ID: history.ID,
RecruitmentCycleID: history.RecruitmentCycleID,
Comments: history.Comments,
})
}

ctx.JSON(http.StatusOK, historyResponse)
}
17 changes: 17 additions & 0 deletions rc/db.company.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rc

import "github.com/gin-gonic/gin"
import "fmt"

func fetchAllCompanies(ctx *gin.Context, rid string, companies *[]CompanyRecruitmentCycle) error {
tx := db.WithContext(ctx).Where("recruitment_cycle_id = ?", rid).Find(companies)
Expand Down Expand Up @@ -54,3 +55,19 @@ func deleteRCCompany(ctx *gin.Context, cid uint) error {
tx := db.WithContext(ctx).Where("id = ?", cid).Delete(&CompanyRecruitmentCycle{})
return tx.Error
}

func FetchCompanyHistory(ctx *gin.Context, companyID uint, companyHistory *[]CompanyHistory) error {
tx := db.WithContext(ctx).
Table("company_recruitment_cycles").
Select("company_recruitment_cycles.id, company_recruitment_cycles.recruitment_cycle_id, recruitment_cycles.type, recruitment_cycles.phase, company_recruitment_cycles.comments").
Joins("JOIN recruitment_cycles ON company_recruitment_cycles.recruitment_cycle_id = recruitment_cycles.id").
Where("company_recruitment_cycles.company_id = ?", companyID).
Find(companyHistory)

if tx.Error != nil {
fmt.Println("Error fetching company history:", tx.Error)
return tx.Error
}

return nil
}
14 changes: 14 additions & 0 deletions rc/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,17 @@ type StudentRecruitmentCycleResume struct {
Verified sql.NullBool `json:"verified" gorm:"default:NULL"`
ActionTakenBy string `json:"action_taken_by"`
}

type CompanyHistory struct {
ID uint `json:"id" gorm:"column:id"`
RecruitmentCycleID uint `json:"recruitment_cycle_id" gorm:"column:recruitment_cycle_id"`
Type string `json:"type" gorm:"column:type"`
Phase string `json:"phase" gorm:"column:phase"`
Comments string `json:"comments" gorm:"column:comments"`
}

type CompanyHistoryResponse struct {
ID uint `json:"id" gorm:"column:id"`
RecruitmentCycleID uint `json:"recruitmentCycleID" gorm:"column:recruitment_cycle_id"`
Comments string `json:"comments" gorm:"column:comments"`
}
1 change: 1 addition & 0 deletions rc/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func AdminRouter(mail_channel chan mail.Mail, r *gin.Engine) {
admin.PUT("/company", putCompanyHandler)
admin.GET("/company/:cid", getCompanyHandler)
admin.DELETE("/company/:cid", deleteCompanyHandler)
admin.GET("/company/:cid/history", getCompanyHistoryHandler)

admin.GET("/student", getAllStudentsHandler)

Expand Down

0 comments on commit b1aee0a

Please sign in to comment.