Skip to content

Commit

Permalink
code cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
Christophe Ninucci committed May 16, 2023
1 parent d83e900 commit dda77b9
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 79 deletions.
6 changes: 3 additions & 3 deletions cards.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (wekan *Wekan) SelectCardsFromListID(ctx context.Context, listID ListID) ([
return wekan.SelectCardsFromQuery(ctx, bson.M{"listId": listID})
}

// SelectCardsWithCommentsFromPipeline retourne les objets correspondant au modèle Card à partir d'un pipeline mongodb
// SelectCardsFromPipeline retourne les objets correspondant au modèle Card à partir d'un pipeline mongodb
func (wekan *Wekan) SelectCardsFromPipeline(ctx context.Context, collection string, pipeline Pipeline) ([]Card, error) {
cur, err := wekan.db.Collection(collection).Aggregate(ctx, pipeline)
if err != nil {
Expand Down Expand Up @@ -413,8 +413,8 @@ func (wekan *Wekan) BuildCardFromCustomTextFieldPipeline(name string, value stri
return pipeline
}

func (w *Wekan) UnarchiveCard(ctx context.Context, cardID CardID) error {
update, err := w.db.Collection("cards").UpdateOne(ctx, bson.M{
func (wekan *Wekan) UnarchiveCard(ctx context.Context, cardID CardID) error {
update, err := wekan.db.Collection("cards").UpdateOne(ctx, bson.M{
"_id": cardID,
}, bson.M{
"$set": bson.M{
Expand Down
8 changes: 4 additions & 4 deletions cards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ func TestCard_AddMember(t *testing.T) {
BoardID(t.Name()+"boardID"),
ListID(t.Name()+"boardID"),
SwimlaneID(t.Name()+"boardID"),
(t.Name() + "title"),
(t.Name() + "description"),
t.Name()+"title",
t.Name()+"description",
UserID(t.Name()+"userID"),
)
memberID := UserID(t.Name() + "memberID")
Expand All @@ -24,8 +24,8 @@ func TestCard_AddMember_Duplicate(t *testing.T) {
BoardID(t.Name()+"boardID"),
ListID(t.Name()+"boardID"),
SwimlaneID(t.Name()+"boardID"),
(t.Name() + "title"),
(t.Name() + "description"),
t.Name()+"title",
t.Name()+"description",
UserID(t.Name()+"userID"),
)
memberID := UserID(t.Name() + "memberID")
Expand Down
2 changes: 1 addition & 1 deletion init.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (wekan *Wekan) AssertPrivileged(ctx context.Context) error {
if *wekan.privileged {
return nil
}
return NotPrivilegedError{wekan.adminUserID, errors.New("L'utilisateur n'est pas administration")}
return NotPrivilegedError{wekan.adminUserID, errors.New("l'utilisateur n'est pas administrateur")}
}
admin, err := wekan.GetUserFromUsername(ctx, wekan.adminUsername)
if err != nil {
Expand Down
128 changes: 64 additions & 64 deletions misc.go
Original file line number Diff line number Diff line change
@@ -1,96 +1,96 @@
package libwekan

import (
"math/rand"
"time"
"math/rand"
"time"
)

func newId() string {
return newIdN(17)
return newIdN(17)
}

func newId6() string {
return newIdN(6)
return newIdN(6)
}

func newIdN(n int) string {
chars := "123456789ABCDEFGHJKLMNPQRSTWXYZabcdefghijkmnopqrstuvwxyz"
l := len(chars)
var digits []byte
for i := 0; i < n; i++ {
digit := rand.Intn(l)
digits = append(digits, chars[digit])
}
return string(digits)
chars := "123456789ABCDEFGHJKLMNPQRSTWXYZabcdefghijkmnopqrstuvwxyz"
l := len(chars)
var digits []byte
for i := 0; i < n; i++ {
digit := rand.Intn(l)
digits = append(digits, chars[digit])
}
return string(digits)
}

func uniq[Element comparable](array []Element) []Element {
m := make(map[Element]struct{})
for _, element := range array {
m[element] = struct{}{}
}
var set = []Element{}
for element := range m {
set = append(set, element)
}
return set
m := make(map[Element]struct{})
for _, element := range array {
m[element] = struct{}{}
}
var set []Element
for element := range m {
set = append(set, element)
}
return set
}

func intersect[E comparable](elementsA []E, elementsB []E) (both []E, onlyA []E, onlyB []E) {
for _, elementA := range elementsA {
foundBoth := false
for _, elementB := range elementsB {
if elementA == elementB {
both = append(both, elementA)
foundBoth = true
}
}
if !foundBoth {
onlyA = append(onlyA, elementA)
}
}
for _, elementA := range elementsA {
foundBoth := false
for _, elementB := range elementsB {
if elementA == elementB {
both = append(both, elementA)
foundBoth = true
}
}
if !foundBoth {
onlyA = append(onlyA, elementA)
}
}

for _, elementB := range elementsB {
foundBoth := false
for _, elementA := range elementsA {
if elementA == elementB {
foundBoth = true
}
}
if !foundBoth {
onlyB = append(onlyB, elementB)
}
}
return both, onlyA, onlyB
for _, elementB := range elementsB {
foundBoth := false
for _, elementA := range elementsA {
if elementA == elementB {
foundBoth = true
}
}
if !foundBoth {
onlyB = append(onlyB, elementB)
}
}
return both, onlyA, onlyB
}

func mapSlice[T any, M any](a []T, f func(T) M) []M {
n := make([]M, len(a))
for i, e := range a {
n[i] = f(e)
}
return n
n := make([]M, len(a))
for i, e := range a {
n[i] = f(e)
}
return n
}

func toMongoTime(t time.Time) time.Time {
return t.In(time.UTC).Truncate(time.Millisecond)
return t.In(time.UTC).Truncate(time.Millisecond)
}

func contains[Element comparable](elements []Element, element Element) bool {
for _, actual := range elements {
if element == actual {
return true
}
}
return false
for _, actual := range elements {
if element == actual {
return true
}
}
return false
}

func selectSlice[Element any](slice []Element, filter func(Element) bool) []Element {
var accepted []Element
for _, element := range slice {
if filter(element) {
accepted = append(accepted, element)
}
}
return accepted
var accepted []Element
for _, element := range slice {
if filter(element) {
accepted = append(accepted, element)
}
}
return accepted
}
4 changes: 2 additions & 2 deletions pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ func (p *Pipeline) AppendStage(stage bson.M) {
}

func (p *Pipeline) PrependStage(stage bson.M) {
*p = append(Pipeline{stage}, (*p)...)
*p = append(Pipeline{stage}, *p...)
}

func (p *Pipeline) AppendPipeline(pipeline Pipeline) {
*p = append(*p, pipeline...)
}

func (p *Pipeline) PrependPipeline(pipeline Pipeline) {
*p = append(pipeline, (*p)...)
*p = append(pipeline, *p...)
}
8 changes: 4 additions & 4 deletions users.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ type UserProfile struct {
type Username string
type UserID string

func (userID UserID) GetDocument(ctx context.Context, wekan *Wekan) (User, error) {
return wekan.GetUserFromID(ctx, userID)
func (userId UserID) GetDocument(ctx context.Context, wekan *Wekan) (User, error) {
return wekan.GetUserFromID(ctx, userId)
}

func (userID UserID) Check(ctx context.Context, wekan *Wekan) error {
_, err := wekan.GetUserFromID(ctx, userID)
func (userId UserID) Check(ctx context.Context, wekan *Wekan) error {
_, err := wekan.GetUserFromID(ctx, userId)
return err
}

Expand Down
1 change: 0 additions & 1 deletion users_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build integration
// +build integration

// nolint:errcheck
package libwekan
Expand Down

0 comments on commit dda77b9

Please sign in to comment.