Skip to content
Snippets Groups Projects
Commit 99cf4b7b authored by Fajar Herawan's avatar Fajar Herawan
Browse files

Merge branch 'story/status-log' into 'main'

Story/status log

See merge request !23
parents 447c4179 da59d339
1 merge request!23Story/status log
...@@ -6,7 +6,7 @@ stages: # List of stages for jobs, and their order of execution ...@@ -6,7 +6,7 @@ stages: # List of stages for jobs, and their order of execution
test-job: test-job:
stage: test stage: test
rules: rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == 'staging' || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == 'production') - if: $CI_PIPELINE_SOURCE == 'merge_request_event' && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == 'main' || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == 'production')
script: script:
- echo 'Testing' - echo 'Testing'
...@@ -20,7 +20,7 @@ build-job: # This job runs in the build stage, which runs first. ...@@ -20,7 +20,7 @@ build-job: # This job runs in the build stage, which runs first.
services: services:
- name: 'docker:dind' - name: 'docker:dind'
rules: rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == 'production' - if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == 'main'
before_script: before_script:
- apk add --no-cache curl jq python3 py3-pip - apk add --no-cache curl jq python3 py3-pip
- python3 -m venv awscli-env - python3 -m venv awscli-env
...@@ -41,14 +41,16 @@ deploy-job: ...@@ -41,14 +41,16 @@ deploy-job:
image: alpine:latest image: alpine:latest
when: on_success when: on_success
rules: rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == 'production' - if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == 'main'
before_script: before_script:
- 'command -v ssh-agent >/dev/null || ( apk add --update openssh )' - 'command -v ssh-agent >/dev/null || ( apk add --update openssh )'
- eval $(ssh-agent -s) - eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh - mkdir -p ~/.ssh
- chmod 700 ~/.ssh - chmod 700 ~/.ssh
- touch ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts - chmod 644 ~/.ssh/known_hosts
- echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts # You may need to add you
script: script:
- ssh $SSH_USER@$VM_IPADDRESS "" - ssh $SSH_USER@$VM_IPADDRESS ""
- ssh $SSH_USER@$VM_IPADDRESS "hostname && echo 'Welcome!!!' > log.txt && echo 'Command executed successfully.' >> log.txt" - ssh $SSH_USER@$VM_IPADDRESS "hostname && echo 'Welcome!!!' > log.txt && echo 'Command executed successfully.' >> log.txt"
......
version: "3.8" version: "3.8"
services: services:
graduit_server:
build: .
ports:
- 8080:8080
hostname: graduit_server
env_file: .env
volumes:
- ./:/usr/app
- /usr/app/db-data
restart: always
depends_on:
- graduit_db
- s2_db
s2_db: s2_db:
image: postgres:alpine image: postgres:alpine
......
...@@ -36,6 +36,10 @@ type UpdateStatusRequest struct { ...@@ -36,6 +36,10 @@ type UpdateStatusRequest struct {
Status bool `json:"status"` Status bool `json:"status"`
} }
type BimbinganLogStatus struct {
Status bool `json:"status"`
LogBimbingan []BimbinganLogBerkas `json:"bimbingan_logs"`
}
type InfoTopikMahasiswa struct { type InfoTopikMahasiswa struct {
IDMahasiswa string `json:"id_mahasiswa"` IDMahasiswa string `json:"id_mahasiswa"`
Nama string `json:"nama"` Nama string `json:"nama"`
......
package usecase package usecase
import ( import (
"math"
"time"
"gitlab.informatika.org/k-01-11/graduit-be/src/module/bimbingan_log/entity" "gitlab.informatika.org/k-01-11/graduit-be/src/module/bimbingan_log/entity"
"gitlab.informatika.org/k-01-11/graduit-be/src/utils" "gitlab.informatika.org/k-01-11/graduit-be/src/utils"
) )
...@@ -10,6 +13,7 @@ type BimbinganLogUsecase interface { ...@@ -10,6 +13,7 @@ type BimbinganLogUsecase interface {
GetBimbinganLog(param utils.LimitOffset, idMahasiswa string) ([]entity.BimbinganLogBerkas, error) GetBimbinganLog(param utils.LimitOffset, idMahasiswa string) ([]entity.BimbinganLogBerkas, error)
UpdateBimbinganLogStatus(id string, status bool) error UpdateBimbinganLogStatus(id string, status bool) error
GetInfoTopikMahasiswa(idMahasiswa string) (entity.InfoTopikMahasiswa, error) GetInfoTopikMahasiswa(idMahasiswa string) (entity.InfoTopikMahasiswa, error)
GetBimbinganLogStatusByStudentId(param utils.LimitOffset, idMahasiswa string)(entity.BimbinganLogStatus,error)
} }
type BimbinganLogUc struct { type BimbinganLogUc struct {
...@@ -53,3 +57,64 @@ func (uc *BimbinganLogUc) UpdateBimbinganLogStatus(id string, status bool) error ...@@ -53,3 +57,64 @@ func (uc *BimbinganLogUc) UpdateBimbinganLogStatus(id string, status bool) error
func (uc *BimbinganLogUc) GetInfoTopikMahasiswa(idMahasiswa string) (entity.InfoTopikMahasiswa, error) { func (uc *BimbinganLogUc) GetInfoTopikMahasiswa(idMahasiswa string) (entity.InfoTopikMahasiswa, error) {
return uc.bimbinganLogRepo.GetInfoTopikMahasiswa(idMahasiswa) return uc.bimbinganLogRepo.GetInfoTopikMahasiswa(idMahasiswa)
} }
func (uc *BimbinganLogUc) GetBimbinganLogStatusByStudentId(param utils.LimitOffset, nim string)(entity.BimbinganLogStatus, error){
logs := []entity.BimbinganLogBerkas{}
var offset int
const limit = 100
for{
logBimbinganStatus, err := uc.bimbinganLogRepo.GetBimbinganLogByStudentId(limit,offset,nim)
if err != nil {
// Handle error
break
}
logs = append(logs, logBimbinganStatus...)
if len(logs) < limit {
break
}
offset += limit
}
bimbinganLogStatus := entity.BimbinganLogStatus{
Status: true,
LogBimbingan: logs,
}
var newestLog entity.BimbinganLogBerkas
for _, log := range logs {
newestLogDate, err := time.Parse(time.RFC3339,newestLog.Date)
date, err := time.Parse(time.RFC3339, log.Date)
if err != nil {
return bimbinganLogStatus, err
}
if log.Status && (newestLog.Date == "" || date.Before(newestLogDate)) {
newestLog = log
}
}
now := time.Now()
newestLogDate, err := time.Parse(time.RFC3339,newestLog.Date)
discrepancy := int(math.Abs(float64(now.Month() - newestLogDate.Month())))
if(discrepancy <= 1){
bimbinganLogStatus.Status = true
}else if(discrepancy > 1 && discrepancy <3){
bimbinganLogStatus.Status = false
}else if(discrepancy >= 3){
bimbinganLogStatus.Status = false
}
if err != nil {
return bimbinganLogStatus, err
}
return bimbinganLogStatus, nil
}
...@@ -27,6 +27,7 @@ func NewAdminBimginganLogHandler(cfg config.BimbinganLogTransportConfig) *AdminB ...@@ -27,6 +27,7 @@ func NewAdminBimginganLogHandler(cfg config.BimbinganLogTransportConfig) *AdminB
func (t *AdminBimbinganLogHandler) MountAdmin(group *echo.Group) { func (t *AdminBimbinganLogHandler) MountAdmin(group *echo.Group) {
group.GET("/bimbingan-logs", t.GetBimbinganLog) group.GET("/bimbingan-logs", t.GetBimbinganLog)
group.GET("/bimbingan-logs-status",t.GetBimbinganLogStatus)
} }
func (t *AdminBimbinganLogHandler) GetBimbinganLog(c echo.Context) error { func (t *AdminBimbinganLogHandler) GetBimbinganLog(c echo.Context) error {
...@@ -46,3 +47,17 @@ func (t *AdminBimbinganLogHandler) GetBimbinganLog(c echo.Context) error { ...@@ -46,3 +47,17 @@ func (t *AdminBimbinganLogHandler) GetBimbinganLog(c echo.Context) error {
return c.JSON(http.StatusOK, utils.ResponseDetailOutput(true, http.StatusOK, "Bimbingan logs successfully retreived", BimbinganLogsBerkas)) return c.JSON(http.StatusOK, utils.ResponseDetailOutput(true, http.StatusOK, "Bimbingan logs successfully retreived", BimbinganLogsBerkas))
} }
func (t *AdminBimbinganLogHandler) GetBimbinganLogStatus(c echo.Context) error {
param, err := utils.GetLimitOffset(c.QueryParams())
nim := c.QueryParam("id_mahasiswa")
if err != nil {
return c.JSON(http.StatusInternalServerError, utils.ResponseDetailOutput(false, http.StatusInternalServerError, err.Error(), nil))
}
listBimbinganLogStatuts, err := t.bimbinganLogUsecase.GetBimbinganLogStatusByStudentId(param, nim)
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, "Bimbingan logs Status successfully retreived", listBimbinganLogStatuts))
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment