-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce user's dashboard MVP (being able to manage their comments a…
…nd bookmarks) (#24)
- Loading branch information
1 parent
140a352
commit 2ed2235
Showing
91 changed files
with
3,912 additions
and
198 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 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,29 @@ | ||
package bookmarkExists | ||
|
||
import "github.com/khanzadimahdi/testproject/domain/bookmark" | ||
|
||
type validationErrors map[string]string | ||
|
||
type Request struct { | ||
ObjectType string `json:"object_type"` | ||
ObjectUUID string `json:"object_uuid"` | ||
OwnerUUID string `json:"-"` | ||
} | ||
|
||
func (r *Request) Validate() (bool, validationErrors) { | ||
errors := make(validationErrors) | ||
|
||
if r.ObjectType != bookmark.ObjectTypeArticle { | ||
errors["object_type"] = "object type is not supported" | ||
} | ||
|
||
if len(r.ObjectUUID) == 0 { | ||
errors["object_uuid"] = "object uuid is required" | ||
} | ||
|
||
if len(r.OwnerUUID) == 0 { | ||
errors["owner_uuid"] = "owner uuid is required" | ||
} | ||
|
||
return len(errors) == 0, errors | ||
} |
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,7 @@ | ||
package bookmarkExists | ||
|
||
type Response struct { | ||
ValidationErrors validationErrors `json:"errors,omitempty"` | ||
|
||
Exist bool `json:"exist"` | ||
} |
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,40 @@ | ||
package bookmarkExists | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/khanzadimahdi/testproject/domain" | ||
"github.com/khanzadimahdi/testproject/domain/bookmark" | ||
) | ||
|
||
type UseCase struct { | ||
bookmarkRepository bookmark.Repository | ||
} | ||
|
||
func NewUseCase( | ||
bookmarkRepository bookmark.Repository, | ||
) *UseCase { | ||
return &UseCase{ | ||
bookmarkRepository: bookmarkRepository, | ||
} | ||
} | ||
|
||
func (uc *UseCase) Execute(request *Request) (*Response, error) { | ||
if ok, validation := request.Validate(); !ok { | ||
return &Response{ | ||
ValidationErrors: validation, | ||
}, nil | ||
} | ||
|
||
if _, err := uc.bookmarkRepository.GetByOwnerUUID(request.OwnerUUID, request.ObjectType, request.ObjectUUID); errors.Is(err, domain.ErrNotExists) { | ||
return &Response{ | ||
Exist: false, | ||
}, nil | ||
} else if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &Response{ | ||
Exist: true, | ||
}, nil | ||
} |
Oops, something went wrong.