paginate api list dokter
This commit is contained in:
@@ -123,6 +123,20 @@ const docTemplate = `{
|
|||||||
"description": "Search keyword",
|
"description": "Search keyword",
|
||||||
"name": "search",
|
"name": "search",
|
||||||
"in": "query"
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"default": "10",
|
||||||
|
"description": "Limit",
|
||||||
|
"name": "limit",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"default": "0",
|
||||||
|
"description": "Offset",
|
||||||
|
"name": "offset",
|
||||||
|
"in": "query"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
|
|||||||
@@ -117,6 +117,20 @@
|
|||||||
"description": "Search keyword",
|
"description": "Search keyword",
|
||||||
"name": "search",
|
"name": "search",
|
||||||
"in": "query"
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"default": "10",
|
||||||
|
"description": "Limit",
|
||||||
|
"name": "limit",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"default": "0",
|
||||||
|
"description": "Offset",
|
||||||
|
"name": "offset",
|
||||||
|
"in": "query"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
|
|||||||
@@ -282,6 +282,16 @@ paths:
|
|||||||
in: query
|
in: query
|
||||||
name: search
|
name: search
|
||||||
type: string
|
type: string
|
||||||
|
- default: "10"
|
||||||
|
description: Limit
|
||||||
|
in: query
|
||||||
|
name: limit
|
||||||
|
type: string
|
||||||
|
- default: "0"
|
||||||
|
description: Offset
|
||||||
|
in: query
|
||||||
|
name: offset
|
||||||
|
type: string
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: OK
|
description: OK
|
||||||
|
|||||||
@@ -21,13 +21,13 @@ func NewDokterHandler(repo IDokterRepository) DokterHandler {
|
|||||||
// @Summary Get List Dokter
|
// @Summary Get List Dokter
|
||||||
// @Tags Dokter
|
// @Tags Dokter
|
||||||
// @Param search query string false "Search keyword"
|
// @Param search query string false "Search keyword"
|
||||||
|
// @Param limit query string false "Limit" default(10)
|
||||||
|
// @Param offset query string false "Offset" default(0)
|
||||||
// @Success 200 {object} []DokterResponse
|
// @Success 200 {object} []DokterResponse
|
||||||
// @Failure 500 {object} shared.BaseErrorResponse
|
// @Failure 500 {object} shared.BaseErrorResponse
|
||||||
// @Router /dokter/ [get]
|
// @Router /dokter/ [get]
|
||||||
func (h DokterHandler) ListDokter(c *gin.Context) {
|
func (h DokterHandler) ListDokter(c *gin.Context) {
|
||||||
var list ListDokterModel
|
result, err := h.repo.SearchableListDokter(c)
|
||||||
|
|
||||||
list, err := h.repo.SearchableListDokter(c)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorResponse := baseResponse.BaseErrorResponse{
|
errorResponse := baseResponse.BaseErrorResponse{
|
||||||
Success: false,
|
Success: false,
|
||||||
@@ -38,8 +38,9 @@ func (h DokterHandler) ListDokter(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
response := baseResponse.ToBaseResponse(
|
response := baseResponse.ToBaseResponsePaginate(
|
||||||
list.ToResponseList(),
|
result.Data.ToResponseList(),
|
||||||
|
result.Paging,
|
||||||
true,
|
true,
|
||||||
200,
|
200,
|
||||||
"success get doctor's list")
|
"success get doctor's list")
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package dokter
|
package dokter
|
||||||
|
|
||||||
import "database/sql"
|
import (
|
||||||
|
"antrian-operasi/internal/shared"
|
||||||
|
"database/sql"
|
||||||
|
)
|
||||||
|
|
||||||
type DokterModel struct {
|
type DokterModel struct {
|
||||||
ID string `json:"id" db:"id"`
|
ID string `json:"id" db:"id"`
|
||||||
@@ -18,3 +21,8 @@ type DokterResponse struct {
|
|||||||
HfisCode *string `json:"hfis_code"`
|
HfisCode *string `json:"hfis_code"`
|
||||||
NamaKsm string `json:"nama_ksm"`
|
NamaKsm string `json:"nama_ksm"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ListDokterModelPaginate struct {
|
||||||
|
Data ListDokterModel
|
||||||
|
Paging shared.PaginationInfo
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ package dokter
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"antrian-operasi/internal/database"
|
"antrian-operasi/internal/database"
|
||||||
|
"antrian-operasi/internal/shared"
|
||||||
"errors"
|
"errors"
|
||||||
|
"log"
|
||||||
|
|
||||||
queryUtils "antrian-operasi/internal/utils/query"
|
queryUtils "antrian-operasi/internal/utils/query"
|
||||||
|
|
||||||
@@ -13,7 +15,7 @@ const DB_NAME = "db_antrian"
|
|||||||
const TBL_NAME = "data_pegawai"
|
const TBL_NAME = "data_pegawai"
|
||||||
|
|
||||||
type IDokterRepository interface {
|
type IDokterRepository interface {
|
||||||
SearchableListDokter(c *gin.Context) ([]DokterModel, error)
|
SearchableListDokter(c *gin.Context) (ListDokterModelPaginate, error)
|
||||||
GetDokterById(c *gin.Context, id string) (DokterModel, error)
|
GetDokterById(c *gin.Context, id string) (DokterModel, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,8 +74,10 @@ func baseSelectQuery() queryUtils.DynamicQuery {
|
|||||||
return query
|
return query
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r dokterRepo) SearchableListDokter(c *gin.Context) ([]DokterModel, error) {
|
func (r dokterRepo) SearchableListDokter(c *gin.Context) (ListDokterModelPaginate, error) {
|
||||||
var result []DokterModel
|
var result ListDokterModelPaginate
|
||||||
|
limit := shared.ParseQueryLimit(c)
|
||||||
|
offset := shared.ParseQueryOffset(c)
|
||||||
search := c.Query("search")
|
search := c.Query("search")
|
||||||
|
|
||||||
// base query
|
// base query
|
||||||
@@ -105,8 +109,23 @@ func (r dokterRepo) SearchableListDokter(c *gin.Context) ([]DokterModel, error)
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// query count
|
||||||
|
countData, err := r.queryBuilder.ExecuteCount(c, dbconn, query)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Unable to execute query count : %s ", err)
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
result.Paging.Limit = limit
|
||||||
|
result.Paging.Offset = offset
|
||||||
|
result.Paging.Total = int(countData)
|
||||||
|
result.Paging.CalculatePagingInfo()
|
||||||
|
|
||||||
|
// query data
|
||||||
|
queryData := query
|
||||||
|
queryData.Limit = limit
|
||||||
|
queryData.Offset = offset
|
||||||
err = r.queryBuilder.ExecuteQuery(
|
err = r.queryBuilder.ExecuteQuery(
|
||||||
c, dbconn, query, &result)
|
c, dbconn, queryData, &result.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// log.Fatalf("unable to execute query %s", err)
|
// log.Fatalf("unable to execute query %s", err)
|
||||||
return result, nil
|
return result, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user