Skip to content

Commit

Permalink
added past hires in master company
Browse files Browse the repository at this point in the history
  • Loading branch information
yashlm committed Jun 19, 2024
1 parent 28170a6 commit 7eb3ac0
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 0 deletions.
58 changes: 58 additions & 0 deletions application/db.student.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,64 @@ func createEventStudents(ctx *gin.Context, eventStudents *[]EventStudent) error
return tx.Error
}

func getCompanyRecruitmentStats(ctx *gin.Context, cid uint, stats *[]statsResponse) error {
tx := db.WithContext(ctx).Model(&EventStudent{}).
Joins("JOIN proforma_events ON proforma_events.name IN ? AND proforma_events.id = event_students.proforma_event_id", []EventType{Recruited, PIOPPOACCEPTED}).
Joins("JOIN proformas ON proformas.id = proforma_events.proforma_id AND proformas.company_recruitment_cycle_id = ?", cid).
Select("event_students.student_recruitment_cycle_id, proformas.company_name, proformas.profile ,proforma_events.name as type").
Order("event_students.student_recruitment_cycle_id").
Find(stats)
return tx.Error
}
func fetchCompanyRecruitCount(ctx *gin.Context, cids []uint) (map[uint]int, error) {
resultCounts := make(map[uint]int)

var stats []companyRecruitResponce
tx := db.WithContext(ctx).Model(&EventStudent{}).
Joins("JOIN proforma_events ON proforma_events.name IN ? AND proforma_events.id = event_students.proforma_event_id", []EventType{Recruited, PIOPPOACCEPTED}).
Joins("JOIN proformas ON proformas.id = proforma_events.proforma_id").
Where("proformas.company_recruitment_cycle_id IN ?", cids).
Select("proformas.company_recruitment_cycle_id, COUNT(*) as count").
Group("proformas.company_recruitment_cycle_id").
Order("proformas.company_recruitment_cycle_id").
Find(&stats)

if tx.Error != nil {
return nil, tx.Error
}

// Populate resultCounts map
for _, stat := range stats {
resultCounts[stat.CompanyRecruitmentCycleID] = stat.Count
}

return resultCounts, nil
}

func fetchCompanyPPOCount(ctx *gin.Context, cids []uint) (map[uint]int, error) {
resultCounts := make(map[uint]int)

var stats []companyRecruitResponce
tx := db.WithContext(ctx).Model(&EventStudent{}).
Joins("JOIN proforma_events ON proforma_events.name IN ? AND proforma_events.id = event_students.proforma_event_id", []EventType{PIOPPOACCEPTED}).
Joins("JOIN proformas ON proformas.id = proforma_events.proforma_id").
Where("proformas.company_recruitment_cycle_id IN ?", cids).
Select("proformas.company_recruitment_cycle_id, COUNT(*) as count").
Group("proformas.company_recruitment_cycle_id").
Order("proformas.company_recruitment_cycle_id").
Find(&stats)

if tx.Error != nil {
return nil, tx.Error
}

for _, stat := range stats {
resultCounts[stat.CompanyRecruitmentCycleID] = stat.Count
}

return resultCounts, nil
}

func getRecruitmentStats(ctx *gin.Context, rid uint, stats *[]statsResponse) error {
tx := db.WithContext(ctx).Model(&EventStudent{}).
Joins("JOIN proforma_events ON proforma_events.name IN ? AND proforma_events.id = event_students.proforma_event_id", []EventType{Recruited, PIOPPOACCEPTED}).
Expand Down
2 changes: 2 additions & 0 deletions application/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ func AdminRouter(mail_channel chan mail.Mail, r *gin.Engine) {
admin.DELETE("event/:eid/student/:sid", deleteStudentFromEventHandler)

admin.GET("/company/:cid/proforma", getProformaByCompanyHandler)
admin.GET("/company/:cid/stats", getCompanyRecruitStatsHandler)
admin.POST("/company/count", fetchCompanyRecruitCountHandler)

admin.GET("/proforma", getAllProformasHandler)
admin.POST("/proforma", postProformaHandler)
Expand Down
79 changes: 79 additions & 0 deletions application/stats.recruitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,85 @@ type statsRecruitmentResponse struct {
Type string `json:"type"`
}

type companyRecruitResponce struct {
CompanyRecruitmentCycleID uint `json:"company_recruitment_cycle_id"`
Count int `json:"count"`
}

func fetchCompanyRecruitCountHandler(c *gin.Context) {
var cids []uint

if err := c.ShouldBindJSON(&cids); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request format"})
return
}

recruitCounts, err := fetchCompanyRecruitCount(c, cids)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Internal Server Error"})
return
}
ppoCounts, err := fetchCompanyPPOCount(c, cids)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Internal Server Error"})
return
}

