Skip to content

Commit

Permalink
Merge pull request #70 from yuminn-k/docs/add-missing-comments
Browse files Browse the repository at this point in the history
주석 누락된 함수 및 타입에 대한 문서화 개선
  • Loading branch information
yuminn-k authored Oct 19, 2024
2 parents 506ef02 + 94097fe commit 9748a49
Show file tree
Hide file tree
Showing 53 changed files with 178 additions and 42 deletions.
5 changes: 5 additions & 0 deletions api/controller/category_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ import (
"github.com/ryokushaka/project_YoriEat-gin-deployment-repo/domain"
)

// CategoryController handles category-related HTTP requests.
type CategoryController struct {
CategoryUsecase domain.CategoryUsecase
}

// NewCategoryController creates a new CategoryController.
func NewCategoryController(cu domain.CategoryUsecase) *CategoryController {
return &CategoryController{
CategoryUsecase: cu,
}
}

// CreateCategory handles the creation of a new category.
func (cc *CategoryController) CreateCategory(c *gin.Context) {
var category domain.Category
if err := c.ShouldBindJSON(&category); err != nil {
Expand All @@ -33,6 +36,7 @@ func (cc *CategoryController) CreateCategory(c *gin.Context) {
c.JSON(http.StatusCreated, category)
}

// FetchCategories handles fetching all categories.
func (cc *CategoryController) FetchCategories(c *gin.Context) {
categories, err := cc.CategoryUsecase.Fetch(c.Request.Context())
if err != nil {
Expand All @@ -43,6 +47,7 @@ func (cc *CategoryController) FetchCategories(c *gin.Context) {
c.JSON(http.StatusOK, categories)
}

// GetCategoryByID handles fetching a category by its ID.
func (cc *CategoryController) GetCategoryByID(c *gin.Context) {
id := c.Param("id")
category, err := cc.CategoryUsecase.GetByID(c.Request.Context(), id)
Expand Down
5 changes: 5 additions & 0 deletions api/controller/comment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ import (
"github.com/ryokushaka/project_YoriEat-gin-deployment-repo/domain"
)

// CommentController handles comment-related HTTP requests.
type CommentController struct {
CommentUsecase domain.CommentUsecase
}

// NewCommentController creates a new CommentController.
func NewCommentController(cu domain.CommentUsecase) *CommentController {
return &CommentController{
CommentUsecase: cu,
}
}

// CreateComment handles the creation of a new comment.
func (cc *CommentController) CreateComment(c *gin.Context) {
var comment domain.Comment
if err := c.ShouldBindJSON(&comment); err != nil {
Expand All @@ -34,6 +37,7 @@ func (cc *CommentController) CreateComment(c *gin.Context) {
c.JSON(http.StatusCreated, comment)
}

// FetchCommentsByRecipeID handles fetching comments by recipe ID.
func (cc *CommentController) FetchCommentsByRecipeID(c *gin.Context) {
recipeID, err := strconv.Atoi(c.Param("recipe_id"))
if err != nil {
Expand All @@ -50,6 +54,7 @@ func (cc *CommentController) FetchCommentsByRecipeID(c *gin.Context) {
c.JSON(http.StatusOK, comments)
}

// GetCommentByID handles fetching a comment by its ID.
func (cc *CommentController) GetCommentByID(c *gin.Context) {
id := c.Param("id")
comment, err := cc.CommentUsecase.GetByID(c.Request.Context(), id)
Expand Down
3 changes: 3 additions & 0 deletions api/controller/login_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ import (
"github.com/ryokushaka/project_YoriEat-gin-deployment-repo/domain"
)

// LoginController handles login-related HTTP requests.
type LoginController struct {
LoginUsecase domain.LoginUsecase
Env *bootstrap.Env
}

// NewLoginController creates a new LoginController.
func NewLoginController(usecase domain.LoginUsecase) *LoginController {
return &LoginController{
LoginUsecase: usecase,
}
}

// Login handles user login requests.
func (lc *LoginController) Login(c *gin.Context) {
var request domain.LoginRequest

Expand Down
7 changes: 7 additions & 0 deletions api/controller/recipe_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ import (
"github.com/ryokushaka/project_YoriEat-gin-deployment-repo/domain"
)

// RecipeController handles recipe-related HTTP requests.
type RecipeController struct {
RecipeUsecase domain.RecipeUsecase
}

// NewRecipeController creates a new RecipeController.
func NewRecipeController(ru domain.RecipeUsecase) *RecipeController {
return &RecipeController{
RecipeUsecase: ru,
}
}

// CreateRecipe handles the creation of a new recipe.
func (rc *RecipeController) CreateRecipe(c *gin.Context) {
var recipe domain.Recipe
if err := c.ShouldBindJSON(&recipe); err != nil {
Expand All @@ -33,6 +36,7 @@ func (rc *RecipeController) CreateRecipe(c *gin.Context) {
c.JSON(http.StatusCreated, recipe)
}

// FetchRecipes handles fetching all recipes.
func (rc *RecipeController) FetchRecipes(c *gin.Context) {
recipes, err := rc.RecipeUsecase.Fetch(c.Request.Context())
if err != nil {
Expand All @@ -43,6 +47,7 @@ func (rc *RecipeController) FetchRecipes(c *gin.Context) {
c.JSON(http.StatusOK, recipes)
}

// GetRecipeByID handles fetching a recipe by its ID.
func (rc *RecipeController) GetRecipeByID(c *gin.Context) {
id := c.Param("id")
recipe, err := rc.RecipeUsecase.GetByID(c.Request.Context(), id)
Expand All @@ -59,6 +64,7 @@ func (rc *RecipeController) GetRecipeByID(c *gin.Context) {
c.JSON(http.StatusOK, recipe)
}

// UpdateRecipe handles updating an existing recipe.
func (rc *RecipeController) UpdateRecipe(c *gin.Context) {
var recipe domain.Recipe
if err := c.ShouldBindJSON(&recipe); err != nil {
Expand All @@ -75,6 +81,7 @@ func (rc *RecipeController) UpdateRecipe(c *gin.Context) {
c.JSON(http.StatusOK, recipe)
}

// DeleteRecipe handles deleting a recipe by its ID.
func (rc *RecipeController) DeleteRecipe(c *gin.Context) {
id := c.Param("id")
err := rc.RecipeUsecase.Delete(c.Request.Context(), id)
Expand Down
2 changes: 2 additions & 0 deletions api/controller/refresh_token_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import (
"github.com/ryokushaka/project_YoriEat-gin-deployment-repo/domain"
)

// RefreshTokenController handles refresh token-related HTTP requests.
type RefreshTokenController struct {
RefreshTokenUsecase domain.RefreshTokenUsecase
Env *bootstrap.Env
}

// RefreshToken handles the refresh token requests.
func (rtc *RefreshTokenController) RefreshToken(c *gin.Context) {
var request domain.RefreshTokenRequest

Expand Down
7 changes: 7 additions & 0 deletions api/controller/script_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ import (
"github.com/ryokushaka/project_YoriEat-gin-deployment-repo/domain"
)

// ScriptController handles script-related HTTP requests.
type ScriptController struct {
ScriptUsecase domain.ScriptUsecase
}

// NewScriptController creates a new ScriptController.
func NewScriptController(su domain.ScriptUsecase) *ScriptController {
return &ScriptController{
ScriptUsecase: su,
}
}

// CreateScript handles the creation of a new script.
func (sc *ScriptController) CreateScript(c *gin.Context) {
var script domain.Script
if err := c.ShouldBindJSON(&script); err != nil {
Expand All @@ -34,6 +37,7 @@ func (sc *ScriptController) CreateScript(c *gin.Context) {
c.JSON(http.StatusCreated, script)
}

// FetchScripts handles fetching all scripts.
func (sc *ScriptController) FetchScripts(c *gin.Context) {
scripts, err := sc.ScriptUsecase.Fetch(c.Request.Context())
if err != nil {
Expand All @@ -44,6 +48,7 @@ func (sc *ScriptController) FetchScripts(c *gin.Context) {
c.JSON(http.StatusOK, scripts)
}

// GetScriptByID handles fetching a script by its ID.
func (sc *ScriptController) GetScriptByID(c *gin.Context) {
id := c.Param("id")
script, err := sc.ScriptUsecase.GetByID(c.Request.Context(), id)
Expand All @@ -60,6 +65,7 @@ func (sc *ScriptController) GetScriptByID(c *gin.Context) {
c.JSON(http.StatusOK, script)
}

// AddRecipeToScript handles adding a recipe to a script.
func (sc *ScriptController) AddRecipeToScript(c *gin.Context) {
scriptID, err := strconv.Atoi(c.Param("script_id"))
if err != nil {
Expand All @@ -85,6 +91,7 @@ func (sc *ScriptController) AddRecipeToScript(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "Recipe added to script"})
}

// RemoveRecipeFromScript handles removing a recipe from a script.
func (sc *ScriptController) RemoveRecipeFromScript(c *gin.Context) {
scriptID, err := strconv.Atoi(c.Param("script_id"))
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions api/controller/signup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import (
"golang.org/x/crypto/bcrypt"
)

// SignupController handles signup-related HTTP requests.
type SignupController struct {
SignupUsecase domain.SignupUsecase
Env *bootstrap.Env
}

// Signup handles user signup requests.
func (sc *SignupController) Signup(c *gin.Context) {
var request domain.SignupRequest

Expand Down
7 changes: 7 additions & 0 deletions api/controller/user_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ import (
"github.com/ryokushaka/project_YoriEat-gin-deployment-repo/domain"
)

// UserController handles user-related HTTP requests.
type UserController struct {
UserUsecase domain.UserUsecase
}

// NewUserController creates a new UserController.
func NewUserController(uu domain.UserUsecase) *UserController {
return &UserController{
UserUsecase: uu,
}
}

// CreateUser handles the creation of a new user.
func (uc *UserController) CreateUser(c *gin.Context) {
var user domain.User
if err := c.ShouldBindJSON(&user); err != nil {
Expand All @@ -33,6 +36,7 @@ func (uc *UserController) CreateUser(c *gin.Context) {
c.JSON(http.StatusCreated, user)
}

// FetchUsers handles fetching all users.
func (uc *UserController) FetchUsers(c *gin.Context) {
users, err := uc.UserUsecase.Fetch(c.Request.Context())
if err != nil {
Expand All @@ -43,6 +47,7 @@ func (uc *UserController) FetchUsers(c *gin.Context) {
c.JSON(http.StatusOK, users)
}

// GetUserByEmail handles fetching a user by their email.
func (uc *UserController) GetUserByEmail(c *gin.Context) {
email := c.Param("email")
user, err := uc.UserUsecase.GetByEmail(c.Request.Context(), email)
Expand All @@ -59,6 +64,7 @@ func (uc *UserController) GetUserByEmail(c *gin.Context) {
c.JSON(http.StatusOK, user)
}

// GetUserByID handles fetching a user by their ID.
func (uc *UserController) GetUserByID(c *gin.Context) {
id := c.Param("id")
user, err := uc.UserUsecase.GetByID(c.Request.Context(), id)
Expand All @@ -75,6 +81,7 @@ func (uc *UserController) GetUserByID(c *gin.Context) {
c.JSON(http.StatusOK, user)
}

// UpdateUser handles updating an existing user.
func (uc *UserController) UpdateUser(c *gin.Context) {
var user domain.User
if err := c.ShouldBindJSON(&user); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions api/controller/user_like_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ import (
"github.com/ryokushaka/project_YoriEat-gin-deployment-repo/domain"
)

// UserLikesController handles user likes-related HTTP requests.
type UserLikesController struct {
UserLikesUsecase domain.UserLikesUsecase
}

// NewUserLikesController creates a new UserLikesController.
func NewUserLikesController(ulu domain.UserLikesUsecase) *UserLikesController {
return &UserLikesController{
UserLikesUsecase: ulu,
}
}

// AddLike handles adding a like to a recipe by a user.
func (ulc *UserLikesController) AddLike(c *gin.Context) {
userID, err := strconv.Atoi(c.Param("user_id"))
if err != nil {
Expand All @@ -43,6 +46,7 @@ func (ulc *UserLikesController) AddLike(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "Like added"})
}

// RemoveLike handles removing a like from a recipe by a user.
func (ulc *UserLikesController) RemoveLike(c *gin.Context) {
userID, err := strconv.Atoi(c.Param("user_id"))
if err != nil {
Expand All @@ -65,6 +69,7 @@ func (ulc *UserLikesController) RemoveLike(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "Like removed"})
}

// FetchLikesByUserID handles fetching all likes by a user.
func (ulc *UserLikesController) FetchLikesByUserID(c *gin.Context) {
userID, err := strconv.Atoi("user_id")
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions api/middleware/jwt_auth_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/ryokushaka/project_YoriEat-gin-deployment-repo/internal/tokenutil"
)

// JwtAuthMiddleware returns a middleware function that validates JWT tokens.
func JwtAuthMiddleware(secret string) gin.HandlerFunc {
return func(c *gin.Context) {
authHeader := c.Request.Header.Get("Authorization")
Expand Down
1 change: 1 addition & 0 deletions api/route/category_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"gorm.io/gorm"
)

// NewCategoryRouter sets up the category routes.
func NewCategoryRouter(env *bootstrap.Env, db *gorm.DB, group *gin.RouterGroup) {
categoryRepo := repository.NewCategoryRepository(db)
categoryUsecase := usecase.NewCategoryUsecase(categoryRepo)
Expand Down
1 change: 1 addition & 0 deletions api/route/comment_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"gorm.io/gorm"
)

// NewCommentRouter sets up the comment routes.
func NewCommentRouter(env *bootstrap.Env, db *gorm.DB, group *gin.RouterGroup) {
commentRepo := repository.NewCommentRepository(db)
commentUsecase := usecase.NewCommentUsecase(commentRepo)
Expand Down
1 change: 1 addition & 0 deletions api/route/login_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"gorm.io/gorm"
)

// NewLoginRouter sets up the login routes.
func NewLoginRouter(env *bootstrap.Env, db *gorm.DB, group *gin.RouterGroup) {
userRepo := repository.NewUserRepository(db)
tokenSecret := env.AccessTokenSecret
Expand Down
1 change: 1 addition & 0 deletions api/route/recipe_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"gorm.io/gorm"
)

// NewRecipeRouter sets up the recipe routes.
func NewRecipeRouter(env *bootstrap.Env, db *gorm.DB, group *gin.RouterGroup) {
recipeRepo := repository.NewRecipeRepository(db)
recipeUsecase := usecase.NewRecipeUsecase(recipeRepo)
Expand Down
1 change: 1 addition & 0 deletions api/route/refresh_token_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"gorm.io/gorm"
)

// NewRefreshTokenRouter sets up the refresh token routes.
func NewRefreshTokenRouter(env *bootstrap.Env, db *gorm.DB, group *gin.RouterGroup) {
ur := repository.NewUserRepository(db)
tokenSecret := env.AccessTokenSecret
Expand Down
Loading

0 comments on commit 9748a49

Please sign in to comment.