-
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.
- Postman update - Add a cute cate pic - Test: 200 | OK Author: [email protected]
- Loading branch information
Showing
11 changed files
with
192 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package application | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/thanhpp/zola/internal/laclongquan/domain/entity" | ||
) | ||
|
||
func (p PostHandler) GetMedia(ctx context.Context, userID, postID, mediaID string) (*entity.Media, error) { | ||
user, err := p.userRepo.GetByID(ctx, userID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
post, err := p.repo.GetByID(ctx, postID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var relation *entity.Relation | ||
if userID != post.CreatorUUID().String() { | ||
relation, err = p.relationRepo.GetRelationBetween(ctx, userID, post.CreatorUUID().String()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
return post.CanUserGetMedia(user, relation, mediaID) | ||
} |
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
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
73 changes: 73 additions & 0 deletions
73
internal/laclongquan/infrastructure/port/httpserver/controller/postctrl_media.go
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,73 @@ | ||
package controller | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/thanhpp/zola/internal/laclongquan/domain/entity" | ||
"github.com/thanhpp/zola/internal/laclongquan/domain/repository" | ||
"github.com/thanhpp/zola/pkg/logger" | ||
"github.com/thanhpp/zola/pkg/responsevalue" | ||
) | ||
|
||
func (ctrl PostController) GetMedia(c *gin.Context) { | ||
userID, err := getUserUUIDFromClaims(c) | ||
if err != nil { | ||
logger.Errorf("get user id from claims error: %v", err) | ||
ginAbortNotAcceptable(c, responsevalue.CodeInvalidateUser, "invalid user", nil) | ||
return | ||
} | ||
|
||
postID, err := getPostID(c) | ||
if err != nil { | ||
logger.Errorf("get post id error: %v", err) | ||
ginAbortNotAcceptable(c, responsevalue.CodeInvalidParameterType, "invalid post id", nil) | ||
return | ||
} | ||
|
||
mediaID, err := getMediaID(c) | ||
if err != nil { | ||
logger.Errorf("get media id error: %v", err) | ||
ginAbortNotAcceptable(c, responsevalue.CodeInvalidParameterType, "invalid media id", nil) | ||
return | ||
} | ||
|
||
media, err := ctrl.handler.GetMedia(c, userID.String(), postID.String(), mediaID.String()) | ||
if err != nil { | ||
logger.Errorf("get media error: %v", err) | ||
switch err { | ||
case repository.ErrUserNotFound: | ||
ginAbortNotAcceptable(c, responsevalue.CodeInvalidateUser, "user not found", nil) | ||
return | ||
|
||
case repository.ErrPostNotFound: | ||
ginAbortInternalError(c, responsevalue.CodePostNotExist, "post not found", nil) | ||
return | ||
|
||
case repository.ErrRelationNotFound: | ||
ginAbortNotAcceptable(c, responsevalue.CodeInvalidParameterValue, "relation not found", nil) | ||
return | ||
|
||
case entity.ErrLockedUser: | ||
ginAbortNotAcceptable(c, responsevalue.CodeInvalidateUser, "locked user", nil) | ||
return | ||
|
||
case entity.ErrLockedPost: | ||
ginAbortNotAcceptable(c, responsevalue.CodeActionHasBeenDone, "locked post", nil) | ||
return | ||
|
||
case entity.ErrPermissionDenied: | ||
ginAbortNotAcceptable(c, responsevalue.CodeInvalidAccess, "permission denied", nil) | ||
return | ||
|
||
case entity.ErrPostNotContainsMedia: | ||
ginAbortNotAcceptable(c, responsevalue.CodeInvalidParameterValue, "post not contains media", nil) | ||
return | ||
} | ||
|
||
ginAbortInternalError(c, responsevalue.CodeUnknownError, responsevalue.MsgUnknownError, nil) | ||
} | ||
|
||
fmt.Println(media.Path()) | ||
c.File(media.Path()) | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.