diff --git a/src/module/dashboard_tim_tugas/entity/dashboard_tim_tugas.go b/src/module/dashboard_tim_tugas/entity/dashboard_tim_tugas.go index 34b9c47477dae9ff72a5902df0c73937710769a6..2cca700b99c699fc34a638b6265af89fb8a8ae7c 100644 --- a/src/module/dashboard_tim_tugas/entity/dashboard_tim_tugas.go +++ b/src/module/dashboard_tim_tugas/entity/dashboard_tim_tugas.go @@ -36,13 +36,6 @@ type Pendaftaran struct { IdPeriode string } -type Mahasiswa struct { - Name string `gorm:"size:100"` - NIM string `gorm:"size:8"` - IdMahasiswa string `gorm:"index;primaryKey"` - IdDosen string `gorm:"default:null"` -} - type Topik struct { Id string `gorm:"type:uuid;primaryKey;default:gen_random_uuid()"` // UUID as a string Judul string @@ -64,4 +57,24 @@ type PeriodPendaftaran struct { type PeriodStats struct { Period PeriodPendaftaran `json:"period"` NumMahasiswa int64 `json:"count_mahasiswa"` +} + +type StatMahasiswa struct { + NIM string `json:"nim"` + Nama string `json:"nama"` + Pengajuan bool `json:"pengajuan"` + Seminar bool `json:"seminar"` + Sidang bool `json:"sidang"` +} + +type Pengguna struct { + ID string `json:"id"` + Name string `json:"nama"` + NIM string `json:"nim"` + Email string `json:"email"` + Roles string `json:"roles"` +} + +type PendaftaranTA struct { + } \ No newline at end of file diff --git a/src/module/dashboard_tim_tugas/internal/repository/dashboard_tim_tugas.go b/src/module/dashboard_tim_tugas/internal/repository/dashboard_tim_tugas.go index 82b15723d55ef929015ece7994e7564076888c01..8d900daea585eb4f912e052e1b3ab87dd59b20b8 100644 --- a/src/module/dashboard_tim_tugas/internal/repository/dashboard_tim_tugas.go +++ b/src/module/dashboard_tim_tugas/internal/repository/dashboard_tim_tugas.go @@ -91,10 +91,10 @@ func (repo *DashboardTimTugasRepo) GetDaftarMahasiswa(periode string) (output [] } for _, pendaftaran := range pendaftarans { - var mahasiswa entity1.Mahasiswa + var mahasiswa entity1.Pengguna var topik entity1.Topik - repo.DBRead.Where("id_mahasiswa = ?", pendaftaran.IdMahasiswa).First(&mahasiswa) + repo.DBRead.Where("id = ?", pendaftaran.IdMahasiswa).First(&mahasiswa) repo.DBRead.Where("id = ?", pendaftaran.IdTopik).First(&topik) output = append(output, entity1.DataPendaftaranMahasiswa{ @@ -138,3 +138,7 @@ func (repo *DashboardTimTugasRepo) GetPeriodData() (output []entity1.PeriodStats return periodStats, nil } + +// func (repo *DashboardTimTugasRepo) GetStatsDaftarMahasiswa() (output []entity1.StatMahasiswa, err error) { +// var pendaftaran_ta entity1.PendaftaranTA +// } \ No newline at end of file diff --git a/src/module/dashboard_tim_tugas/internal/usecase/dashboard_tim_tugas.go b/src/module/dashboard_tim_tugas/internal/usecase/dashboard_tim_tugas.go index 63fbf4e303794ae3fb1d4779abc5997df28e0df0..723ceffc959a4f5d4bfac5c3e567cc352f3a4765 100644 --- a/src/module/dashboard_tim_tugas/internal/usecase/dashboard_tim_tugas.go +++ b/src/module/dashboard_tim_tugas/internal/usecase/dashboard_tim_tugas.go @@ -86,4 +86,8 @@ func (uc *DashboardTimTugasUc) GetDaftarMahasiswa() ([]entity.DataPendaftaranMah func (uc *DashboardTimTugasUc) GetPeriodData() ([]entity.PeriodStats, error) { return uc.dashboardTimTugasRepo.GetPeriodData() -} \ No newline at end of file +} + +// func (uc *DashboardTimTugasUc) GetStatsDaftarMahasiswa() ([]entity.StatMahasiswa, error) { +// return uc.dashboardTimTugasRepo.GetStatsDaftarMahasiswa() +// } \ No newline at end of file diff --git a/src/module/dashboard_tim_tugas/internal/usecase/repository.go b/src/module/dashboard_tim_tugas/internal/usecase/repository.go index 21bc8cca9c943ef8754e40affd88653a7e8d8742..c9a84424679a3bbd85a724cc3b3f1f9fe3daa119 100644 --- a/src/module/dashboard_tim_tugas/internal/usecase/repository.go +++ b/src/module/dashboard_tim_tugas/internal/usecase/repository.go @@ -6,4 +6,5 @@ type DashboardTimTugasRepo interface { GetDashboardStatistics(periode string) (output entity.StatusStatistics, err error) GetDaftarMahasiswa(periode string) (output []entity.DataPendaftaranMahasiswa, err error) GetPeriodData() (output []entity.PeriodStats, err error) + // GetStatsDaftarMahasiswa() (output []entity.StatMahasiswa, err error) } \ No newline at end of file diff --git a/src/module/dashboard_tim_tugas/transport/admin_handler.go b/src/module/dashboard_tim_tugas/transport/admin_handler.go index 8904ff54fc882c8f80de2c0ad5e38920399c64ec..887e7c7deecb7552be6ccab47bbe24beb5364702 100644 --- a/src/module/dashboard_tim_tugas/transport/admin_handler.go +++ b/src/module/dashboard_tim_tugas/transport/admin_handler.go @@ -30,6 +30,7 @@ func NewDashboardTimTugasHandler(cfg config.DashboardTimTugasTransportConfig) *A func (admin *AdminDashboardTimTugasHandler) MountAdmin(group *echo.Group) { group.GET("/statistics-dashboard-tim-tugas", admin.GetDashboardStatistics) group.GET("/period-data", admin.GetPeriodData) + // group.GET("/stats-mahasiswa", admin.GetStatsDaftarMahasiswa) } // GetDashboardStatistics retrieves the tim tugas dashboard data and statistics. @@ -72,4 +73,8 @@ func (admin *AdminDashboardTimTugasHandler) GetPeriodData(c echo.Context) error } return c.JSON(http.StatusOK, utils.ResponseDetailOutput(true, http.StatusOK, "Period data retrieved", periodStats)) -} \ No newline at end of file +} + +// func (admin *AdminDashboardTimTugasHandler) GetStatsDaftarMahasiswa(c echo.Context) error { + +// } \ No newline at end of file diff --git a/src/module/topic_allocation/entity/topic_allocation.go b/src/module/topic_allocation/entity/topic_allocation.go index 4bc16cc71170849384ab446988f3b0e779b7674c..e979c6ad6364509823472a57258db30515abbf9f 100644 --- a/src/module/topic_allocation/entity/topic_allocation.go +++ b/src/module/topic_allocation/entity/topic_allocation.go @@ -1,12 +1,38 @@ package entity type Topik struct { - Id string `json:"id"` - IdDosen string `json:"idDosen"` - NamaDosen string `json:"namaDosen"` + ID string `json:"id"` + Judul string `json:"judul"` + Deskripsi string `json:"deskripsi"` + PengajuID string `json:"pengaju"` + + Pengguna Pengguna `gorm:"foreignKey:PengajuID"` +} + +func (Topik) TableName() string { + return "topik" +} + +type Pengguna struct { + ID string `gorm:"type:uuid;primaryKey" json:"id"` + Nama string `json:"nama"` + Email string `json:"email"` + Roles string `json:"roles"` +} + +func (Pengguna) TableName() string { + return "pengguna" +} + +type GetAllReturnType struct { + DaftarTopikData []Topik `json:"data"` + MaxPage int `json:"maxPage"` +} + +type TopikPostPutReqData struct { Judul string `json:"judul"` Deskripsi string `json:"deskripsi"` - Periode string `json:"periode"` + PengajuID string `json:"pengajuID"` } type ParamValues struct { diff --git a/src/module/topic_allocation/internal/repository/topic_allocation.go b/src/module/topic_allocation/internal/repository/topic_allocation.go index f0c0a83f845ff6cc3d68b727fa6f055fdcd08615..79212600e4199a9b243c249fe283635bdde250a5 100644 --- a/src/module/topic_allocation/internal/repository/topic_allocation.go +++ b/src/module/topic_allocation/internal/repository/topic_allocation.go @@ -18,56 +18,75 @@ func NewTopicAllocationRepository(dbWrite *gorm.DB, dbRead *gorm.DB) *TopicAlloc } } -func (repo *TopicAllocationRepo) NewTopic(topic entity.Topik) (output entity.Topik, err error) { - topic.Id = uuid.New().String() +func (repo *TopicAllocationRepo) NewTopic(reqData entity.TopikPostPutReqData) (output entity.TopikPostPutReqData, err error) { + topic := entity.Topik{ + ID: uuid.New().String(), + Judul: reqData.Judul, + Deskripsi: reqData.Deskripsi, + PengajuID: reqData.PengajuID, + } result := repo.DBWrite.Create(&topic) if result.Error != nil { - return entity.Topik{}, result.Error + return entity.TopikPostPutReqData{}, result.Error } - return topic, nil + return reqData, nil } -func (repo *TopicAllocationRepo) GetTopic(page int, limit int, search string, id string, periode string) (output []entity.Topik, err error) { + +func (repo *TopicAllocationRepo) GetTopic(page int, limit int, search string, id string) (output entity.GetAllReturnType, err error) { var topics []entity.Topik - result := repo.DBRead.Find(&topics).Where("Periode = ?", periode) + result := repo.DBRead.Preload("Pengguna") + if search != "" { - result = result.Where("Judul LIKE ?", "%"+search+"%").Find(&topics) - if result.Error != nil { - return nil, result.Error - } + result = result.Where("judul LIKE ?", "%"+search+"%") } if id != "" { - result = result.Where("IdDosen = ?", id).Find(&topics) - if result.Error != nil { - return nil, result.Error - } + result = result.Where("pengaju_id = ?", id) } if page != 0 { - result = result.Offset((page - 1) * limit).Find(&topics) - if result.Error != nil { - return nil, result.Error - } + result = result.Offset((page - 1) * limit) } if limit != 0 { - result = result.Limit(limit).Find(&topics) - if result.Error != nil { - return nil, result.Error - } + result = result.Limit(limit) + } + + result = result.Find(&topics) + if result.Error != nil { + return entity.GetAllReturnType{}, result.Error + } + + var count int64 + res := result.Count(&count) + if res.Error != nil { + return entity.GetAllReturnType{}, res.Error + } + + var maxPage int + + if limit == 0 || count == 0 { + maxPage = 1 + } else { + maxPage = int(count) / limit + } + + data := entity.GetAllReturnType { + DaftarTopikData: topics, + MaxPage: maxPage, } - return topics, nil + return data, nil } func (repo *TopicAllocationRepo) GetTopicByID(ID string) (output entity.Topik, err error) { var topic entity.Topik - result := repo.DBRead.Where("Id = ?", ID).First(&topic) + result := repo.DBRead.Preload("Pengguna").Where("id = ?", ID).First(&topic) if result.Error != nil { return entity.Topik{}, result.Error } @@ -75,20 +94,29 @@ func (repo *TopicAllocationRepo) GetTopicByID(ID string) (output entity.Topik, e return topic, nil } -func (repo *TopicAllocationRepo) UpdateTopic(topic entity.Topik) (output entity.Topik, err error) { - result := repo.DBWrite.Save(&topic) +func (repo *TopicAllocationRepo) UpdateTopic(reqData entity.TopikPostPutReqData, id string) (output entity.TopikPostPutReqData, err error) { + var topic entity.Topik + topicResult := repo.DBWrite.First(&topic, "id = ?", id) + if topicResult.Error != nil { + return entity.TopikPostPutReqData{}, topicResult.Error + } + topic.Judul = reqData.Judul + topic.Deskripsi = reqData.Deskripsi + + result := repo.DBWrite.Save(&topic) if result.Error != nil { - return entity.Topik{}, result.Error + return entity.TopikPostPutReqData{}, result.Error } - return topic, nil + return reqData, nil } + func (repo *TopicAllocationRepo) DeleteTopic(ID string) (err error) { var topic entity.Topik - result := repo.DBWrite.Where("Id = ?", ID).Delete(&topic) + result := repo.DBWrite.Where("id = ?", ID).Delete(&topic) if result.Error != nil { return result.Error diff --git a/src/module/topic_allocation/internal/usecase/repository.go b/src/module/topic_allocation/internal/usecase/repository.go index 08a7d97fd4eb65c78f0bcb7fa55921982729b8fe..165f98f4d5c7da042a644911c63fa3bd01cb5566 100644 --- a/src/module/topic_allocation/internal/usecase/repository.go +++ b/src/module/topic_allocation/internal/usecase/repository.go @@ -3,9 +3,9 @@ package usecase import "gitlab.informatika.org/k-01-11/graduit-be/src/module/topic_allocation/entity" type TopicAllocationRepo interface { - NewTopic(topic entity.Topik) (output entity.Topik, err error) - GetTopic(page int, limit int, search string, id string, periode string) (output []entity.Topik, err error) + NewTopic(topic entity.TopikPostPutReqData) (output entity.TopikPostPutReqData, err error) + GetTopic(page int, limit int, search string, id string) (output entity.GetAllReturnType, err error) GetTopicByID(ID string) (output entity.Topik, err error) - UpdateTopic(topic entity.Topik) (output entity.Topik, err error) + UpdateTopic(topic entity.TopikPostPutReqData, id string) (output entity.TopikPostPutReqData, err error) DeleteTopic(ID string) (err error) } \ No newline at end of file diff --git a/src/module/topic_allocation/internal/usecase/topic_allocation.go b/src/module/topic_allocation/internal/usecase/topic_allocation.go index 994173ece18444cd735b17c7d841499bfb3b1d16..589038bf932bd38790a7cd8c463bdea25f9b8080 100644 --- a/src/module/topic_allocation/internal/usecase/topic_allocation.go +++ b/src/module/topic_allocation/internal/usecase/topic_allocation.go @@ -1,21 +1,15 @@ package usecase import ( - "encoding/json" - "fmt" - "io" - "net/http" - "os" - "gitlab.informatika.org/k-01-11/graduit-be/src/module/topic_allocation/entity" "gitlab.informatika.org/k-01-11/graduit-be/src/utils" ) type TopicUsecase interface { - AddTopic(topic []entity.Topik) ([]entity.Topik, error) - GetTopic(param utils.PageLimitSearchID) ([]entity.Topik, error) + AddTopic(topic []entity.TopikPostPutReqData) ([]entity.TopikPostPutReqData, error) + GetTopic(param utils.PageLimitSearchID) (entity.GetAllReturnType, error) GetTopicByID(param string) (entity.Topik, error) - UpdateTopic(topic entity.Topik) (entity.Topik, error) + UpdateTopic(topic entity.TopikPostPutReqData, id string) (entity.TopikPostPutReqData, error) DeleteTopic(param string) (error) } @@ -29,73 +23,30 @@ func NewTopicUc(topicAllocationRepo TopicAllocationRepo) *TopicUc { } } -func (uc *TopicUc) AddTopic(topics []entity.Topik) ([]entity.Topik, error) { - url := os.Getenv("S1_URL") - res, reqErr := http.Get(url + "/api/internal/batch-seminar-live") - if reqErr != nil { - return nil, reqErr - } - defer res.Body.Close() - - body, parseErr := io.ReadAll(res.Body) - if parseErr != nil { - return nil, parseErr - } - - var parsedRes map[string]interface{} - parsedErr := json.Unmarshal(body, &parsedRes) - if parsedErr != nil { - return nil, parsedErr - } - +func (uc *TopicUc) AddTopic(topics []entity.TopikPostPutReqData) ([]entity.TopikPostPutReqData, error) { for _, topic := range topics { _, err := uc.topicAllocationRepo.NewTopic(topic) if err != nil { - topic.Periode = fmt.Sprint(parsedRes["semester"]) + "-" + fmt.Sprint(parsedRes["year"]) - _, err := uc.topicAllocationRepo.NewTopic(topic) - if err != nil { - return nil, err - } + return nil, err } } return topics, nil } -func (uc *TopicUc) GetTopic(param utils.PageLimitSearchID) ([]entity.Topik, error) { - - url := os.Getenv("S1_URL") - res, reqErr := http.Get(url + "/api/internal/batch-seminar-live") - if reqErr != nil { - return nil, reqErr - } - defer res.Body.Close() - - body, parseErr := io.ReadAll(res.Body) - if parseErr != nil { - return nil, parseErr - } - - var parsedRes map[string]interface{} - parsedErr := json.Unmarshal(body, &parsedRes) - if parsedErr != nil { - return nil, parsedErr - } - - param.Periode = fmt.Sprint(parsedRes["semester"]) + "-" + fmt.Sprint(parsedRes["year"]) - - return uc.topicAllocationRepo.GetTopic(param.Page, param.Limit, param.Search, param.ID, param.Periode) +func (uc *TopicUc) GetTopic(param utils.PageLimitSearchID) (entity.GetAllReturnType, error) { + return uc.topicAllocationRepo.GetTopic(param.Page, param.Limit, param.Search, param.ID) } func (uc *TopicUc) GetTopicByID(param string) (entity.Topik, error) { return uc.topicAllocationRepo.GetTopicByID(param) } -func (uc *TopicUc) UpdateTopic(topic entity.Topik) (entity.Topik, error) { - updatedTopic, err := uc.topicAllocationRepo.UpdateTopic(topic) +func (uc *TopicUc) UpdateTopic(topic entity.TopikPostPutReqData, id string) (entity.TopikPostPutReqData, error) { + updatedTopic, err := uc.topicAllocationRepo.UpdateTopic(topic, id) if err != nil { - return entity.Topik{}, err + return entity.TopikPostPutReqData{}, err } return updatedTopic, nil diff --git a/src/module/topic_allocation/transport/admin_handler.go b/src/module/topic_allocation/transport/admin_handler.go index 4526fff160dc5fa24fe0b651357c2efa0bc4a61e..935aa707f91a16a72acf9124dc66d709afd7d7c4 100644 --- a/src/module/topic_allocation/transport/admin_handler.go +++ b/src/module/topic_allocation/transport/admin_handler.go @@ -92,12 +92,12 @@ func (admin *AdminTopicAllocationHandler) GetTopicByID(c echo.Context) error { // @Accept json // @Produce json // @Param topics body []entity.Topik true "Topic object to add" -// @Success 200 {object} []entity.Topik +// @Success 200 {object} []entity.TopikPostPutReqData // @Router /alokasi-topik [post] func (admin *AdminTopicAllocationHandler) AddTopic(c echo.Context) error { - var topics []entity.Topik + var topics []entity.TopikPostPutReqData - if err := c.Bind(topics); err != nil { + if err := c.Bind(&topics); err != nil { return c.JSON(http.StatusBadRequest, utils.ResponseDetailOutput(false, http.StatusBadRequest, err.Error(), nil)) } topics, err := admin.topicUsecase.AddTopic(topics) @@ -122,11 +122,10 @@ func (admin *AdminTopicAllocationHandler) UpdateTopic(c echo.Context) error { id := c.Param("id") if id != "" { - topic := new(entity.Topik) + topic := new(entity.TopikPostPutReqData) c.Bind(topic) - topic.Id = id - newItem, err := admin.topicUsecase.UpdateTopic(*topic) + newItem, err := admin.topicUsecase.UpdateTopic(*topic, id) if err != nil { return c.JSON(http.StatusInternalServerError, utils.ResponseDetailOutput(false, http.StatusInternalServerError, "Failed to update topic", nil))