added method for create integration
This commit is contained in:
parent
7ff7b315b6
commit
3622e5fbce
@ -2,6 +2,8 @@ module controllers
|
|||||||
|
|
||||||
import repository
|
import repository
|
||||||
import veb
|
import veb
|
||||||
|
import models
|
||||||
|
import json
|
||||||
|
|
||||||
pub struct IntegrationControllers {
|
pub struct IntegrationControllers {
|
||||||
pub mut:
|
pub mut:
|
||||||
@ -18,8 +20,22 @@ fn (mut c IntegrationControllers) get(mut ctx veb.Context,quizID i64) veb.Result
|
|||||||
|
|
||||||
@['/:quizID'; post]
|
@['/:quizID'; post]
|
||||||
fn (mut c IntegrationControllers) create(mut ctx veb.Context,quizID int) veb.Result {
|
fn (mut c IntegrationControllers) create(mut ctx veb.Context,quizID int) veb.Result {
|
||||||
println(quizID)
|
mut integration := json.decode(models.TelegramIntegration,ctx.req.data)or {
|
||||||
return ctx.text('create')
|
return ctx.request_error('Failed parse request body: $err')
|
||||||
|
}
|
||||||
|
integration.quiz_id = quizID
|
||||||
|
|
||||||
|
if integration.account_id == "" || integration.bot_name == "" || integration.bot_token == ""{
|
||||||
|
return ctx.request_error('Missing required fields')
|
||||||
|
}
|
||||||
|
|
||||||
|
id := c.repo.create_integration(integration) or {
|
||||||
|
return ctx.server_error('Failed create integration: $err')
|
||||||
|
}
|
||||||
|
|
||||||
|
integration.id = id
|
||||||
|
|
||||||
|
return ctx.json(integration)
|
||||||
}
|
}
|
||||||
|
|
||||||
@['/:quizID'; patch]
|
@['/:quizID'; patch]
|
||||||
|
@ -86,6 +86,11 @@ pub fn (mut r Repo) get_integration_by_id(id i64) !models.TelegramIntegration {
|
|||||||
} or {
|
} or {
|
||||||
return error('Integration not found')
|
return error('Integration not found')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if integration.len == 0 {
|
||||||
|
return error('Integration not found')
|
||||||
|
}
|
||||||
|
|
||||||
return integration[0]
|
return integration[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user