diff --git a/src/database/Database.go b/src/database/Database.go index ff271cbb6f8f3e66d21f4f0ce671a42588d1ff98..f063fa7c60faccc376da57f6150296ea51e915db 100644 --- a/src/database/Database.go +++ b/src/database/Database.go @@ -23,7 +23,7 @@ func initialize() { sslMode := os.Getenv("SSL_MODE") print(host) - dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=%s", host, user, pass, name, port,sslMode) + dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=%s", host, user, pass, name, port, sslMode) print(dsn) dbInstance, err = gorm.Open(postgres.Open(dsn), &gorm.Config{}) @@ -45,6 +45,8 @@ func initialize() { dbInstance.AutoMigrate(&models.BatchSidang{}) dbInstance.AutoMigrate(&models.JadwalSidang{}) dbInstance.AutoMigrate(&models.JadwalSeminar{}) + + dbInstance.AutoMigrate(&models.Pendaftaran{}) } func GetInstance() *gorm.DB { diff --git a/src/handler/handler.go b/src/handler/handler.go index d7c8ee8d99483060de631af54349d9a3eca63715..fe4c124974d27ba382b4ad9ea9752c7bc902340f 100644 --- a/src/handler/handler.go +++ b/src/handler/handler.go @@ -12,6 +12,8 @@ import ( jadwalSeminarTransport "gitlab.informatika.org/k-01-11/graduit-be/src/module/jadwal_seminar/transport" jadwalSidangConfig "gitlab.informatika.org/k-01-11/graduit-be/src/module/jadwal_sidang/config" jadwalSidangTransport "gitlab.informatika.org/k-01-11/graduit-be/src/module/jadwal_sidang/transport" + pendaftaranConfig "gitlab.informatika.org/k-01-11/graduit-be/src/module/pendaftaran/config" + pendaftaranTransport "gitlab.informatika.org/k-01-11/graduit-be/src/module/pendaftaran/transport" statusMahasiswaConfig "gitlab.informatika.org/k-01-11/graduit-be/src/module/status_mahasiswa/config" statusMahasiswaTransport "gitlab.informatika.org/k-01-11/graduit-be/src/module/status_mahasiswa/transport" systemLogConfig "gitlab.informatika.org/k-01-11/graduit-be/src/module/system_log/config" @@ -21,15 +23,16 @@ import ( ) type Service struct { - InternalSystemLogHandler *systemLogTransport.InternalSystemLogHandler - AdminSytemLogHandler *systemLogTransport.AdminSystemLogHandler - AdminBimbinganLogHandler *bimbinganLogTransport.AdminBimbinganLogHandler + InternalSystemLogHandler *systemLogTransport.InternalSystemLogHandler + AdminSytemLogHandler *systemLogTransport.AdminSystemLogHandler + AdminBimbinganLogHandler *bimbinganLogTransport.AdminBimbinganLogHandler AdminTopicAllocationHandler *topicAllocationTransport.AdminTopicAllocationHandler BatchSeminarHandler *batchSeminarTransport.AdminBatchSeminarHandler BatchSidangHandler *batchSidangTransport.AdminBatchSidangHandler JadwalSidangHandler *jadwalSidangTransport.AdminJadwalSidangHandler JadwalSeminarHandler *jadwalSeminarTransport.AdminJadwalSeminarHandler AdminStatusMahasiswaHandler *statusMahasiswaTransport.AdminStatusMahasiswaHandler + AdminPendaftaranHandler *pendaftaranTransport.AdminPendaftaranHandler } func MakeHandler() *Service { @@ -50,7 +53,7 @@ func MakeHandler() *Service { }) AdminTopicAllocationHandler := topicAllocationTransport.NewAdminTopicAllocationHandler(topicAllocationConfig.TopicAllocationTransportConfig{ DBWrite: dbWrite, - DBRead: dbRead, + DBRead: dbRead, }) AdminBatchSeminarHandler := batchSeminarTransport.NewAdminBatchSeminarHandler(batchSeminarConfig.BatchSeminarTransportConfig{ DBWrite: dbWrite, @@ -72,17 +75,21 @@ func MakeHandler() *Service { DBWrite: dbWrite, DBRead: dbRead, }) - + AdminPendaftaranHandler := pendaftaranTransport.NewAdminPendaftaranHandler(pendaftaranConfig.PendaftaranTransportConfig{ + DBWrite: dbWrite, + DBRead: dbRead, + }) + return &Service{ - InternalSystemLogHandler: InternalSystemLogHandler, - AdminSytemLogHandler: AdminSystemLogHandler, - AdminBimbinganLogHandler: AdminBimbinganLogHandler, + InternalSystemLogHandler: InternalSystemLogHandler, + AdminSytemLogHandler: AdminSystemLogHandler, + AdminBimbinganLogHandler: AdminBimbinganLogHandler, AdminTopicAllocationHandler: AdminTopicAllocationHandler, BatchSeminarHandler: AdminBatchSeminarHandler, BatchSidangHandler: AdminBatchSidangHandler, JadwalSidangHandler: AdminJadwalSidangHandler, JadwalSeminarHandler: AdminJadwalSeminarHandler, AdminStatusMahasiswaHandler: AdminStatusMahasiswaHandler, - + AdminPendaftaranHandler: AdminPendaftaranHandler, } } diff --git a/src/handler/server.go b/src/handler/server.go index 3fb18a9e2dd02bb812ad7e9f975d38c0ff603db0..67cb667285c8a6cf650fd07e86b484bb668a6f8b 100644 --- a/src/handler/server.go +++ b/src/handler/server.go @@ -29,6 +29,7 @@ func (s *Service) InitializeRoutes() *echo.Echo { s.JadwalSeminarHandler.MountAdmin(adminGroup) s.JadwalSidangHandler.MountAdmin(adminGroup) s.AdminStatusMahasiswaHandler.MountAdmin(adminGroup) + s.AdminPendaftaranHandler.MountAdmin(adminGroup) return e } diff --git a/src/module/pendaftaran/config/common.go b/src/module/pendaftaran/config/common.go new file mode 100644 index 0000000000000000000000000000000000000000..a24500e1b7a4b9c7e1ad162aa70475e59aaf49a1 --- /dev/null +++ b/src/module/pendaftaran/config/common.go @@ -0,0 +1,8 @@ +package config + +import "gorm.io/gorm" + +type PendaftaranTransportConfig struct { + DBWrite *gorm.DB + DBRead *gorm.DB +} diff --git a/src/module/pendaftaran/entity/pendaftaran.go b/src/module/pendaftaran/entity/pendaftaran.go new file mode 100644 index 0000000000000000000000000000000000000000..89162099e1be43c6d842c00977177b28bb25392e --- /dev/null +++ b/src/module/pendaftaran/entity/pendaftaran.go @@ -0,0 +1,36 @@ +package entity + +import "time" + +type Pendaftaran struct { + Id string `gorm:"type:uuid;primaryKey;default:gen_random_uuid();unique"` // UUID as a string + IdTopik string + IdMahasiswa string + IdDosen string + Status *bool `gorm:"default:null"` + InterviewAt *time.Time `gorm:"default:null"` + DecidedAt *time.Time `gorm:"default:null"` + CreatedAt time.Time `gorm:"autoCreateTime"` // Use this if you want to override the gorm.Model's CreatedAt + UpdatedAt time.Time `gorm:"autoUpdateTime"` // Use this if you want to override the gorm.Model's UpdatedAt +} + +type ParamValues struct { + Limit int + Offset int +} + +type PendaftaranAddRequest struct { + IdTopik string + IdMahasiswa string + IdDosen string +} + +type UpdatePendaftaranRequest struct { + Id string + Status bool +} + +type WaktuInterviewUpdateRequest struct { + Id string + InterviewAt time.Time +} diff --git a/src/module/pendaftaran/internal/repository/pendaftaran.go b/src/module/pendaftaran/internal/repository/pendaftaran.go new file mode 100644 index 0000000000000000000000000000000000000000..fa6712c6d373e68addb7f6b5be77ba0274443c25 --- /dev/null +++ b/src/module/pendaftaran/internal/repository/pendaftaran.go @@ -0,0 +1,104 @@ +package repository + +import ( + "time" + + "github.com/google/uuid" + "gitlab.informatika.org/k-01-11/graduit-be/src/module/pendaftaran/entity" + "gorm.io/gorm" +) + +type PendaftaranRepo struct { + DBWrite *gorm.DB + DBRead *gorm.DB +} + +func NewPendaftaranRepository(dbWrite *gorm.DB, dbRead *gorm.DB) *PendaftaranRepo { + return &PendaftaranRepo{ + DBWrite: dbWrite, + DBRead: dbRead, + } +} + +func (repo *PendaftaranRepo) NewPendaftaran(pendaftaran entity.Pendaftaran) (output entity.Pendaftaran, err error) { + pendaftaran.Id = uuid.New().String() + pendaftaran.CreatedAt = time.Now() + pendaftaran.UpdatedAt = time.Now() + + result := repo.DBWrite.Create(&pendaftaran) + if result.Error != nil { + return entity.Pendaftaran{}, result.Error + } + return pendaftaran, nil +} + +func (repo *PendaftaranRepo) GetPendaftaran() (output []entity.Pendaftaran, err error) { + var batches []entity.Pendaftaran + result := repo.DBRead.Find(&batches) + if result.Error != nil { + return nil, err + } + return batches, nil +} + +func (repo *PendaftaranRepo) DeletePendaftaran(id string) (entity.Pendaftaran, error) { + batch := entity.Pendaftaran{Id: id} + err := repo.DBWrite.Delete(&batch).Error + + if err != nil { + return batch, err + } + + return batch, err +} + +func (repo *PendaftaranRepo) GetPendaftaranByIdDosen(id string) (output []entity.Pendaftaran, err error) { + var pendaftaran []entity.Pendaftaran + result := repo.DBRead.Where("id = ?", id).Find(&pendaftaran) + if result.Error != nil { + return nil, err + } + return pendaftaran, nil +} + +func (repo *PendaftaranRepo) SetStatus(id string, val bool) (output []entity.Pendaftaran, err error) { + var pendaftaran entity.Pendaftaran + result := repo.DBRead.Where("id = ?", id).First(&pendaftaran) + if result.Error != nil { + return nil, result.Error + } + + pendaftaran.Status = &val + pendaftaran.UpdatedAt = time.Now() + if val { + now := time.Now() + pendaftaran.DecidedAt = &now + } else { + pendaftaran.DecidedAt = nil + } + + result = repo.DBRead.Save(&pendaftaran) + if result.Error != nil { + return nil, result.Error + } + + return []entity.Pendaftaran{pendaftaran}, nil +} + +func (repo *PendaftaranRepo) SetTimeInterview(id string, val time.Time) (output []entity.Pendaftaran, err error) { + var pendaftaran entity.Pendaftaran + result := repo.DBRead.Where("id = ?", id).First(&pendaftaran) + if result.Error != nil { + return nil, result.Error + } + + pendaftaran.UpdatedAt = time.Now() + pendaftaran.InterviewAt = &val + + result = repo.DBRead.Save(&pendaftaran) + if result.Error != nil { + return nil, result.Error + } + + return []entity.Pendaftaran{pendaftaran}, nil +} diff --git a/src/module/pendaftaran/internal/usecase/pendaftaran.go b/src/module/pendaftaran/internal/usecase/pendaftaran.go new file mode 100644 index 0000000000000000000000000000000000000000..4970769f4ac95f4c1076798be18ab2e18b528d5e --- /dev/null +++ b/src/module/pendaftaran/internal/usecase/pendaftaran.go @@ -0,0 +1,57 @@ +package usecase + +import ( + "time" + + "gitlab.informatika.org/k-01-11/graduit-be/src/module/pendaftaran/entity" +) + +type PendaftaranUsecase interface { + AddPendaftaran(pendaftaran entity.Pendaftaran) (entity.Pendaftaran, error) + GetPendaftaran() ([]entity.Pendaftaran, error) + DeletePendaftaran(id string) (entity.Pendaftaran, error) + GetPendaftaranByIdDosen(id string) ([]entity.Pendaftaran, error) + UpdateStatusPendaftaran(id string, val bool) ([]entity.Pendaftaran, error) + UpdateWaktuInterview(id string, val time.Time) ([]entity.Pendaftaran, error) +} + +type PendaftaranUc struct { + pendaftaranRepo PendaftaranRepository +} + +func NewPendaftaranUseCase(pendaftaranRepo PendaftaranRepository) *PendaftaranUc { + return &PendaftaranUc{ + pendaftaranRepo: pendaftaranRepo, + } +} + +func (uc *PendaftaranUc) AddPendaftaran(pendaftaran entity.Pendaftaran) (entity.Pendaftaran, error) { + newPendaftaran, err := uc.pendaftaranRepo.NewPendaftaran(pendaftaran) + + if err != nil { + return newPendaftaran, err + } + + return newPendaftaran, nil + +} + +func (uc *PendaftaranUc) GetPendaftaran() ([]entity.Pendaftaran, error) { + return uc.pendaftaranRepo.GetPendaftaran() +} + +func (uc *PendaftaranUc) DeletePendaftaran(id string) (entity.Pendaftaran, error) { + return uc.pendaftaranRepo.DeletePendaftaran(id) +} + +func (uc *PendaftaranUc) GetPendaftaranByIdDosen(id string) ([]entity.Pendaftaran, error) { + return uc.pendaftaranRepo.GetPendaftaranByIdDosen(id) +} + +func (uc *PendaftaranUc) UpdateStatusPendaftaran(id string, val bool) ([]entity.Pendaftaran, error) { + return uc.pendaftaranRepo.SetStatus(id, val) +} + +func (uc *PendaftaranUc) UpdateWaktuInterview(id string, val time.Time) ([]entity.Pendaftaran, error) { + return uc.pendaftaranRepo.SetTimeInterview(id, val) +} diff --git a/src/module/pendaftaran/internal/usecase/repository.go b/src/module/pendaftaran/internal/usecase/repository.go new file mode 100644 index 0000000000000000000000000000000000000000..1a1b3d8c3acb5dbda8140e76afc0761b2cd4366a --- /dev/null +++ b/src/module/pendaftaran/internal/usecase/repository.go @@ -0,0 +1,16 @@ +package usecase + +import ( + "time" + + "gitlab.informatika.org/k-01-11/graduit-be/src/module/pendaftaran/entity" +) + +type PendaftaranRepository interface { + NewPendaftaran(pendaftaran entity.Pendaftaran) (output entity.Pendaftaran, err error) + GetPendaftaran() (output []entity.Pendaftaran, err error) + DeletePendaftaran(id string) (entity.Pendaftaran, error) + GetPendaftaranByIdDosen(id string) (output []entity.Pendaftaran, err error) + SetStatus(id string, val bool) (output []entity.Pendaftaran, err error) + SetTimeInterview(id string, val time.Time) (output []entity.Pendaftaran, err error) +} diff --git a/src/module/pendaftaran/transport/admin_handler.go b/src/module/pendaftaran/transport/admin_handler.go new file mode 100644 index 0000000000000000000000000000000000000000..22fe498a0df31a69b2721ef261c051a88f816d57 --- /dev/null +++ b/src/module/pendaftaran/transport/admin_handler.go @@ -0,0 +1,112 @@ +package transport + +import ( + "net/http" + + "github.com/labstack/echo" + "gitlab.informatika.org/k-01-11/graduit-be/src/module/pendaftaran/config" + "gitlab.informatika.org/k-01-11/graduit-be/src/module/pendaftaran/entity" + "gitlab.informatika.org/k-01-11/graduit-be/src/module/pendaftaran/internal/repository" + "gitlab.informatika.org/k-01-11/graduit-be/src/module/pendaftaran/internal/usecase" + "gitlab.informatika.org/k-01-11/graduit-be/src/utils" +) + +type AdminPendaftaranHandler struct { + pendaftaranUsecase usecase.PendaftaranUsecase +} + +func NewAdminPendaftaranHandler(cfg config.PendaftaranTransportConfig) *AdminPendaftaranHandler { + pendaftaranRepository := repository.NewPendaftaranRepository(cfg.DBWrite, cfg.DBRead) + pendaftaranUsecase := usecase.NewPendaftaranUseCase(pendaftaranRepository) + + return &AdminPendaftaranHandler{ + pendaftaranUsecase: pendaftaranUsecase, + } + +} + +func (t *AdminPendaftaranHandler) MountAdmin(group *echo.Group) { + group.POST("/pendaftaran", t.AddPendaftaran) + group.GET("/pendaftaran-get", t.GetPendaftaran) + group.GET("/pendaftaran-get-by-dosen", t.GetPendaftaranByIdDosen) + group.GET("/pendaftaran-delete", t.DeletePendaftaran) + group.POST("/pendaftaran-update-status", t.UpdateStatusPendaftaran) + group.POST("/pendaftaran-update-interview", t.UpdateWaktuInterview) +} + +func (t *AdminPendaftaranHandler) AddPendaftaran(c echo.Context) error { + request := new(entity.PendaftaranAddRequest) + if err := c.Bind(&request); err != nil { + return c.JSON(http.StatusBadRequest, utils.ResponseDetailOutput(false, http.StatusBadRequest, err.Error(), nil)) + } + + target := &entity.Pendaftaran{ + IdTopik: request.IdTopik, + IdMahasiswa: request.IdMahasiswa, + IdDosen: request.IdDosen, + } + + newPendaftaran, err := t.pendaftaranUsecase.AddPendaftaran(*target) + if err != nil { + return c.JSON(http.StatusInternalServerError, utils.ResponseDetailOutput(false, http.StatusInternalServerError, err.Error(), nil)) + } + + return c.JSON(http.StatusOK, utils.ResponseDetailOutput(true, http.StatusCreated, "Pendaftaran added successfully", newPendaftaran)) +} + +func (t *AdminPendaftaranHandler) GetPendaftaran(c echo.Context) error { + listGroupLimit, err := t.pendaftaranUsecase.GetPendaftaran() + if err != nil { + return c.JSON(http.StatusBadRequest, utils.ResponseDetailOutput(false, http.StatusBadRequest, err.Error(), nil)) + } + + return c.JSON(http.StatusOK, utils.ResponseDetailOutput(true, http.StatusOK, "Pendaftaran successfully retreived", listGroupLimit)) +} + +func (t *AdminPendaftaranHandler) GetPendaftaranByIdDosen(c echo.Context) error { + id := c.QueryParam("id") + listGroupLimit, err := t.pendaftaranUsecase.GetPendaftaranByIdDosen(id) + if err != nil { + return c.JSON(http.StatusBadRequest, utils.ResponseDetailOutput(false, http.StatusBadRequest, err.Error(), nil)) + } + + return c.JSON(http.StatusOK, utils.ResponseDetailOutput(true, http.StatusOK, "Pendaftaran successfully retreived", listGroupLimit)) +} + +func (t *AdminPendaftaranHandler) DeletePendaftaran(c echo.Context) error { + id := c.QueryParam("id") + listGroupLimit, err := t.pendaftaranUsecase.DeletePendaftaran(id) + if err != nil { + return c.JSON(http.StatusBadRequest, utils.ResponseDetailOutput(false, http.StatusBadRequest, err.Error(), nil)) + } + + return c.JSON(http.StatusOK, utils.ResponseDetailOutput(true, http.StatusOK, "Pendaftaran successfully deleted", listGroupLimit)) +} + +func (t *AdminPendaftaranHandler) UpdateStatusPendaftaran(c echo.Context) error { + request := new(entity.UpdatePendaftaranRequest) + if err := c.Bind(&request); err != nil { + return c.JSON(http.StatusBadRequest, utils.ResponseDetailOutput(false, http.StatusBadRequest, err.Error(), nil)) + } + + newPendaftaran, err := t.pendaftaranUsecase.UpdateStatusPendaftaran(request.Id, request.Status) + if err != nil { + return c.JSON(http.StatusInternalServerError, utils.ResponseDetailOutput(false, http.StatusInternalServerError, err.Error(), nil)) + } + + return c.JSON(http.StatusOK, utils.ResponseDetailOutput(true, http.StatusCreated, "Pendaftaran status updated successfully", newPendaftaran)) +} + +func (t *AdminPendaftaranHandler) UpdateWaktuInterview(c echo.Context) error { + request := new(entity.WaktuInterviewUpdateRequest) + if err := c.Bind(&request); err != nil { + return c.JSON(http.StatusBadRequest, utils.ResponseDetailOutput(false, http.StatusBadRequest, err.Error(), nil)) + } + + newPendaftaran, err := t.pendaftaranUsecase.UpdateWaktuInterview(request.Id, request.InterviewAt) + if err != nil { + return c.JSON(http.StatusInternalServerError, utils.ResponseDetailOutput(false, http.StatusInternalServerError, err.Error(), nil)) + } + + return c.JSON(http.StatusOK, utils.ResponseDetailOutput(true, http.StatusCreated, "Pendaftaran interview time updated successfully", newPendaftaran)) +}