Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add email and notification #28

Open
wants to merge 36 commits into
base: fix/adminAccess
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
2b125e1
Merge pull request #24 from joshsoftware/Deployment
shailendrakanherkar18 Aug 21, 2024
a4439df
updated mina script
shailendrakanherkar18 Aug 21, 2024
2308abb
[Deployment] IST time check
SamnitPatil9882 Aug 21, 2024
347ff22
Merge branch 'Deployment' of github.com:joshsoftware/peerly-backend i…
SamnitPatil9882 Aug 21, 2024
7ca7f13
[Deployment] IST time check
SamnitPatil9882 Aug 21, 2024
3932a24
[Deployment] ist check
SamnitPatil9882 Aug 21, 2024
a0082dd
[Deployment] ist check
SamnitPatil9882 Aug 21, 2024
b5db7d0
[Deployment] reset monthly an daily update data timing
SamnitPatil9882 Aug 21, 2024
5434583
Merge branch 'Deployment' of github.com:joshsoftware/peerly-backend i…
SharyuMarwadi Aug 22, 2024
d8d4559
[Deployment] migration updation
SharyuMarwadi Aug 22, 2024
4ee648a
Merge branch 'fix/adminAccess' of github.com:joshsoftware/peerly-back…
SharyuMarwadi Aug 22, 2024
6b3228d
[feature/UpdateLogs] added debug logs
SamnitPatil9882 Aug 23, 2024
4fba193
[feature/UpdateLogs] logs updated
SharyuMarwadi Aug 23, 2024
069f6c8
[feature/UpdateLogs] logs added
SamnitPatil9882 Aug 26, 2024
d200904
[Deployment] feature/UpdateLogs merged
SamnitPatil9882 Aug 26, 2024
b295e54
Merge branch 'Deployment' of github.com:joshsoftware/peerly-backend i…
SamnitPatil9882 Aug 26, 2024
a61d8ef
[ feature/UpdateLogs] main.go updated
SamnitPatil9882 Aug 26, 2024
7f313f1
Merge branch 'feature/UpdateLogs' of github.com:joshsoftware/peerly-b…
SamnitPatil9882 Aug 26, 2024
8aaf7ef
[feature/UpdateLogs] logs folder added
SamnitPatil9882 Aug 26, 2024
27405e4
Merge branch 'feature/UpdateLogs' of github.com:joshsoftware/peerly-b…
SamnitPatil9882 Aug 26, 2024
a03cd52
[feature/UpdateLogs] defer function changed
SamnitPatil9882 Aug 26, 2024
4d3573a
Merge branch 'feature/UpdateLogs' of github.com:joshsoftware/peerly-b…
SamnitPatil9882 Aug 26, 2024
208ccf7
[fix/AdminPermissions] permissions given to admin
SharyuMarwadi Aug 27, 2024
368973f
[fix/AdminPermissions] iota logic added
SharyuMarwadi Aug 27, 2024
327598a
[feature/addEmailAndNotification] image url changed as per env
SamnitPatil9882 Aug 28, 2024
d128713
[feature/addEmailAndNotification] import cycle removed
SamnitPatil9882 Aug 28, 2024
07e217a
[feature/addEmailAndNotification] import cycle removed
SamnitPatil9882 Aug 28, 2024
4918d5d
Merge pull request #30 from joshsoftware/fix/AdminPermissions
shailendrakanherkar18 Aug 29, 2024
dd2acfc
[fix/AdminPermissions] route permissions updated
SharyuMarwadi Aug 29, 2024
42560aa
[fix/AdminPermissions] go vet errors removed
SharyuMarwadi Aug 29, 2024
f4336d9
[feature/addEmailAndNotification] email service validation and struct…
SamnitPatil9882 Aug 29, 2024
87c319e
Merge pull request #33 from joshsoftware/fix/AdminPermissions
shailendrakanherkar18 Aug 29, 2024
182e74a
[feature/UpdateLogs] review comments resolved
SamnitPatil9882 Aug 29, 2024
24abb14
[feature/addEmailAndNotification] data field added in notification
SamnitPatil9882 Sep 2, 2024
d46c813
[feature/UpdateLogs] main merged in feature/UpdateLogs
SamnitPatil9882 Sep 2, 2024
91e990b
[feature/addEmailAndNotification] featureUpdateLogs merged
SamnitPatil9882 Sep 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ INTRANET_BASE_URL = https://pg-stage-intranet.joshsoftware.com

