fix:profile api get
This commit is contained in:
parent
e10e8b03fc
commit
5bee8af44c
|
|
@ -26,8 +26,9 @@ func NewEducationHistoryRepository(db *database.Database) EducationHistoryReposi
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_i *educationHistoryRepository) GetAll(userId uint, req request.EducationHistoryQueryRequest) (educationHistories []*entity.EducationHistory, paging paginator.Pagination, err error) {
|
func (_i *educationHistoryRepository) GetAll(userId uint, req request.EducationHistoryQueryRequest) (educationHistories []*entity.EducationHistory, paging paginator.Pagination, err error) {
|
||||||
query := _i.DB.DB.Where("user_id = ?", userId)
|
query := _i.DB.DB.
|
||||||
|
Model(&entity.EducationHistory{}).
|
||||||
|
Where("user_id = ?", userId)
|
||||||
// Apply filters
|
// Apply filters
|
||||||
if req.SchoolName != nil {
|
if req.SchoolName != nil {
|
||||||
query = query.Where("school_name ILIKE ?", "%"+*req.SchoolName+"%")
|
query = query.Where("school_name ILIKE ?", "%"+*req.SchoolName+"%")
|
||||||
|
|
|
||||||
|
|
@ -47,9 +47,9 @@ func (_i *researchJournalsController) All(c *fiber.Ctx) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
authHeader := c.Get("Authorization")
|
|
||||||
|
|
||||||
reqContext := request.ResearchJournalsQueryRequestContext{
|
reqContext := request.ResearchJournalsQueryRequestContext{
|
||||||
|
UserID: c.Query("userId"),
|
||||||
|
|
||||||
JournalTitle: c.Query("journalTitle"),
|
JournalTitle: c.Query("journalTitle"),
|
||||||
Publisher: c.Query("publisher"),
|
Publisher: c.Query("publisher"),
|
||||||
PublishedYear: c.Query("publishedYear"),
|
PublishedYear: c.Query("publishedYear"),
|
||||||
|
|
@ -64,7 +64,7 @@ func (_i *researchJournalsController) All(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
journalsData, paging, err := _i.researchJournalsService.All(authHeader, req)
|
journalsData, paging, err := _i.researchJournalsService.All(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,9 @@ func NewResearchJournalsRepository(db *database.Database) ResearchJournalsReposi
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_i *researchJournalsRepository) GetAll(userId uint, req request.ResearchJournalsQueryRequest) (researchJournals []*entity.ResearchJournals, paging paginator.Pagination, err error) {
|
func (_i *researchJournalsRepository) GetAll(userId uint, req request.ResearchJournalsQueryRequest) (researchJournals []*entity.ResearchJournals, paging paginator.Pagination, err error) {
|
||||||
query := _i.DB.DB.Where("user_id = ?", userId)
|
query := _i.DB.DB.
|
||||||
|
Model(&entity.ResearchJournals{}).
|
||||||
|
Where("user_id = ?", userId)
|
||||||
// Apply filters
|
// Apply filters
|
||||||
if req.JournalTitle != nil {
|
if req.JournalTitle != nil {
|
||||||
query = query.Where("journal_title ILIKE ?", "%"+*req.JournalTitle+"%")
|
query = query.Where("journal_title ILIKE ?", "%"+*req.JournalTitle+"%")
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,12 @@ package request
|
||||||
import (
|
import (
|
||||||
"narasi-ahli-be/app/database/entity"
|
"narasi-ahli-be/app/database/entity"
|
||||||
"narasi-ahli-be/utils/paginator"
|
"narasi-ahli-be/utils/paginator"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ResearchJournalsQueryRequest struct {
|
type ResearchJournalsQueryRequest struct {
|
||||||
|
UserID uint `json:"userId" validate:"required"`
|
||||||
JournalTitle *string `json:"journalTitle"`
|
JournalTitle *string `json:"journalTitle"`
|
||||||
Publisher *string `json:"publisher"`
|
Publisher *string `json:"publisher"`
|
||||||
PublishedYear *int `json:"publishedYear"`
|
PublishedYear *int `json:"publishedYear"`
|
||||||
|
|
@ -46,6 +48,7 @@ func (req ResearchJournalsUpdateRequest) ToEntity() *entity.ResearchJournals {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResearchJournalsQueryRequestContext struct {
|
type ResearchJournalsQueryRequestContext struct {
|
||||||
|
UserID string `json:"userId"`
|
||||||
JournalTitle string `json:"journalTitle"`
|
JournalTitle string `json:"journalTitle"`
|
||||||
Publisher string `json:"publisher"`
|
Publisher string `json:"publisher"`
|
||||||
PublishedYear string `json:"publishedYear"`
|
PublishedYear string `json:"publishedYear"`
|
||||||
|
|
@ -54,6 +57,13 @@ type ResearchJournalsQueryRequestContext struct {
|
||||||
func (req ResearchJournalsQueryRequestContext) ToParamRequest() ResearchJournalsQueryRequest {
|
func (req ResearchJournalsQueryRequestContext) ToParamRequest() ResearchJournalsQueryRequest {
|
||||||
var request ResearchJournalsQueryRequest
|
var request ResearchJournalsQueryRequest
|
||||||
|
|
||||||
|
if userId := req.UserID; userId != "" {
|
||||||
|
userIdUint, err := strconv.ParseUint(userId, 10, 0)
|
||||||
|
if err == nil {
|
||||||
|
request.UserID = uint(userIdUint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if journalTitle := req.JournalTitle; journalTitle != "" {
|
if journalTitle := req.JournalTitle; journalTitle != "" {
|
||||||
request.JournalTitle = &journalTitle
|
request.JournalTitle = &journalTitle
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"log"
|
||||||
"narasi-ahli-be/app/module/research_journals/mapper"
|
"narasi-ahli-be/app/module/research_journals/mapper"
|
||||||
"narasi-ahli-be/app/module/research_journals/repository"
|
"narasi-ahli-be/app/module/research_journals/repository"
|
||||||
"narasi-ahli-be/app/module/research_journals/request"
|
"narasi-ahli-be/app/module/research_journals/request"
|
||||||
|
|
@ -20,7 +21,7 @@ type researchJournalsService struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResearchJournalsService interface {
|
type ResearchJournalsService interface {
|
||||||
All(authToken string, req request.ResearchJournalsQueryRequest) (researchJournals []*response.ResearchJournalsResponse, paging paginator.Pagination, err error)
|
All(req request.ResearchJournalsQueryRequest) (researchJournals []*response.ResearchJournalsResponse, paging paginator.Pagination, err error)
|
||||||
Show(authToken string, id uint) (researchJournal *response.ResearchJournalsResponse, err error)
|
Show(authToken string, id uint) (researchJournal *response.ResearchJournalsResponse, err error)
|
||||||
Save(authToken string, req request.ResearchJournalsCreateRequest) (researchJournal *response.ResearchJournalsResponse, err error)
|
Save(authToken string, req request.ResearchJournalsCreateRequest) (researchJournal *response.ResearchJournalsResponse, err error)
|
||||||
Update(authToken string, id uint, req request.ResearchJournalsUpdateRequest) (err error)
|
Update(authToken string, id uint, req request.ResearchJournalsUpdateRequest) (err error)
|
||||||
|
|
@ -35,19 +36,34 @@ func NewResearchJournalsService(repo repository.ResearchJournalsRepository, user
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_i *researchJournalsService) All(authToken string, req request.ResearchJournalsQueryRequest) (researchJournals []*response.ResearchJournalsResponse, paging paginator.Pagination, err error) {
|
// func (_i *researchJournalsService) All(authToken string, req request.ResearchJournalsQueryRequest) (researchJournals []*response.ResearchJournalsResponse, paging paginator.Pagination, err error) {
|
||||||
userInfo := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken)
|
// userInfo := utilSvc.GetUserInfo(_i.Log, _i.UsersRepo, authToken)
|
||||||
if userInfo == nil {
|
// if userInfo == nil {
|
||||||
return nil, paginator.Pagination{}, errors.New("unauthorized")
|
// return nil, paginator.Pagination{}, errors.New("unauthorized")
|
||||||
}
|
// }
|
||||||
|
|
||||||
results, paging, err := _i.Repo.GetAll(userInfo.ID, req)
|
// results, paging, err := _i.Repo.GetAll(userInfo.ID, req)
|
||||||
|
// if err != nil {
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
|
// for _, result := range results {
|
||||||
|
// researchJournals = append(researchJournals, mapper.ResearchJournalsResponseMapper(result))
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
|
func (_i *researchJournalsService) All(req request.ResearchJournalsQueryRequest) (educationHistories []*response.ResearchJournalsResponse, paging paginator.Pagination, err error) {
|
||||||
|
log.Println("USER ID:", req.UserID)
|
||||||
|
|
||||||
|
results, paging, err := _i.Repo.GetAll(req.UserID, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, result := range results {
|
for _, result := range results {
|
||||||
researchJournals = append(researchJournals, mapper.ResearchJournalsResponseMapper(result))
|
educationHistories = append(educationHistories, mapper.ResearchJournalsResponseMapper(result))
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,10 @@ func NewWorkHistoryRepository(db *database.Database) WorkHistoryRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_i *workHistoryRepository) GetAll(userId uint, req request.WorkHistoryQueryRequest) (workHistories []*entity.WorkHistory, paging paginator.Pagination, err error) {
|
func (_i *workHistoryRepository) GetAll(userId uint, req request.WorkHistoryQueryRequest) (workHistories []*entity.WorkHistory, paging paginator.Pagination, err error) {
|
||||||
query := _i.DB.DB.Where("user_id = ?", userId)
|
query := _i.DB.DB.
|
||||||
|
Model(&entity.WorkHistory{}).
|
||||||
|
Where("user_id = ?", userId)
|
||||||
|
|
||||||
// Apply filters
|
// Apply filters
|
||||||
if req.JobTitle != nil {
|
if req.JobTitle != nil {
|
||||||
query = query.Where("job_title ILIKE ?", "%"+*req.JobTitle+"%")
|
query = query.Where("job_title ILIKE ?", "%"+*req.JobTitle+"%")
|
||||||
|
|
|
||||||
|
|
@ -12881,6 +12881,12 @@ const docTemplate = `{
|
||||||
"name": "publisher",
|
"name": "publisher",
|
||||||
"in": "query"
|
"in": "query"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"name": "userId",
|
||||||
|
"in": "query",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"name": "count",
|
"name": "count",
|
||||||
|
|
|
||||||
|
|
@ -12870,6 +12870,12 @@
|
||||||
"name": "publisher",
|
"name": "publisher",
|
||||||
"in": "query"
|
"in": "query"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"name": "userId",
|
||||||
|
"in": "query",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"name": "count",
|
"name": "count",
|
||||||
|
|
|
||||||
|
|
@ -9656,6 +9656,10 @@ paths:
|
||||||
- in: query
|
- in: query
|
||||||
name: publisher
|
name: publisher
|
||||||
type: string
|
type: string
|
||||||
|
- in: query
|
||||||
|
name: userId
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
- in: query
|
- in: query
|
||||||
name: count
|
name: count
|
||||||
type: integer
|
type: integer
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue