Skip to content

Commit

Permalink
feat(master): add new api posts
Browse files Browse the repository at this point in the history
  • Loading branch information
thaisonenouvo committed Nov 28, 2023
1 parent 0df85dd commit 44d9b29
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apps/api/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const docTemplate = `{
var SwaggerInfo = &swag.Spec{
Version: "1.0",
Host: "",
BasePath: "",
BasePath: "/dev",
Schemes: []string{},
Title: "Meta-Clone",
Description: "API for Meta-Clone",
Expand Down
2 changes: 1 addition & 1 deletion apps/api/handlers/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/aws/aws-lambda-go/events"
)

func Connect(ctx context.Context, event events.APIGatewayWebsocketProxyRequest) (events.APIGatewayProxyResponse, error) {
func Connect(_ context.Context, event events.APIGatewayWebsocketProxyRequest) (events.APIGatewayProxyResponse, error) {
log.Printf("new connection. id: %s", event.RequestContext.ConnectionID)

return events.APIGatewayProxyResponse{
Expand Down
2 changes: 1 addition & 1 deletion apps/api/handlers/disconnect.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/aws/aws-lambda-go/events"
)

func Disconnect(ctx context.Context, event events.APIGatewayWebsocketProxyRequest) (events.APIGatewayProxyResponse, error) {
func Disconnect(_ context.Context, event events.APIGatewayWebsocketProxyRequest) (events.APIGatewayProxyResponse, error) {
log.Printf("new disconnection. id: %s", event.RequestContext.ConnectionID)

return events.APIGatewayProxyResponse{
Expand Down
27 changes: 27 additions & 0 deletions apps/api/handlers/feed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package handlers

import (
"github.com/gin-gonic/gin"
h "github.com/tranthaison1231/meta-clone/api/helpers"
"github.com/tranthaison1231/meta-clone/api/models"
"github.com/tranthaison1231/meta-clone/api/services"
)

// @Summary Get News Feed
// @ID get-news-feed
// @Security BearerAuth
// @Success 200 {string} {"status": "success", data: { "posts": []models.Post }, "code": 200}
// @Router /posts [get]
func GetNewsFeed(c *gin.Context) {
user := c.MustGet("user").(*models.User)

posts, err := services.GetPosts(user.ID)

if err != nil {
h.Fail400(c, err.Error())
}

h.Success(c, gin.H{
"posts": posts,
})
}
4 changes: 1 addition & 3 deletions apps/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
docs "github.com/tranthaison1231/meta-clone/api/docs"
)

var (
Expand All @@ -42,6 +41,7 @@ func initRoutes(r *gin.Engine) {
auth.PUT("/me", handlers.UpdateMe)
auth.GET("/chats", handlers.GetChats)
auth.POST("/chats", handlers.CreateChat)
auth.POST("/news-feed", handlers.GetNewsFeed)
auth.GET("/posts", handlers.GetPosts)
auth.POST("/posts", handlers.CreatePost)
auth.POST("/chats/:chatID/join", handlers.AddMemberToChat)
Expand Down Expand Up @@ -97,9 +97,7 @@ func Handler(ctx context.Context, req events.APIGatewayProxyRequest) (events.API
func main() {
if port != "" {
server.ListenAndServe()
docs.SwaggerInfo.BasePath = "/"
} else {
lambda.Start(Handler)
docs.SwaggerInfo.BasePath = "/dev"
}
}
6 changes: 6 additions & 0 deletions apps/api/models/media.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package models

type Media struct {
Base
URL string `gorm:"not null;type:text" json:"url"`
}

1 comment on commit 44d9b29

@vercel
Copy link

@vercel vercel bot commented on 44d9b29 Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.