Skip to content

Instantly share code, notes, and snippets.

View anatoliyfedorenko's full-sized avatar
🤘
Creating value at maddevs.io

Anatoliy anatoliyfedorenko

🤘
Creating value at maddevs.io
View GitHub Profile
@anatoliyfedorenko
anatoliyfedorenko / logs.go
Created July 13, 2020 06:06
logs to change
err = api.Storage.Profile().Update(ctx, user)
if err != nil {
api.Logger.WithFields(logrus.Fields{"err": err}).Error("Update failed")
}
@anatoliyfedorenko
anatoliyfedorenko / changes.go
Created July 13, 2020 06:03
Changes to Interface
// IStorage represents database methods
type IStorage interface {
Feedback() Feedback
// this is just a temporary change not to break all the functionality. Will reimplment this
// for the version mentioned above as a next step with just a small chucks under improvements
User
Profile
Agreement
AgreementChange
@anatoliyfedorenko
anatoliyfedorenko / interface_1.go
Last active July 13, 2020 06:03
Interface Refactoring
// IStorage represents database methods
type IStorage interface {
// User() User
// Profile() Profile
// Agreement() Agreement
// AgreementChanges() AgreementChange
// Milestone() Milestone
// Contact() Contact
// Notifications() Notification
// Payout() Payout
@anatoliyfedorenko
anatoliyfedorenko / interface_poor.go
Last active July 13, 2020 11:55
Heavy Interface for Database interactions
// IStorage represents database methods
type IStorage interface {
IfUserCanBeDeleted(ctx context.Context, userID int64) (bool, error)
CreateUser(ctx context.Context, u *model.User) (model.User, error)
CreateProfile(ctx context.Context, item *model.Profile) (*model.Profile, error)
DeleteUser(ctx context.Context, id int64) error
MarkUserAsDeleted(ctx context.Context, id int64, reason string) error
ListProfiles(ctx context.Context) ([]model.Profile, error)
UpdateProfile(ctx context.Context, item *model.Profile) error
GetUserByID(ctx context.Context, id int64) (model.User, error)
@anatoliyfedorenko
anatoliyfedorenko / interface.go
Created July 13, 2020 05:52
Interface for Database Communication
// IStorage represents database methods
type IStorage interface {
User() User
Profile() Profile
Agreement() Agreement
AgreementChanges() AgreementChanges
Milestone() Milestone
Contact() Contact
Notification() Notification
Payout() Payout
@anatoliyfedorenko
anatoliyfedorenko / gist:836704a2bf0cc7eb642f3a62562c545c
Created March 30, 2019 08:45
Create db dump with all id primary keys NULL
mysqldump --complete-insert --host=localhost --user=root --password=root --no-create-info database | sed -e "s/([0-9]*,/(NULL,/gi" > database.sql
@anatoliyfedorenko
anatoliyfedorenko / main.go
Created November 9, 2018 10:46
slack main loop
func (s *Slack) Run() {
s.UpdateUsersList()
s.SendUserMessage(s.Conf.ManagerSlackUserID, s.Conf.Translate.HelloManager)
gocron.Every(1).Day().At("23:50").Do(s.FillStandupsForNonReporters)
gocron.Every(1).Day().At("23:55").Do(s.UpdateUsersList)
gocron.Start()
s.WG.Add(1)
@anatoliyfedorenko
anatoliyfedorenko / main.go
Created November 9, 2018 10:44
How to exit goroutine
package main
import "sync"
func main() {
var wg sync.WaitGroup
wg.Add(1)
ch := make(chan int)
@anatoliyfedorenko
anatoliyfedorenko / handleUser.go
Created July 30, 2018 05:49
Go table tests practice
func TestHandleUserCommands(t *testing.T) {
AddUser := "command=/comedianadd&text=<@userid|test>&channel_id=chanid&channel_name=channame"
AddEmptyText := "command=/comedianadd&text="
AddUserEmptyChannelID := "command=/comedianadd&text=test&channel_id=&channel_name=channame"
AddUserEmptyChannelName := "command=/comedianadd&text=test&channel_id=chanid&channel_name="
DelUser := "command=/comedianremove&text=@test&channel_id=chanid"
ListUsers := "command=/comedianlist&channel_id=chanid"
c, err := config.Get()
rest, err := NewRESTAPI(c)