Skip to content

Commit

Permalink
Use NEXTJS file conventions params for pages (#93)
Browse files Browse the repository at this point in the history
* feat: added parameters best practices in dashboard pages and added metadata to improve SEO

* feat: modified errors returned from analysis and analysis-landing
  • Loading branch information
webtaken authored Dec 9, 2023
1 parent 26e3d55 commit 3cc5a9c
Show file tree
Hide file tree
Showing 23 changed files with 167 additions and 282 deletions.
37 changes: 14 additions & 23 deletions go-server/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,22 @@ const docTemplate = `{
"$ref": "#/definitions/models.YoutubeAnalyzerRespBody"
}
},
"204": {
"description": "No Content",
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/utils.HandleError.errorResponse"
"$ref": "#/definitions/fiber.Error"
}
},
"400": {
"description": "Bad Request",
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/utils.HandleError.errorResponse"
"$ref": "#/definitions/fiber.Error"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/utils.HandleError.errorResponse"
"$ref": "#/definitions/fiber.Error"
}
}
}
Expand Down Expand Up @@ -111,22 +111,22 @@ const docTemplate = `{
"$ref": "#/definitions/models.YoutubeAnalyzerLandingRespBody"
}
},
"204": {
"description": "No Content",
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/utils.HandleError.errorResponse"
"$ref": "#/definitions/fiber.Error"
}
},
"400": {
"description": "Bad Request",
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/utils.HandleError.errorResponse"
"$ref": "#/definitions/fiber.Error"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/utils.HandleError.errorResponse"
"$ref": "#/definitions/fiber.Error"
}
}
}
Expand Down Expand Up @@ -1615,15 +1615,6 @@ const docTemplate = `{
}
}
},
"utils.HandleError.errorResponse": {
"type": "object",
"properties": {
"error": {
"type": "string",
"example": "an error ocurred"
}
}
},
"youtube.Comment": {
"type": "object",
"properties": {
Expand Down
37 changes: 14 additions & 23 deletions go-server/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@
"$ref": "#/definitions/models.YoutubeAnalyzerRespBody"
}
},
"204": {
"description": "No Content",
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/utils.HandleError.errorResponse"
"$ref": "#/definitions/fiber.Error"
}
},
"400": {
"description": "Bad Request",
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/utils.HandleError.errorResponse"
"$ref": "#/definitions/fiber.Error"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/utils.HandleError.errorResponse"
"$ref": "#/definitions/fiber.Error"
}
}
}
Expand Down Expand Up @@ -104,22 +104,22 @@
"$ref": "#/definitions/models.YoutubeAnalyzerLandingRespBody"
}
},
"204": {
"description": "No Content",
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/utils.HandleError.errorResponse"
"$ref": "#/definitions/fiber.Error"
}
},
"400": {
"description": "Bad Request",
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/utils.HandleError.errorResponse"
"$ref": "#/definitions/fiber.Error"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/utils.HandleError.errorResponse"
"$ref": "#/definitions/fiber.Error"
}
}
}
Expand Down Expand Up @@ -1608,15 +1608,6 @@
}
}
},
"utils.HandleError.errorResponse": {
"type": "object",
"properties": {
"error": {
"type": "string",
"example": "an error ocurred"
}
}
},
"youtube.Comment": {
"type": "object",
"properties": {
Expand Down
30 changes: 12 additions & 18 deletions go-server/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -653,12 +653,6 @@ definitions:
$ref: '#/definitions/models.YoutubeVideoDashboard'
type: array
type: object
utils.HandleError.errorResponse:
properties:
error:
example: an error ocurred
type: string
type: object
youtube.Comment:
properties:
etag:
Expand Down Expand Up @@ -949,18 +943,18 @@ paths:
description: OK
schema:
$ref: '#/definitions/models.YoutubeAnalyzerRespBody'
"204":
description: No Content
schema:
$ref: '#/definitions/utils.HandleError.errorResponse'
"400":
description: Bad Request
schema:
$ref: '#/definitions/utils.HandleError.errorResponse'
$ref: '#/definitions/fiber.Error'
"404":
description: Not Found
schema:
$ref: '#/definitions/fiber.Error'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/utils.HandleError.errorResponse'
$ref: '#/definitions/fiber.Error'
summary: Performs the analysis of the youtube video
/api/youtube/analysis-landing:
post:
Expand All @@ -980,18 +974,18 @@ paths:
description: OK
schema:
$ref: '#/definitions/models.YoutubeAnalyzerLandingRespBody'
"204":
description: No Content
schema:
$ref: '#/definitions/utils.HandleError.errorResponse'
"400":
description: Bad Request
schema:
$ref: '#/definitions/utils.HandleError.errorResponse'
$ref: '#/definitions/fiber.Error'
"404":
description: Not Found
schema:
$ref: '#/definitions/fiber.Error'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/utils.HandleError.errorResponse'
$ref: '#/definitions/fiber.Error'
summary: Simple analysis with BERT model for the landing page
/api/youtube/pre-analysis:
post:
Expand Down
3 changes: 1 addition & 2 deletions go-server/handlers/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"gptube/database"
"gptube/models"
"gptube/services"
"gptube/utils"
"log"
"math"
"net/http"
Expand Down Expand Up @@ -351,7 +350,7 @@ func BillingSubscriptionsWebhooks(c *fiber.Ctx) error {

prettyJSON, err := json.MarshalIndent(webhookBody, "", " ")
if err != nil {
return utils.HandleError(err, http.StatusInternalServerError, c)
return fiber.NewError(http.StatusInternalServerError, err.Error())
}

eventHandlers := make(map[string]func(
Expand Down
53 changes: 21 additions & 32 deletions go-server/handlers/youtube.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package handlers

import (
"errors"
"fmt"
"gptube/config"
"gptube/database"
"gptube/models"
"gptube/services"
"gptube/utils"
"log"
"math"
"net/http"
Expand Down Expand Up @@ -186,36 +184,33 @@ func YoutubePreAnalysisHandler(c *fiber.Ctx) error {
// @Produce json
// @Param video body models.YoutubeAnalyzerReqBody true "Youtube video analysis request body"
// @Success 200 {object} models.YoutubeAnalyzerRespBody
// @Failure 204 {object} utils.HandleError.errorResponse
// @Failure 400 {object} utils.HandleError.errorResponse
// @Failure 500 {object} utils.HandleError.errorResponse
// @Failure 400 {object} fiber.Error
// @Failure 404 {object} fiber.Error
// @Failure 500 {object} fiber.Error
// @Router /api/youtube/analysis [post]
func YoutubeAnalysisHandler(c *fiber.Ctx) error {
var body models.YoutubeAnalyzerReqBody

if err := c.BodyParser(&body); err != nil {
return utils.HandleError(err, http.StatusInternalServerError, c)
return fiber.NewError(http.StatusInternalServerError, "problem while parsing your request")
}

if body.VideoId == "" {
err := fmt.Errorf("you must provide the youtube video id")
return utils.HandleError(err, http.StatusBadRequest, c)
return fiber.NewError(http.StatusBadRequest, "you must provide the youtube video id")
}

if body.UserId == "" {
err := fmt.Errorf("you must provide your user id")
return utils.HandleError(err, http.StatusBadRequest, c)
return fiber.NewError(http.StatusBadRequest, "you must provide your user id")
}

videoData, err := services.GetVideoData(body.VideoId)
if err != nil {
if err.Error() == "video not found" {
err = fmt.Errorf("video analysis failed 😿, video not found please provide a valid video id")
return utils.HandleError(err, http.StatusBadRequest, c)
return fiber.NewError(http.StatusBadRequest, "video analysis failed 😿, video not found please provide a valid video id")
}
err = fmt.Errorf("video analysis for %q failed 😿, try again later or contact us",
videoData.Items[0].Snippet.Title)
return utils.HandleError(err, http.StatusBadRequest, c)
return fiber.NewError(http.StatusBadRequest, err.Error())
}

// This means we haven´t received email hence is a short video so we do
Expand All @@ -228,12 +223,10 @@ func YoutubeAnalysisHandler(c *fiber.Ctx) error {
if err != nil {
err = fmt.Errorf("video analysis for %q failed 😿, try again later or contact us",
videoData.Items[0].Snippet.Title)
return utils.HandleError(err, http.StatusInternalServerError, c)
return fiber.NewError(http.StatusInternalServerError, err.Error())
}

if analysis.Results.BertResults.SuccessCount == 0 && analysis.Results.RobertaResults.SuccessCount == 0 {
err = fmt.Errorf("video analysis for %q failed 😿, couldn't analyze any comment",
videoData.Items[0].Snippet.Title)
log.Printf("[YoutubeAnalysisHandler] Couldn't analyze any comment for a model\n")
log.Printf("[YoutubeAnalysisHandler] Number of comments success Bert: %d\n",
analysis.Results.BertResults.SuccessCount)
Expand All @@ -243,7 +236,7 @@ func YoutubeAnalysisHandler(c *fiber.Ctx) error {
analysis.Results.RobertaResults.SuccessCount)
log.Printf("[YoutubeAnalysisHandler] Number of comments failed Roberta: %d\n",
analysis.Results.RobertaResults.ErrorsCount)
return utils.HandleError(err, http.StatusNoContent, c)
return fiber.NewError(http.StatusNotFound, "We didn't found any negative comment.")
}

// sending the results to the user
Expand All @@ -258,8 +251,7 @@ func YoutubeAnalysisHandler(c *fiber.Ctx) error {
// Sending the e-mail error to the user
log.Printf("[YoutubeAnalysisHandler] Error saving data to firebase: %v\n",
err.Error())
return utils.HandleError(errors.New("error while saving analysis results"),
http.StatusInternalServerError, c)
return fiber.NewError(http.StatusInternalServerError, "error while doing the analysis")
}

////////////////////////////////////////////////
Expand Down Expand Up @@ -357,32 +349,29 @@ func YoutubeAnalysisHandler(c *fiber.Ctx) error {
// @Produce json
// @Param video body models.YoutubeAnalyzerLandingReqBody true "Youtube video id"
// @Success 200 {object} models.YoutubeAnalyzerLandingRespBody
// @Failure 204 {object} utils.HandleError.errorResponse
// @Failure 400 {object} utils.HandleError.errorResponse
// @Failure 500 {object} utils.HandleError.errorResponse
// @Failure 400 {object} fiber.Error
// @Failure 404 {object} fiber.Error
// @Failure 500 {object} fiber.Error
// @Router /api/youtube/analysis-landing [post]
func YoutubeAnalysisLandingHandler(c *fiber.Ctx) error {
var body models.YoutubeAnalyzerLandingReqBody

if err := c.BodyParser(&body); err != nil {
err := fmt.Errorf("video analysis failed 😿, incorrect body encoding")
return utils.HandleError(err, http.StatusInternalServerError, c)
return fiber.NewError(http.StatusInternalServerError, "video analysis failed 😿, incorrect body encoding")
}

if body.VideoID == "" {
err := fmt.Errorf("video analysis failed 😿, please provide a video id")
return utils.HandleError(err, http.StatusBadRequest, c)
return fiber.NewError(http.StatusBadRequest, "video analysis failed 😿, please provide a video id")
}

videoData, err := services.GetVideoData(body.VideoID)
if err != nil {
if err.Error() == "video not found" {
err = fmt.Errorf("video analysis failed 😿, video not found please provide a valid video id")
return utils.HandleError(err, http.StatusBadRequest, c)
return fiber.NewError(http.StatusBadRequest, "video analysis failed 😿, video not found please provide a valid video id")
}
err = fmt.Errorf("video analysis for %q failed 😿, try again later or contact us",
videoData.Items[0].Snippet.Title)
return utils.HandleError(err, http.StatusBadRequest, c)
return fiber.NewError(http.StatusBadRequest, err.Error())
}

// This means we haven´t received email hence is a short video so we do
Expand All @@ -391,13 +380,13 @@ func YoutubeAnalysisLandingHandler(c *fiber.Ctx) error {
if err != nil {
err = fmt.Errorf("video analysis for %q failed 😿, try again later or contact us",
videoData.Items[0].Snippet.Title)
return utils.HandleError(err, http.StatusInternalServerError, c)
return fiber.NewError(http.StatusInternalServerError, err.Error())
}

if results.BertResults.SuccessCount == 0 {
noContentError := fmt.Errorf("video analysis for %q failed 😿, we couldn't analyze any comment",
noContentError := fmt.Errorf("we didn't found any negative comment for video: %q",
videoData.Items[0].Snippet.Title)
return utils.HandleError(noContentError, http.StatusNoContent, c)
return fiber.NewError(http.StatusNotFound, noContentError.Error())
}

// sending the results to the user
Expand Down
7 changes: 6 additions & 1 deletion gptube/app/dashboard/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
'use client'
import type { Metadata } from 'next'

import { DashboardNavigation } from '@/components/dashboard/navigation'
import { Header } from '@/components/header'

export const metadata: Metadata = {
title: 'GPTube Dashboard',
}

export default function DashboardLayout({ children }: { children: React.ReactNode }) {
return (
<>
Expand Down
Loading

1 comment on commit 3cc5a9c

@vercel
Copy link

@vercel vercel bot commented on 3cc5a9c Dec 9, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

gptube-subscriptions – ./subscriptions-server

gptube-subscriptions-git-main-luckly083-gmailcom.vercel.app
gptube-subscriptions-luckly083-gmailcom.vercel.app
gptube-subscriptions.vercel.app

Please sign in to comment.