This repository has been archived by the owner on Aug 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: authentication system - mongo storage (#84)
* - Model - Repo * - fix go mod * - move auth storage logic to usecase\interactor * - fix lint issue * - fix PR comments * implement memory storage for authRequest repo
- Loading branch information
1 parent
532423b
commit 3913545
Showing
17 changed files
with
1,953 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package memory | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
|
||
"github.com/reearth/reearth-backend/internal/usecase/repo" | ||
"github.com/reearth/reearth-backend/pkg/auth" | ||
"github.com/reearth/reearth-backend/pkg/id" | ||
"github.com/reearth/reearth-backend/pkg/rerror" | ||
) | ||
|
||
type AuthRequest struct { | ||
lock sync.Mutex | ||
data map[id.AuthRequestID]auth.Request | ||
} | ||
|
||
func NewAuthRequest() repo.AuthRequest { | ||
return &AuthRequest{ | ||
data: map[id.AuthRequestID]auth.Request{}, | ||
} | ||
} | ||
|
||
func (r *AuthRequest) FindByID(_ context.Context, id id.AuthRequestID) (*auth.Request, error) { | ||
r.lock.Lock() | ||
defer r.lock.Unlock() | ||
|
||
d, ok := r.data[id] | ||
if ok { | ||
return &d, nil | ||
} | ||
return &auth.Request{}, rerror.ErrNotFound | ||
} | ||
|
||
func (r *AuthRequest) FindByCode(_ context.Context, s string) (*auth.Request, error) { | ||
r.lock.Lock() | ||
defer r.lock.Unlock() | ||
|
||
for _, ar := range r.data { | ||
if ar.GetCode() == s { | ||
return &ar, nil | ||
} | ||
} | ||
|
||
return &auth.Request{}, rerror.ErrNotFound | ||
} | ||
|
||
func (r *AuthRequest) FindBySubject(_ context.Context, s string) (*auth.Request, error) { | ||
r.lock.Lock() | ||
defer r.lock.Unlock() | ||
|
||
for _, ar := range r.data { | ||
if ar.GetSubject() == s { | ||
return &ar, nil | ||
} | ||
} | ||
|
||
return &auth.Request{}, rerror.ErrNotFound | ||
} | ||
|
||
func (r *AuthRequest) Save(_ context.Context, request *auth.Request) error { | ||
r.lock.Lock() | ||
defer r.lock.Unlock() | ||
|
||
r.data[request.ID()] = *request | ||
return nil | ||
} | ||
|
||
func (r *AuthRequest) Remove(_ context.Context, requestID id.AuthRequestID) error { | ||
r.lock.Lock() | ||
defer r.lock.Unlock() | ||
|
||
delete(r.data, requestID) | ||
return nil | ||
} |
Oops, something went wrong.