userquizpaper title, category 등 추가
This commit is contained in:
parent
cb1cec3947
commit
6bb8dd3ada
60
docs/docs.go
60
docs/docs.go
@ -153,6 +153,43 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"Bearer": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "센터를 만듭니다.",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"센터"
|
||||||
|
],
|
||||||
|
"summary": "센터 생성",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "Center Body",
|
||||||
|
"name": "quizBody",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/learnsteam_cslms-api_internal_models.CenterRequest"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/learnsteam_cslms-api_internal_models.Center"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/center/{id}": {
|
"/center/{id}": {
|
||||||
@ -1154,7 +1191,7 @@ const docTemplate = `{
|
|||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "OK",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/learnsteam_cslms-api_internal_models.UserQuizPaperResponse"
|
"$ref": "#/definitions/learnsteam_cslms-api_internal_models.UserQuizPaper"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1879,7 +1916,7 @@ const docTemplate = `{
|
|||||||
"data": {
|
"data": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
"$ref": "#/definitions/learnsteam_cslms-api_internal_models.UserQuizPaper"
|
"$ref": "#/definitions/learnsteam_cslms-api_internal_models.UserQuizPaperResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"page": {
|
"page": {
|
||||||
@ -1949,13 +1986,24 @@ const docTemplate = `{
|
|||||||
"learnsteam_cslms-api_internal_models.UserQuizPaperResponse": {
|
"learnsteam_cslms-api_internal_models.UserQuizPaperResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"category": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "파이썬기본"
|
||||||
|
},
|
||||||
"center_id": {
|
"center_id": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"example": 1000015
|
"example": 1000015
|
||||||
},
|
},
|
||||||
|
"created_at": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"done_at": {
|
"done_at": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"first_name": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "길순"
|
||||||
|
},
|
||||||
"guid_id": {
|
"guid_id": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"example": "7f9329f5-2e36-4638-92d2-73064b7291a4"
|
"example": "7f9329f5-2e36-4638-92d2-73064b7291a4"
|
||||||
@ -1964,6 +2012,10 @@ const docTemplate = `{
|
|||||||
"type": "integer",
|
"type": "integer",
|
||||||
"example": 1000015
|
"example": 1000015
|
||||||
},
|
},
|
||||||
|
"last_name": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "홍"
|
||||||
|
},
|
||||||
"quiz_paper_id": {
|
"quiz_paper_id": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"example": 1000001
|
"example": 1000001
|
||||||
@ -1975,6 +2027,10 @@ const docTemplate = `{
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"example": "wating"
|
"example": "wating"
|
||||||
},
|
},
|
||||||
|
"title": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "출력 Print"
|
||||||
|
},
|
||||||
"total_score": {
|
"total_score": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"example": 100
|
"example": 100
|
||||||
|
@ -145,6 +145,43 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"Bearer": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "센터를 만듭니다.",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"센터"
|
||||||
|
],
|
||||||
|
"summary": "센터 생성",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "Center Body",
|
||||||
|
"name": "quizBody",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/learnsteam_cslms-api_internal_models.CenterRequest"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/learnsteam_cslms-api_internal_models.Center"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/center/{id}": {
|
"/center/{id}": {
|
||||||
@ -1146,7 +1183,7 @@
|
|||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "OK",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/learnsteam_cslms-api_internal_models.UserQuizPaperResponse"
|
"$ref": "#/definitions/learnsteam_cslms-api_internal_models.UserQuizPaper"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1871,7 +1908,7 @@
|
|||||||
"data": {
|
"data": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
"$ref": "#/definitions/learnsteam_cslms-api_internal_models.UserQuizPaper"
|
"$ref": "#/definitions/learnsteam_cslms-api_internal_models.UserQuizPaperResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"page": {
|
"page": {
|
||||||
@ -1941,13 +1978,24 @@
|
|||||||
"learnsteam_cslms-api_internal_models.UserQuizPaperResponse": {
|
"learnsteam_cslms-api_internal_models.UserQuizPaperResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"category": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "파이썬기본"
|
||||||
|
},
|
||||||
"center_id": {
|
"center_id": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"example": 1000015
|
"example": 1000015
|
||||||
},
|
},
|
||||||
|
"created_at": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"done_at": {
|
"done_at": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"first_name": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "길순"
|
||||||
|
},
|
||||||
"guid_id": {
|
"guid_id": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"example": "7f9329f5-2e36-4638-92d2-73064b7291a4"
|
"example": "7f9329f5-2e36-4638-92d2-73064b7291a4"
|
||||||
@ -1956,6 +2004,10 @@
|
|||||||
"type": "integer",
|
"type": "integer",
|
||||||
"example": 1000015
|
"example": 1000015
|
||||||
},
|
},
|
||||||
|
"last_name": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "홍"
|
||||||
|
},
|
||||||
"quiz_paper_id": {
|
"quiz_paper_id": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"example": 1000001
|
"example": 1000001
|
||||||
@ -1967,6 +2019,10 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"example": "wating"
|
"example": "wating"
|
||||||
},
|
},
|
||||||
|
"title": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "출력 Print"
|
||||||
|
},
|
||||||
"total_score": {
|
"total_score": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"example": 100
|
"example": 100
|
||||||
|
@ -510,7 +510,7 @@ definitions:
|
|||||||
properties:
|
properties:
|
||||||
data:
|
data:
|
||||||
items:
|
items:
|
||||||
$ref: '#/definitions/learnsteam_cslms-api_internal_models.UserQuizPaper'
|
$ref: '#/definitions/learnsteam_cslms-api_internal_models.UserQuizPaperResponse'
|
||||||
type: array
|
type: array
|
||||||
page:
|
page:
|
||||||
example: 1
|
example: 1
|
||||||
@ -560,17 +560,28 @@ definitions:
|
|||||||
type: object
|
type: object
|
||||||
learnsteam_cslms-api_internal_models.UserQuizPaperResponse:
|
learnsteam_cslms-api_internal_models.UserQuizPaperResponse:
|
||||||
properties:
|
properties:
|
||||||
|
category:
|
||||||
|
example: 파이썬기본
|
||||||
|
type: string
|
||||||
center_id:
|
center_id:
|
||||||
example: 1000015
|
example: 1000015
|
||||||
type: integer
|
type: integer
|
||||||
|
created_at:
|
||||||
|
type: string
|
||||||
done_at:
|
done_at:
|
||||||
type: string
|
type: string
|
||||||
|
first_name:
|
||||||
|
example: 길순
|
||||||
|
type: string
|
||||||
guid_id:
|
guid_id:
|
||||||
example: 7f9329f5-2e36-4638-92d2-73064b7291a4
|
example: 7f9329f5-2e36-4638-92d2-73064b7291a4
|
||||||
type: string
|
type: string
|
||||||
id:
|
id:
|
||||||
example: 1000015
|
example: 1000015
|
||||||
type: integer
|
type: integer
|
||||||
|
last_name:
|
||||||
|
example: 홍
|
||||||
|
type: string
|
||||||
quiz_paper_id:
|
quiz_paper_id:
|
||||||
example: 1000001
|
example: 1000001
|
||||||
type: integer
|
type: integer
|
||||||
@ -579,6 +590,9 @@ definitions:
|
|||||||
status:
|
status:
|
||||||
example: wating
|
example: wating
|
||||||
type: string
|
type: string
|
||||||
|
title:
|
||||||
|
example: 출력 Print
|
||||||
|
type: string
|
||||||
total_score:
|
total_score:
|
||||||
example: 100
|
example: 100
|
||||||
type: number
|
type: number
|
||||||
@ -798,6 +812,29 @@ paths:
|
|||||||
summary: 센터 목록 가져오기
|
summary: 센터 목록 가져오기
|
||||||
tags:
|
tags:
|
||||||
- 센터
|
- 센터
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: 센터를 만듭니다.
|
||||||
|
parameters:
|
||||||
|
- description: Center Body
|
||||||
|
in: body
|
||||||
|
name: quizBody
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/learnsteam_cslms-api_internal_models.CenterRequest'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/learnsteam_cslms-api_internal_models.Center'
|
||||||
|
security:
|
||||||
|
- Bearer: []
|
||||||
|
summary: 센터 생성
|
||||||
|
tags:
|
||||||
|
- 센터
|
||||||
/center/{id}:
|
/center/{id}:
|
||||||
get:
|
get:
|
||||||
consumes:
|
consumes:
|
||||||
@ -1397,7 +1434,7 @@ paths:
|
|||||||
"200":
|
"200":
|
||||||
description: OK
|
description: OK
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/learnsteam_cslms-api_internal_models.UserQuizPaperResponse'
|
$ref: '#/definitions/learnsteam_cslms-api_internal_models.UserQuizPaper'
|
||||||
security:
|
security:
|
||||||
- Bearer: []
|
- Bearer: []
|
||||||
summary: 응시 정보 변경
|
summary: 응시 정보 변경
|
||||||
|
2
go.mod
2
go.mod
@ -10,7 +10,6 @@ require (
|
|||||||
github.com/stretchr/testify v1.8.4
|
github.com/stretchr/testify v1.8.4
|
||||||
github.com/swaggo/files v1.0.1
|
github.com/swaggo/files v1.0.1
|
||||||
github.com/swaggo/gin-swagger v1.6.0
|
github.com/swaggo/gin-swagger v1.6.0
|
||||||
github.com/swaggo/swag v1.16.2
|
|
||||||
golang.org/x/crypto v0.15.0
|
golang.org/x/crypto v0.15.0
|
||||||
gorm.io/datatypes v1.2.0
|
gorm.io/datatypes v1.2.0
|
||||||
gorm.io/driver/mysql v1.5.2
|
gorm.io/driver/mysql v1.5.2
|
||||||
@ -49,6 +48,7 @@ require (
|
|||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
|
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
github.com/swaggo/swag v1.16.2 // indirect
|
||||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||||
golang.org/x/arch v0.6.0 // indirect
|
golang.org/x/arch v0.6.0 // indirect
|
||||||
|
@ -136,7 +136,7 @@ func (controller *centerController) Find(c *gin.Context) {
|
|||||||
// @Param quizBody body models.CenterRequest true "Center Body"
|
// @Param quizBody body models.CenterRequest true "Center Body"
|
||||||
//
|
//
|
||||||
// @Success 200 {object} models.Center
|
// @Success 200 {object} models.Center
|
||||||
// @Router /quiz [post]
|
// @Router /center [post]
|
||||||
func (controller *centerController) Create(c *gin.Context) {
|
func (controller *centerController) Create(c *gin.Context) {
|
||||||
var request models.CenterRequest
|
var request models.CenterRequest
|
||||||
if err := c.ShouldBindJSON(&request); err != nil {
|
if err := c.ShouldBindJSON(&request); err != nil {
|
||||||
|
@ -220,7 +220,7 @@ func (controller *userQuizPaperController) Update(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("request", request)
|
fmt.Println("request", request)
|
||||||
userQuizPaper, err := controller.service.Find(id)
|
userQuizPaper, err := controller.service.Get(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
@ -274,7 +274,7 @@ func (controller *userQuizPaperController) Update(c *gin.Context) {
|
|||||||
// @Param id path int64 true "UserQuizPaper ID"
|
// @Param id path int64 true "UserQuizPaper ID"
|
||||||
// @Param userQuizPaperPatchBody body models.UserQuizPaperPatchRequest true "UserQuizPaper Patch Body (변경할 필드만 입력)"
|
// @Param userQuizPaperPatchBody body models.UserQuizPaperPatchRequest true "UserQuizPaper Patch Body (변경할 필드만 입력)"
|
||||||
//
|
//
|
||||||
// @Success 200 {object} models.UserQuizPaperResponse
|
// @Success 200 {object} models.UserQuizPaper
|
||||||
// @Router /userquizpaper/{id} [patch]
|
// @Router /userquizpaper/{id} [patch]
|
||||||
func (controller *userQuizPaperController) Patch(c *gin.Context) {
|
func (controller *userQuizPaperController) Patch(c *gin.Context) {
|
||||||
id, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
id, err := strconv.ParseInt(c.Param("id"), 10, 64)
|
||||||
@ -290,7 +290,7 @@ func (controller *userQuizPaperController) Patch(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("request", request)
|
fmt.Println("request", request)
|
||||||
userQuizPaper, err := controller.service.Find(id)
|
userQuizPaper, err := controller.service.Get(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
@ -318,7 +318,6 @@ func (controller *userQuizPaperController) Patch(c *gin.Context) {
|
|||||||
fmt.Println("done_at", done_at)
|
fmt.Println("done_at", done_at)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("userQuizPaper", userQuizPaper)
|
|
||||||
result, err := controller.service.Update(userQuizPaper)
|
result, err := controller.service.Update(userQuizPaper)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||||
|
@ -35,11 +35,16 @@ type UserQuizPaperResponse struct {
|
|||||||
CenterID int64 `json:"center_id" db:"center_id" example:"1000015"`
|
CenterID int64 `json:"center_id" db:"center_id" example:"1000015"`
|
||||||
QuizPaperID int64 `json:"quiz_paper_id" db:"quiz_paper_id" example:"1000001"`
|
QuizPaperID int64 `json:"quiz_paper_id" db:"quiz_paper_id" example:"1000001"`
|
||||||
UserID int64 `json:"user_id" db:"user_id" example:"1000002"`
|
UserID int64 `json:"user_id" db:"user_id" example:"1000002"`
|
||||||
|
FirstName string `json:"first_name" db:"first_name" example:"길순"`
|
||||||
|
LastName string `json:"last_name" db:"last_name" example:"홍"`
|
||||||
UserScore float32 `json:"user_score" db:"user_score" example:"5"`
|
UserScore float32 `json:"user_score" db:"user_score" example:"5"`
|
||||||
TotalScore float32 `json:"total_score" db:"total_score" example:"100"`
|
TotalScore float32 `json:"total_score" db:"total_score" example:"100"`
|
||||||
Status string `json:"status" example:"wating"`
|
Status string `json:"status" example:"wating"`
|
||||||
|
Category string `json:"category" example:"파이썬기본"`
|
||||||
|
Title string `json:"title" example:"출력 Print"`
|
||||||
StartAt *time.Time `json:"start_at"`
|
StartAt *time.Time `json:"start_at"`
|
||||||
DoneAt *time.Time `json:"done_at"`
|
DoneAt *time.Time `json:"done_at"`
|
||||||
|
CreatedAt *time.Time `json:"created_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserQuizPaperUpdateRequest struct {
|
type UserQuizPaperUpdateRequest struct {
|
||||||
@ -61,7 +66,7 @@ type UserQuizPaperPatchRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type UserQuizPaperListResponse struct {
|
type UserQuizPaperListResponse struct {
|
||||||
Data []UserQuizPaper `json:"data"`
|
Data []UserQuizPaperResponse `json:"data"`
|
||||||
Total int64 `json:"total" example:"999"`
|
Total int64 `json:"total" example:"999"`
|
||||||
Page int `json:"page" example:"1"`
|
Page int `json:"page" example:"1"`
|
||||||
TotalPage int64 `json:"totalPage" example:"99"`
|
TotalPage int64 `json:"totalPage" example:"99"`
|
||||||
|
@ -18,33 +18,49 @@ func NewUserQuizPaperRepository(db *gorm.DB) UserQuizPaperRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type UserQuizPaperRepository interface {
|
type UserQuizPaperRepository interface {
|
||||||
List(string, int, int) (*[]models.UserQuizPaper, error)
|
List(string, int, int) (*[]models.UserQuizPaperResponse, error)
|
||||||
Total(string) (int64, error)
|
Total(string) (int64, error)
|
||||||
|
|
||||||
Find(int64) (*models.UserQuizPaper, error)
|
Find(int64) (*models.UserQuizPaperResponse, error)
|
||||||
|
Get(int64) (*models.UserQuizPaper, error)
|
||||||
Create(*models.UserQuizPaper) (*models.UserQuizPaper, error)
|
Create(*models.UserQuizPaper) (*models.UserQuizPaper, error)
|
||||||
Insert([]models.UserQuizPaper) ([]models.UserQuizPaper, error)
|
Insert([]models.UserQuizPaper) ([]models.UserQuizPaper, error)
|
||||||
Update(*models.UserQuizPaper) (*models.UserQuizPaper, error)
|
Update(*models.UserQuizPaper) (*models.UserQuizPaper, error)
|
||||||
Delete(string) error
|
Delete(string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *userQuizPaperRepository) List(q string, page int, limit int) (*[]models.UserQuizPaper, error) {
|
func (r *userQuizPaperRepository) List(q string, page int, limit int) (*[]models.UserQuizPaperResponse, error) {
|
||||||
var userQuizPapers *[]models.UserQuizPaper
|
var rows *[]models.UserQuizPaperResponse
|
||||||
var err error
|
var err error
|
||||||
offset := limit * (page - 1)
|
offset := limit * (page - 1)
|
||||||
if q != "" {
|
if q != "" {
|
||||||
err = r.DB.Offset(offset).Limit(limit).Order("created_at DESC").Where("subject LIKE ? OR program LIKE ? OR name LIKE ?", "%"+q+"%", "%"+q+"%", "%"+q+"%").Find(&userQuizPapers).Error
|
err = r.DB.Offset(offset).Limit(limit).Order("UserQuizPapers.created_at DESC").
|
||||||
|
Table("UserQuizPapers").
|
||||||
|
Select("UserQuizPapers.*", "Users.first_name", "Users.last_name", "QuizPapers.title", "QuizPapers.category").
|
||||||
|
Joins("LEFT JOIN Users ON Users.id = UserQuizPapers.user_id").
|
||||||
|
Joins("LEFT JOIN QuizPapers ON QuizPapers.id = UserQuizPapers.quiz_paper_id").
|
||||||
|
Where("QuizPapers.title LIKE ? OR QuizPapers.category LIKE ? OR CONCAT(first_name, last_name) LIKE ?", "%"+q+"%", "%"+q+"%", "%"+q+"%").
|
||||||
|
Find(&rows).Error
|
||||||
} else {
|
} else {
|
||||||
err = r.DB.Offset(offset).Limit(limit).Order("created_at DESC").Find(&userQuizPapers).Error
|
err = r.DB.Offset(offset).Limit(limit).Order("UserQuizPapers.created_at DESC").
|
||||||
|
Table("UserQuizPapers").
|
||||||
|
Select("UserQuizPapers.*", "Users.first_name", "Users.last_name", "QuizPapers.title", "QuizPapers.category").
|
||||||
|
Joins("LEFT JOIN Users ON Users.id = UserQuizPapers.user_id").
|
||||||
|
Joins("LEFT JOIN QuizPapers ON QuizPapers.id = UserQuizPapers.quiz_paper_id").
|
||||||
|
Find(&rows).Error
|
||||||
}
|
}
|
||||||
return userQuizPapers, err
|
|
||||||
|
return rows, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *userQuizPaperRepository) Total(q string) (int64, error) {
|
func (r *userQuizPaperRepository) Total(q string) (int64, error) {
|
||||||
var total int64
|
var total int64
|
||||||
var err error
|
var err error
|
||||||
if q != "" {
|
if q != "" {
|
||||||
err = r.DB.Model(&models.UserQuizPaper{}).Where("subject LIKE ? OR program LIKE ? OR name LIKE ?", "%"+q+"%", "%"+q+"%", "%"+q+"%").Count(&total).Error
|
err = r.DB.Model(&models.UserQuizPaper{}).
|
||||||
|
Joins("LEFT JOIN Users ON Users.id = UserQuizPapers.user_id").
|
||||||
|
Joins("LEFT JOIN QuizPapers ON QuizPapers.id = UserQuizPapers.quiz_paper_id").
|
||||||
|
Where("QuizPapers.title LIKE ? OR QuizPapers.category LIKE ? OR CONCAT(first_name, last_name) LIKE ?", "%"+q+"%", "%"+q+"%", "%"+q+"%").Count(&total).Error
|
||||||
} else {
|
} else {
|
||||||
err = r.DB.Model(&models.UserQuizPaper{}).Count(&total).Error
|
err = r.DB.Model(&models.UserQuizPaper{}).Count(&total).Error
|
||||||
}
|
}
|
||||||
@ -52,10 +68,23 @@ func (r *userQuizPaperRepository) Total(q string) (int64, error) {
|
|||||||
return total, err
|
return total, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *userQuizPaperRepository) Find(id int64) (*models.UserQuizPaper, error) {
|
func (r *userQuizPaperRepository) Find(id int64) (*models.UserQuizPaperResponse, error) {
|
||||||
var userQuizPaper *models.UserQuizPaper
|
var row *models.UserQuizPaperResponse
|
||||||
err := r.DB.Where("id = ?", id).First(&userQuizPaper).Error
|
err := r.DB.
|
||||||
return userQuizPaper, err
|
Table("UserQuizPapers").
|
||||||
|
Select("UserQuizPapers.*", "Users.first_name", "Users.last_name", "QuizPapers.title", "QuizPapers.category").
|
||||||
|
Joins("LEFT JOIN Users ON Users.id = UserQuizPapers.user_id").
|
||||||
|
Joins("LEFT JOIN QuizPapers ON QuizPapers.id = UserQuizPapers.quiz_paper_id").
|
||||||
|
Where("UserQuizPapers.id = ?", id).First(&row).Error
|
||||||
|
return row, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *userQuizPaperRepository) Get(id int64) (*models.UserQuizPaper, error) {
|
||||||
|
var row *models.UserQuizPaper
|
||||||
|
if err := r.DB.Where("id=?", id).First(&row).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return row, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *userQuizPaperRepository) Create(userQuizPaper *models.UserQuizPaper) (*models.UserQuizPaper, error) {
|
func (r *userQuizPaperRepository) Create(userQuizPaper *models.UserQuizPaper) (*models.UserQuizPaper, error) {
|
||||||
|
@ -12,10 +12,11 @@ type userQuizPaperService struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type UserQuizPaperService interface {
|
type UserQuizPaperService interface {
|
||||||
List(string, int, int) (*[]models.UserQuizPaper, error)
|
List(string, int, int) (*[]models.UserQuizPaperResponse, error)
|
||||||
Total(string) (int64, error)
|
Total(string) (int64, error)
|
||||||
|
|
||||||
Find(int64) (*models.UserQuizPaper, error)
|
Find(int64) (*models.UserQuizPaperResponse, error)
|
||||||
|
Get(int64) (*models.UserQuizPaper, error)
|
||||||
Create(*models.UserQuizPaper) (*models.UserQuizPaper, error)
|
Create(*models.UserQuizPaper) (*models.UserQuizPaper, error)
|
||||||
Insert([]models.UserQuizPaper) ([]models.UserQuizPaper, error)
|
Insert([]models.UserQuizPaper) ([]models.UserQuizPaper, error)
|
||||||
Update(*models.UserQuizPaper) (*models.UserQuizPaper, error)
|
Update(*models.UserQuizPaper) (*models.UserQuizPaper, error)
|
||||||
@ -29,7 +30,7 @@ func NewUserQuizPaperService(repository repositories.UserQuizPaperRepository) Us
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *userQuizPaperService) List(q string, page int, limit int) (*[]models.UserQuizPaper, error) {
|
func (s *userQuizPaperService) List(q string, page int, limit int) (*[]models.UserQuizPaperResponse, error) {
|
||||||
return s.repository.List(q, page, limit)
|
return s.repository.List(q, page, limit)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,10 +38,14 @@ func (s *userQuizPaperService) Total(q string) (int64, error) {
|
|||||||
return s.repository.Total(q)
|
return s.repository.Total(q)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *userQuizPaperService) Find(id int64) (*models.UserQuizPaper, error) {
|
func (s *userQuizPaperService) Find(id int64) (*models.UserQuizPaperResponse, error) {
|
||||||
return s.repository.Find(id)
|
return s.repository.Find(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *userQuizPaperService) Get(id int64) (*models.UserQuizPaper, error) {
|
||||||
|
return s.repository.Get(id)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *userQuizPaperService) Create(userQuizPaper *models.UserQuizPaper) (*models.UserQuizPaper, error) {
|
func (s *userQuizPaperService) Create(userQuizPaper *models.UserQuizPaper) (*models.UserQuizPaper, error) {
|
||||||
result, err := s.repository.Create(userQuizPaper)
|
result, err := s.repository.Create(userQuizPaper)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user