-
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.
- Loading branch information
Showing
17 changed files
with
353 additions
and
29 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 repository | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/team-nerd-planet/api-server/infra/database" | ||
"github.com/team-nerd-planet/api-server/internal/entity" | ||
) | ||
|
||
type FeedRepo struct { | ||
db *database.Database | ||
} | ||
|
||
func NewFeedRepo(db *database.Database) entity.FeedRepo { | ||
return &FeedRepo{ | ||
db: db, | ||
} | ||
} | ||
|
||
// FindAll implements entity.FeedRepo. | ||
func (fr *FeedRepo) FindAll(keyword *string) ([]entity.Feed, error) { | ||
var ( | ||
feeds []entity.Feed | ||
where = make([]string, 0) | ||
param = make([]interface{}, 0) | ||
) | ||
|
||
if keyword != nil { | ||
where = append(where, "name LIKE ?") | ||
param = append(param, fmt.Sprintf("%s%%", *keyword)) | ||
} | ||
|
||
err := fr.db. | ||
Where(strings.Join(where, " AND "), param...). | ||
Order("name"). | ||
Find(&feeds).Error | ||
|
||
return feeds, err | ||
} |
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,39 @@ | ||
package handler | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/team-nerd-planet/api-server/infra/router/util" | ||
"github.com/team-nerd-planet/api-server/internal/controller/rest" | ||
"github.com/team-nerd-planet/api-server/internal/controller/rest/dto/feed_dto" | ||
) | ||
|
||
// SearchFeedName | ||
// | ||
// @Summary Search Feed Name | ||
// @Description search feed's name | ||
// @Tags feed | ||
// @Schemes http | ||
// @Accept json | ||
// @Produce json | ||
// @Param name_keyword query string false "회사 이름 검색 키워드" | ||
// @Success 200 {object} []feed_dto.SearchRes | ||
// @Failure 400 {object} util.HTTPError | ||
// @Failure 500 {object} util.HTTPError | ||
// @Router /v1/feed/search [get] | ||
func SearchFeedName(c *gin.Context, ctrl rest.FeedController) { | ||
req, err := util.ValidateQuery[feed_dto.SearchReq](c) | ||
if err != nil { | ||
util.NewError(c, http.StatusBadRequest, err) | ||
return | ||
} | ||
|
||
res, ok := ctrl.Search(*req) | ||
if !ok { | ||
util.NewError(c, http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
c.JSON(http.StatusOK, res) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package feed_dto | ||
|
||
import "github.com/team-nerd-planet/api-server/internal/entity" | ||
|
||
type SearchReq struct { | ||
NameKeyword string `form:"name_keyword" binding:"min=1"` // 회사 이름 검색어 | ||
} | ||
|
||
type SearchRes struct { | ||
ID uint `json:"id"` | ||
Name string `json:"name"` | ||
} | ||
|
||
func NewSearchRes(feeds []entity.Feed) []SearchRes { | ||
res := make([]SearchRes, len(feeds)) | ||
|
||
for i, feed := range feeds { | ||
res[i] = SearchRes{ | ||
ID: feed.ID, | ||
Name: feed.Name, | ||
} | ||
} | ||
|
||
return res | ||
} |
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 |
---|---|---|
|
@@ -6,4 +6,4 @@ type ApproveReq struct { | |
|
||
type ApproveRes struct { | ||
Ok bool `json:"ok"` // 구독 인증 결과 | ||
} | ||
} |
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,27 @@ | ||
package rest | ||
|
||
import ( | ||
"github.com/team-nerd-planet/api-server/internal/controller/rest/dto/feed_dto" | ||
"github.com/team-nerd-planet/api-server/internal/usecase/feed" | ||
) | ||
|
||
type FeedController struct { | ||
feedUcase feed.FeedUsecase | ||
} | ||
|
||
func NewFeedController(feedUsecase feed.FeedUsecase) FeedController { | ||
return FeedController{ | ||
feedUcase: feedUsecase, | ||
} | ||
} | ||
|
||
func (fc FeedController) Search(req feed_dto.SearchReq) ([]feed_dto.SearchRes, bool) { | ||
res := make([]feed_dto.SearchRes, 0) | ||
|
||
feeds, ok := fc.feedUcase.FindAll(&req.NameKeyword) | ||
if !ok { | ||
return res, false | ||
} | ||
|
||
return feed_dto.NewSearchRes(*feeds), true | ||
} |
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,27 @@ | ||
package feed | ||
|
||
import ( | ||
"log/slog" | ||
|
||
"github.com/team-nerd-planet/api-server/internal/entity" | ||
) | ||
|
||
type FeedUsecase struct { | ||
feedRepo entity.FeedRepo | ||
} | ||
|
||
func NewFeedUsecase(feedRepo entity.FeedRepo) FeedUsecase { | ||
return FeedUsecase{ | ||
feedRepo: feedRepo, | ||
} | ||
} | ||
|
||
func (fu FeedUsecase) FindAll(keyword *string) (*[]entity.Feed, bool) { | ||
feeds, err := fu.feedRepo.FindAll(keyword) | ||
if err != nil { | ||
slog.Error(err.Error(), "error", err) | ||
return nil, false | ||
} | ||
|
||
return &feeds, true | ||
} |
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
Oops, something went wrong.