SENDGRID_API_KEY=sendgrid_api_key
SENDER_EMAIL=sendgrid_email
DEVELOPER_KEY = developer_key
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ go.work.sum

.env
.vscode
serviceAccountKey.json
serviceAccountKey.json
logs/*
Binary file modified assets/silverBadge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 23 additions & 9 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/joshsoftware/peerly-backend/internal/app"
"github.com/joshsoftware/peerly-backend/internal/app/cronjob"
"github.com/joshsoftware/peerly-backend/internal/pkg/config"
log "github.com/joshsoftware/peerly-backend/internal/pkg/logger"
"github.com/joshsoftware/peerly-backend/internal/repository"
script "github.com/joshsoftware/peerly-backend/scripts"
"github.com/rs/cors"
Expand Down Expand Up @@ -94,13 +95,18 @@ func startApp() (err error) {

// Context for main function
ctx := context.Background()
logger.Info("Starting Peerly Application...")
defer logger.Info("Shutting Down Peerly Application...")
lg,err := log.SetupLogger()
if err != nil{
logger.Error("logger setup failed ",err.Error())
return err
}
log.Info(ctx,"Starting Peerly Application...")
defer log.Info(ctx,"Shutting Down Peerly Application...")
//initialize database
dbInstance, err := repository.InitializeDatabase()
if err != nil {
logger.WithField("err", err.Error()).Error("Database init failed")
return
log.Error(ctx,"Database init failed")
return err
}

//cors
Expand All @@ -117,17 +123,25 @@ func startApp() (err error) {
// Initializing Cron Job
scheduler, err := gocron.NewScheduler()
if err != nil {
logger.Error(ctx, "scheduler creation failed with error: %s", err.Error())
return
log.Error(ctx, "scheduler creation failed with error: %s", err.Error())
return err
}

cronjob.InitializeJobs(services.AppreciationService, services.UserService, scheduler)
defer scheduler.Shutdown()
defer func() {
if err := scheduler.Shutdown(); err != nil {
log.Error(ctx, "Scheduler shutdown failed: %s", err.Error())
}
}()
//initialize router
router := api.NewRouter(services)

// init web server
server := negroni.Classic()
// Negroni logger setup
negroniLogger := negroni.NewLogger()
negroniLogger.ALogger = lg

// Initialize web server
server := negroni.New(negroniLogger)
server.Use(c)
server.UseHandler(router)

Expand Down
2 changes: 1 addition & 1 deletion deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
task :production do
set :deploy_to, '/www/peerly-backend'
set :domain, ENV['PEERLY_PRODUCTIONS_IP']
set :branch, 'Deployment'
set :branch, 'main'
end

task :setup do
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,6 @@ require (
google.golang.org/grpc v1.62.1 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1
gopkg.in/yaml.v3 v3.0.1 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
35 changes: 23 additions & 12 deletions internal/api/appreciation.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,62 +9,68 @@ import (
"github.com/joshsoftware/peerly-backend/internal/app/appreciation"
"github.com/joshsoftware/peerly-backend/internal/pkg/apperrors"
"github.com/joshsoftware/peerly-backend/internal/pkg/dto"
log "github.com/joshsoftware/peerly-backend/internal/pkg/logger"
"github.com/joshsoftware/peerly-backend/internal/pkg/utils"
logger "github.com/sirupsen/logrus"
)

func createAppreciationHandler(appreciationSvc appreciation.Service) http.HandlerFunc {
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
var appreciation dto.Appreciation
err := json.NewDecoder(req.Body).Decode(&appreciation)
if err != nil {
logger.Errorf("Error while decoding request data : %v", err)
log.Errorf(req.Context(),"Error while decoding request data : %v", err)
err = apperrors.JSONParsingErrorReq
dto.ErrorRepsonse(rw, err)
return
}

log.Info(req.Context(),"createAppreciationHandler: request: ",req)
err = appreciation.ValidateCreateAppreciation()
if err != nil {
logger.Errorf("Error while validating request data : %v", err)
log.Errorf(req.Context(),"Error while validating request data : %v", err)
dto.ErrorRepsonse(rw, err)
return
}

resp, err := appreciationSvc.CreateAppreciation(req.Context(), appreciation)
if err != nil {
logger.Errorf("err : %v", err)
log.Errorf(req.Context(),"createAppreciationHandler: err : %v", err)
dto.ErrorRepsonse(rw, err)
return
}
log.Debug(req.Context(),"createAppreciationHandler: response: ",resp)
log.Info(req.Context(),"Appreciation created successfully")
dto.SuccessRepsonse(rw, http.StatusCreated, "Appreciation created successfully", resp)
})
}

func getAppreciationByIDHandler(appreciationSvc appreciation.Service) http.HandlerFunc {
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {

vars := mux.Vars(req)
apprID, err := strconv.Atoi(vars["id"])
if err != nil {
log.Errorf(req.Context(),"Error while decoding appreciation id : %v", err)
dto.ErrorRepsonse(rw, err)
return
}


log.Info(req.Context(),"getAppreciationByIDHandler: request: ",req)
resp, err := appreciationSvc.GetAppreciationById(req.Context(), int32(apprID))
if err != nil {
logger.Errorf("err : %v", err)
log.Errorf(req.Context(),"getAppreciationByIDHandler: err : %v", err)
dto.ErrorRepsonse(rw, err)
return
}

log.Debug(req.Context(),"getAppreciationByIDHandler: request: ",resp)
log.Info(req.Context(),"Appreciation data got successfully")
dto.SuccessRepsonse(rw, http.StatusOK, "Appreciation data got successfully", resp)
})
}

// getAppreciationsHandler handles HTTP requests for appreciations
func listAppreciationsHandler(appreciationSvc appreciation.Service) http.HandlerFunc {
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {

var filter dto.AppreciationFilter

filter.Name = req.URL.Query().Get("name")
Expand All @@ -76,13 +82,15 @@ func listAppreciationsHandler(appreciationSvc appreciation.Service) http.Handler
filter.Limit = limit
filter.Page = page
filter.Self = utils.GetSelfParam(req)

log.Info(req.Context(),"listAppreciationsHandler: request: ",req)
appreciations, err := appreciationSvc.ListAppreciations(req.Context(), filter)
if err != nil {
logger.Errorf("err : %v", err)
log.Errorf(req.Context(),"listAppreciationsHandler: err : %v", err)
dto.ErrorRepsonse(rw, err)
return
}
log.Debug(req.Context(),"listAppreciationsHandler: response: ",appreciations)
log.Info(req.Context(),"Appreciations data got successfully")
dto.SuccessRepsonse(rw, http.StatusOK, "Appreciations data got successfully ", appreciations)
})
}
Expand All @@ -92,17 +100,20 @@ func deleteAppreciationHandler(appreciationSvc appreciation.Service) http.Handle
vars := mux.Vars(req)
apprId, err := strconv.Atoi(vars["id"])
if err != nil {
logger.Errorf("Error while decoding request param data : %v", err)
log.Errorf(req.Context(),"Error while decoding request param data : %v", err)
dto.ErrorRepsonse(rw, apperrors.BadRequest)
return
}

log.Info(req.Context(),"deleteAppreciationHandler: request: ",req)
err = appreciationSvc.DeleteAppreciation(req.Context(), int32(apprId))
if err != nil {
logger.Errorf("err : %v", err)
log.Errorf(req.Context(),"deleteAppreciationHandler: err : %v", err)
dto.ErrorRepsonse(rw, err)
return
}
log.Debug(req.Context(),"deleteAppreciationHandler: resp: ",err)
log.Info(req.Context(),"Appreciation invalidate successfully")
dto.SuccessRepsonse(rw, http.StatusOK, "Appreciation invalidate successfully", nil)
})
}
4 changes: 2 additions & 2 deletions internal/api/badges.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/joshsoftware/peerly-backend/internal/app/badges"
"github.com/joshsoftware/peerly-backend/internal/pkg/apperrors"
"github.com/joshsoftware/peerly-backend/internal/pkg/dto"
logger "github.com/sirupsen/logrus"
logger "github.com/joshsoftware/peerly-backend/internal/pkg/logger"
)

func listBadgesHandler(badgeSvc badges.Service) http.HandlerFunc {
Expand All @@ -30,7 +30,7 @@ func editBadgesHandler(badgeSvc badges.Service) http.HandlerFunc {
var reqData dto.UpdateBadgeReq
err := json.NewDecoder(req.Body).Decode(&reqData)
if err != nil {
logger.Errorf("error while decoding request data, err: %s", err.Error())
logger.Errorf(req.Context(), "error while decoding request data, err: %s", err.Error())
err = apperrors.JSONParsingErrorReq
dto.ErrorRepsonse(rw, err)
return
Expand Down
6 changes: 3 additions & 3 deletions internal/api/coreValues.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
corevalues "github.com/joshsoftware/peerly-backend/internal/app/coreValues"
"github.com/joshsoftware/peerly-backend/internal/pkg/apperrors"
"github.com/joshsoftware/peerly-backend/internal/pkg/dto"
logger "github.com/sirupsen/logrus"
logger "github.com/joshsoftware/peerly-backend/internal/pkg/logger"
)

func listCoreValuesHandler(coreValueSvc corevalues.Service) http.HandlerFunc {
Expand Down Expand Up @@ -46,7 +46,7 @@ func createCoreValueHandler(coreValueSvc corevalues.Service) http.HandlerFunc {
var coreValue dto.CreateCoreValueReq
err := json.NewDecoder(req.Body).Decode(&coreValue)
if err != nil {
logger.Errorf("error while decoding request data, err: %s", err.Error())
logger.Errorf(req.Context(), "error while decoding request data, err: %s", err.Error())
err = apperrors.JSONParsingErrorReq
dto.ErrorRepsonse(rw, err)
return
Expand All @@ -72,7 +72,7 @@ func updateCoreValueHandler(coreValueSvc corevalues.Service) http.HandlerFunc {
var updateReq dto.UpdateQueryRequest
err := json.NewDecoder(req.Body).Decode(&updateReq)
if err != nil {
logger.Errorf("error while decoding request data, err: %s", err.Error())
logger.Errorf(req.Context(), "error while decoding request data, err: %s", err.Error())
err = apperrors.JSONParsingErrorReq
dto.ErrorRepsonse(rw, err)
return
Expand Down
4 changes: 2 additions & 2 deletions internal/api/grades.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/joshsoftware/peerly-backend/internal/app/grades"
"github.com/joshsoftware/peerly-backend/internal/pkg/apperrors"
"github.com/joshsoftware/peerly-backend/internal/pkg/dto"
logger "github.com/sirupsen/logrus"
logger "github.com/joshsoftware/peerly-backend/internal/pkg/logger"
)

func listGradesHandler(gradeSvc grades.Service) http.HandlerFunc {
Expand All @@ -30,7 +30,7 @@ func editGradesHandler(gradeSvc grades.Service) http.HandlerFunc {
var reqData dto.UpdateGradeReq
err := json.NewDecoder(req.Body).Decode(&reqData)
if err != nil {
logger.Errorf("error while decoding request data, err: %s", err.Error())
logger.Errorf(ctx, "error while decoding request data, err: %s", err.Error())
err = apperrors.JSONParsingErrorReq
dto.ErrorRepsonse(rw, err)
return
Expand Down
43 changes: 43 additions & 0 deletions internal/api/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package api

import (
"encoding/json"
"fmt"
"net/http"

"github.com/joshsoftware/peerly-backend/internal/pkg/apperrors"
"github.com/joshsoftware/peerly-backend/internal/pkg/config"
"github.com/joshsoftware/peerly-backend/internal/pkg/dto"
log "github.com/joshsoftware/peerly-backend/internal/pkg/logger"
"github.com/sirupsen/logrus"
)


func loggerHandler(rw http.ResponseWriter, req *http.Request) {

log.Debug(req.Context(),"loggerHandler: req: ",req)
var changeLogRequest dto.ChangeLogLevelRequest
err := json.NewDecoder(req.Body).Decode(&changeLogRequest)
if err != nil {
log.Errorf(req.Context(),"Error while decoding request data : %v", err)
err = apperrors.JSONParsingErrorReq
dto.ErrorRepsonse(rw, err)
return
}

if config.DeveloperKey() != changeLogRequest.DeveloperKey {
dto.ErrorRepsonse(rw,apperrors.UnauthorizedDeveloper)
return
}

log.Info(req.Context(), "loggerHandler")
if changeLogRequest.LogLevel == "DebugLevel" {
log.Logger.SetLevel(logrus.DebugLevel)
}else if changeLogRequest.LogLevel == "InfoLevel" {
log.Logger.SetLevel(logrus.InfoLevel)
}else {
dto.ErrorRepsonse(rw, apperrors.InvalidLoggerLevel)
return
}
dto.SuccessRepsonse(rw, http.StatusOK, "Success", fmt.Sprintf("log level changed to %s", changeLogRequest.LogLevel))
}
Loading