c.JSON(http.StatusOK, gin.H{"recruitCounts": recruitCounts, "ppoCount": ppoCounts})
}

func getCompanyRecruitStatsHandler(ctx *gin.Context) {
cid, err := util.ParseUint(ctx.Param("cid"))
if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

var stats []statsResponse
err = getCompanyRecruitmentStats(ctx, cid, &stats)

if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
var srids []uint
for _, stat := range stats {
srids = append(srids, stat.StudentRecruitmentCycleID)
}

var students []rc.StudentRecruitmentCycle
err = rc.FetchStudentBySRID(ctx, srids, &students)
if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

var studentsMap = make(map[uint]*rc.StudentRecruitmentCycle)
for i := range students {
studentsMap[students[i].ID] = &students[i]
}

var studentResponse []statsRecruitmentResponse
for _, stat := range stats {
student := studentsMap[stat.StudentRecruitmentCycleID]
res := statsRecruitmentResponse{
ID: student.ID,
Name: student.Name,
Email: student.Email,
RollNo: student.RollNo,
ProgramDepartmentID: student.ProgramDepartmentID,
SecondaryProgramDepartmentID: student.SecondaryProgramDepartmentID,
CompanyName: stat.CompanyName,
Profile: stat.Profile,
Type: stat.Type,
}
studentResponse = append(studentResponse, res)
}

ctx.JSON(http.StatusOK, gin.H{"student": studentResponse})

}

func getStatsHandler(ctx *gin.Context) {
rid, err := util.ParseUint(ctx.Param("rid"))
if err != nil {
Expand Down
40 changes: 40 additions & 0 deletions rc/admin.company.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,46 @@ type addNewCompanyRequest struct {
Comments string `json:"comments"`
}

type StatResponse struct {
ID uint `json:"id"`
RecruitmentCycleID uint `json:"recruitment_cycle_id"`
Type string `json:"type"`
Phase string `json:"phase"`
}
type CompanyAllRecruitmentCycle struct {
ID uint `json:"id"`
RecruitmentCycleID uint `json:"recruitment_cycle_id"`
Type string `json:"type"`
Phase string `json:"phase"`
}

func getCompanyAllRCID(ctx *gin.Context) {
cid, err := util.ParseUint(ctx.Param("cid"))
if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
var stats []CompanyAllRecruitmentCycle
err = fetchCompanyAllRecruitmentCycles(ctx, cid, &stats)
if err != nil {
ctx.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
var countResponse []CompanyAllRecruitmentCycle

for _, stat := range stats {
countResponse = append(countResponse, CompanyAllRecruitmentCycle{
ID: stat.ID,
RecruitmentCycleID: stat.RecruitmentCycleID,
Type: stat.Type,
Phase: stat.Phase,
})
}

ctx.JSON(http.StatusOK, countResponse)

}

func postNewCompanyHandler(ctx *gin.Context) {
var addNewCompany addNewCompanyRequest

Expand Down
11 changes: 11 additions & 0 deletions rc/db.company.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ func deleteRCCompany(ctx *gin.Context, cid uint) error {
return tx.Error
}

func fetchCompanyAllRecruitmentCycles(ctx *gin.Context, companyID uint, stats *[]CompanyAllRecruitmentCycle) 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").
Joins("JOIN recruitment_cycles ON company_recruitment_cycles.recruitment_cycle_id = recruitment_cycles.id").
Where("company_recruitment_cycles.company_id = ?", companyID).
Find(stats)

return tx.Error
}

func FetchCompanyHistory(ctx *gin.Context, companyID uint, companyHistory *[]CompanyHistory) error {
tx := db.WithContext(ctx).
Table("company_recruitment_cycles").
Expand Down
1 change: 1 addition & 0 deletions rc/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func AdminRouter(mail_channel chan mail.Mail, r *gin.Engine) {
admin.GET("/company/:cid", getCompanyHandler)
admin.DELETE("/company/:cid", deleteCompanyHandler)
admin.GET("/company/:cid/history", getCompanyHistoryHandler)
admin.GET("/company/:cid/ids", getCompanyAllRCID)

admin.GET("/student", getAllStudentsHandler)

Expand Down

0 comments on commit 7eb3ac0

Please sign in to comment.