mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-21 07:21:35 +01:00
Working on new version of website
Signed-off-by: Arthur DANJOU <arthurdanjou@outlook.fr>
This commit is contained in:
63
app/Controllers/Http/AnnouncesController.ts
Normal file
63
app/Controllers/Http/AnnouncesController.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||
import Announce from "App/Models/Announce";
|
||||
import AnnounceStoreValidator from "App/Validators/announce/AnnounceStoreValidator";
|
||||
import AnnounceUpdateValidator from "App/Validators/announce/AnnounceUpdateValidator";
|
||||
import getTranslation from "App/Tasks/getTranslation";
|
||||
import File from "App/Models/File";
|
||||
|
||||
export default class AnnouncesController {
|
||||
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
const announce = await Announce.query().orderBy('created_at', 'desc').first()
|
||||
return response.status(200).send({
|
||||
announce: announce
|
||||
})
|
||||
}
|
||||
|
||||
public async store ({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(AnnounceStoreValidator)
|
||||
const announce = new Announce()
|
||||
|
||||
const translation = await getTranslation(data.code)
|
||||
await announce.related('message').associate(translation)
|
||||
|
||||
const cover = await File.findBy('label', data.cover)
|
||||
if (cover) await announce.related('cover').save(cover)
|
||||
|
||||
return response.status(200).send({
|
||||
announce: announce.save()
|
||||
})
|
||||
}
|
||||
|
||||
public async show ({ params, response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
user: await Announce.findOrFail(params.id)
|
||||
})
|
||||
}
|
||||
|
||||
public async update({ request, params, response }: HttpContextContract) {
|
||||
const data = await request.validate(AnnounceUpdateValidator)
|
||||
const announce = await Announce.findOrFail(params.id)
|
||||
|
||||
if (data.code) {
|
||||
const translation = await getTranslation(data.code)
|
||||
await announce.related('message').associate(translation)
|
||||
}
|
||||
|
||||
const cover = await File.findBy('label', data.cover)
|
||||
if (cover) await announce.related('cover').save(cover)
|
||||
|
||||
return response.status(200).send({
|
||||
announce
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy ({ response, params }: HttpContextContract) {
|
||||
const announce = await Announce.findOrFail(params.id)
|
||||
await announce.delete()
|
||||
return response.status(200).send({
|
||||
message: 'Announce successfully deleted!'
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,13 +4,13 @@ import File from "App/Models/File";
|
||||
|
||||
export default class FileController {
|
||||
|
||||
public async index({response}: HttpContextContract) {
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
files: File.query()
|
||||
})
|
||||
}
|
||||
|
||||
public async store({request, response}: HttpContextContract) {
|
||||
public async store ({ request, response }: HttpContextContract) {
|
||||
const file = await request.file('file', {
|
||||
extnames: ['jpg', 'png', 'jpeg']
|
||||
})
|
||||
@@ -35,7 +35,7 @@ export default class FileController {
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy({params, response}: HttpContextContract) {
|
||||
public async destroy ({ params, response }: HttpContextContract) {
|
||||
const file = await File.findOrFail(params.id)
|
||||
await file.delete()
|
||||
return response.status(200).send({
|
||||
|
||||
@@ -1,18 +1,34 @@
|
||||
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||
import FormValidator from "App/Validators/FormValidator";
|
||||
import FormStoreValidator from "App/Validators/form/FormStoreValidator";
|
||||
import Form from "App/Models/Form";
|
||||
import FormConfirmation from "App/Mailers/FormConfirmation";
|
||||
|
||||
export default class FormsController {
|
||||
|
||||
public async send({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(FormValidator)
|
||||
await Form.create(data)
|
||||
|
||||
await new FormConfirmation(data.name, data.email).preview()
|
||||
//todo send confirmation email + email to me
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
message: 'Form successfully received !'
|
||||
forms: Form.query().orderBy('created_at', 'asc')
|
||||
})
|
||||
}
|
||||
|
||||
public async store ({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(FormStoreValidator)
|
||||
//todo send confirmation email + email to me with FormConfirmation
|
||||
return response.status(200).send({
|
||||
form: await Form.create(data)
|
||||
})
|
||||
}
|
||||
|
||||
public async show ({ params, response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
form: await Form.findOrFail(params.id)
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy ({ response, params }: HttpContextContract) {
|
||||
const form = await Form.findOrFail(params.id)
|
||||
await form.delete()
|
||||
return response.status(200).send({
|
||||
message: 'Form successfully deleted!'
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import User from "App/Models/User";
|
||||
|
||||
export default class GuestBookController {
|
||||
|
||||
public async index ({response}: HttpContextContract) {
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
const guestbook_messages = await GuestbookMessage
|
||||
.query()
|
||||
.preload('user')
|
||||
@@ -15,7 +15,7 @@ export default class GuestBookController {
|
||||
})
|
||||
}
|
||||
|
||||
public async store ({request, response}: HttpContextContract) {
|
||||
public async store ({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(GuestValidator)
|
||||
let user = await User.findBy('email', data.email)
|
||||
if (!user) {
|
||||
@@ -34,7 +34,21 @@ export default class GuestBookController {
|
||||
})
|
||||
}
|
||||
|
||||
public async get ({params, response}: HttpContextContract) {
|
||||
public async show ({ params, response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
guestbook_message: await GuestbookMessage.findOrFail(params.id)
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy ({ params, response }: HttpContextContract) {
|
||||
const guestbook_message = await GuestbookMessage.findOrFail(params.id)
|
||||
await guestbook_message.delete()
|
||||
return response.status(200).send({
|
||||
message: 'GuestBookMessage successfully deleted!'
|
||||
})
|
||||
}
|
||||
|
||||
public async exists ({ params, response }: HttpContextContract) {
|
||||
const email = await params.email
|
||||
const guestbook_message = await GuestbookMessage.findBy('email', email)
|
||||
return response.status(200).send({
|
||||
|
||||
@@ -4,7 +4,7 @@ import LocationValidator from "App/Validators/location/LocationValidator";
|
||||
|
||||
export default class LocationsController {
|
||||
|
||||
public async get ({ response }: HttpContextContract) {
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
const location = await Location.query().orderBy('since', 'desc').first()
|
||||
if (location) {
|
||||
return response.status(200).send({
|
||||
@@ -23,9 +23,9 @@ export default class LocationsController {
|
||||
|
||||
public async store ({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(LocationValidator)
|
||||
await Location.create(data)
|
||||
const location = await Location.create(data)
|
||||
return response.status(200).send({
|
||||
message: 'Location successfully added !'
|
||||
location
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||
|
||||
export default class PostsController {
|
||||
|
||||
public async getLikes({params, response}: HttpContextContract) {
|
||||
public async getLikes ({ params, response }: HttpContextContract) {
|
||||
let post = await Post.findBy('slug', params.slug)
|
||||
|
||||
if (!post) {
|
||||
@@ -18,7 +18,7 @@ export default class PostsController {
|
||||
})
|
||||
}
|
||||
|
||||
public async like ({params, response}: HttpContextContract) {
|
||||
public async like ({ params, response }: HttpContextContract) {
|
||||
let post = await Post.findBy('slug', params.slug)
|
||||
|
||||
if (!post) {
|
||||
@@ -38,7 +38,7 @@ export default class PostsController {
|
||||
})
|
||||
}
|
||||
|
||||
public async unlike ({params, response}: HttpContextContract) {
|
||||
public async unlike ({ params, response }: HttpContextContract) {
|
||||
let post = await Post.findByOrFail('slug', params.slug)
|
||||
|
||||
const getLikes = post.likes - 1
|
||||
|
||||
@@ -48,7 +48,7 @@ export default class ProfileController {
|
||||
}
|
||||
|
||||
//todo get discord Activity
|
||||
public async discord({response}: HttpContextContract) {
|
||||
public async discord ({ response }: HttpContextContract) {
|
||||
const activity = await getDiscordActivity()
|
||||
return response.status(200).send({
|
||||
status: activity
|
||||
|
||||
23
app/Controllers/Http/ProfilesController.ts
Normal file
23
app/Controllers/Http/ProfilesController.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||
import Profile from "App/Models/Profile";
|
||||
import ProfileUpdateValidator from "App/Validators/profile/ProfileUpdateValidator";
|
||||
|
||||
export default class ProfilesController {
|
||||
|
||||
public async index ( { response }: HttpContextContract ) {
|
||||
return response.status(200).send({
|
||||
profile: await Profile.first()
|
||||
})
|
||||
}
|
||||
|
||||
public async update ( { response, request }: HttpContextContract ) {
|
||||
const profile = await Profile.firstOrFail()
|
||||
const data = await request.validate(ProfileUpdateValidator)
|
||||
await profile.merge(data).save()
|
||||
|
||||
return response.status(200).send({
|
||||
profile
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +1,55 @@
|
||||
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||
import Project from "App/Models/Project";
|
||||
import ProjectValidator from "App/Validators/project/ProjectValidator";
|
||||
import ProjectStoreValidator from "App/Validators/project/ProjectStoreValidator";
|
||||
import ProjectUpdateValidator from "App/Validators/project/ProjectUpdateValidator";
|
||||
import File from "App/Models/File";
|
||||
|
||||
export default class ProjectsController {
|
||||
|
||||
public async get ({ response }: HttpContextContract) {
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
projects: await Project.query().orderBy('id', 'asc')
|
||||
projects: await Project.query()
|
||||
.orderBy('id', 'asc')
|
||||
.preload('cover')
|
||||
})
|
||||
}
|
||||
|
||||
public async store ({ request, response}: HttpContextContract) {
|
||||
const data = await request.validate(ProjectValidator)
|
||||
await Project.create(data)
|
||||
public async store ({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(ProjectStoreValidator)
|
||||
const project = await Project.create(data)
|
||||
const cover = await File.findByOrFail('label', data.cover)
|
||||
|
||||
await project.related('cover').save(cover)
|
||||
return response.status(200).send({
|
||||
message: 'Project successfully created'
|
||||
project
|
||||
})
|
||||
}
|
||||
|
||||
public async show ({ params, response }: HttpContextContract) {
|
||||
const project = await Project.findOrFail(params.id)
|
||||
await project.load('cover')
|
||||
return response.status(200).send({
|
||||
project
|
||||
})
|
||||
}
|
||||
|
||||
public async update ({ request, params, response }: HttpContextContract) {
|
||||
const project = await Project.findOrFail(params.id)
|
||||
const data = await request.validate(ProjectUpdateValidator)
|
||||
const cover = await File.findBy('label', data.cover)
|
||||
|
||||
await project.merge(data).save()
|
||||
if (cover) await project.related('cover').save(cover)
|
||||
return response.status(200).send({
|
||||
project
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy ({ response, params }: HttpContextContract) {
|
||||
const project = await Project.findOrFail(params.id)
|
||||
await project.delete()
|
||||
return response.status(200).send({
|
||||
message: 'Project successfully deleted!'
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||
import Redis from "@ioc:Adonis/Addons/Redis";
|
||||
import {UpdateGitHubReadme} from "App/Tasks/UpdateGithubReadme";
|
||||
|
||||
export default class StatesController {
|
||||
|
||||
public async get({response}: HttpContextContract) {
|
||||
|
||||
return response.status(200).send({
|
||||
states: {
|
||||
"is_sleeping": this.getStatus(await Redis.get(`states:is_sleeping`)),
|
||||
"is_developing": this.getStatus(await Redis.get(`states:is_developing`)),
|
||||
"is_learning": this.getStatus(await Redis.get(`states:is_learning`)),
|
||||
"is_listening_music": this.getStatus(await Redis.get(`states:is_listening_music`)),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
public async set({request, response, params}: HttpContextContract) {
|
||||
const state = params.state
|
||||
const value = await request.input('value')
|
||||
|
||||
if (state && value) {
|
||||
await Redis.set(`states:${state}`, value)
|
||||
|
||||
if (value === 'true') {
|
||||
switch (state) {
|
||||
case 'learning':
|
||||
await Redis.set(`states:developing`, 'false')
|
||||
await Redis.set(`states:sleeping`, 'false')
|
||||
break
|
||||
case 'developing':
|
||||
await Redis.set(`states:learning`, 'false')
|
||||
await Redis.set(`states:sleeping`, 'false')
|
||||
break
|
||||
case 'listening':
|
||||
await Redis.set(`states:sleeping`, 'false')
|
||||
break
|
||||
case 'sleeping':
|
||||
await Redis.set(`states:developing`, 'false')
|
||||
await Redis.set(`states:listening`, 'false')
|
||||
await Redis.set(`states:learning`, 'false')
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
await UpdateGitHubReadme()
|
||||
return response.status(200).send({
|
||||
message: 'State successfully updated!'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
public getStatus(state: string | null): string {
|
||||
if (state === null) return "No"
|
||||
return state === 'true' ? "Yes" : "No"
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +1,30 @@
|
||||
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||
import Subscriber from "App/Models/Subscriber";
|
||||
import SubscriberValidator from "App/Validators/subscriber/SubscriberValidator";
|
||||
import SubscriberStoreValidator from "App/Validators/subscriber/SubscriberStoreValidator";
|
||||
|
||||
export default class SubscribersController {
|
||||
|
||||
public async get ({ response }: HttpContextContract) {
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
const subscribers = await Subscriber.query()
|
||||
return response.status(200).send({
|
||||
count: subscribers.length
|
||||
count: subscribers.length,
|
||||
subscribers: subscribers
|
||||
})
|
||||
}
|
||||
|
||||
public async store({request, response}: HttpContextContract) {
|
||||
const data = await request.validate(SubscriberValidator)
|
||||
const email = await Subscriber.findBy('email', data.email)
|
||||
if (email) {
|
||||
return response.status(201).send({
|
||||
message: 'Subscriber already exists'
|
||||
})
|
||||
}
|
||||
await Subscriber.create(data)
|
||||
public async store ({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(SubscriberStoreValidator)
|
||||
return response.status(200).send({
|
||||
message: 'Subscriber successfully registered!'
|
||||
subscriber: await Subscriber.create(data)
|
||||
})
|
||||
}
|
||||
|
||||
public async delete({request, response}: HttpContextContract) {
|
||||
const data = await request.validate(SubscriberValidator)
|
||||
const subscriber = await Subscriber.findBy('email', data.email)
|
||||
if (subscriber) {
|
||||
await subscriber.delete()
|
||||
return response.status(200).send({
|
||||
message: 'Subscriber successfully deleted!'
|
||||
})
|
||||
}
|
||||
public async destroy ({ params, response }: HttpContextContract) {
|
||||
const subscriber = await Subscriber.findOrFail(params.id)
|
||||
await subscriber.delete()
|
||||
return response.status(200).send({
|
||||
message: 'Subscriber successfully deleted!'
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
45
app/Controllers/Http/TranslationsController.ts
Normal file
45
app/Controllers/Http/TranslationsController.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||
import Translation from "App/Models/Translation";
|
||||
import TranslationStoreValidator from "App/Validators/translation/TranslationStoreValidator";
|
||||
import TranslationUpdateValidator from "App/Validators/translation/TranslationUpdateValidator";
|
||||
|
||||
export default class TranslationsController {
|
||||
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
translations: Translation.query()
|
||||
})
|
||||
}
|
||||
|
||||
public async store ({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(TranslationStoreValidator)
|
||||
return response.status(200).send({
|
||||
translation: await Translation.create(data)
|
||||
})
|
||||
}
|
||||
|
||||
public async show ({ params, response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
translation: await Translation.findOrFail(params.id)
|
||||
})
|
||||
}
|
||||
|
||||
public async update ({ request, params, response }: HttpContextContract) {
|
||||
const translation = await Translation.findOrFail(params.id)
|
||||
const data = await request.validate(TranslationUpdateValidator)
|
||||
await translation.merge(data).save()
|
||||
|
||||
return response.status(200).send({
|
||||
translation
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy ({ response, params }: HttpContextContract) {
|
||||
const translation = await Translation.findOrFail(params.id)
|
||||
await translation.delete()
|
||||
return response.status(200).send({
|
||||
message: 'Translation successfully deleted!'
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,40 +1,40 @@
|
||||
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||
import User from "App/Models/User";
|
||||
import UserStoreValidator from "App/Validators/users/UserStoreValidator";
|
||||
import UserUpdateValidator from "App/Validators/users/UserUpdateValidator";
|
||||
import UserStoreValidator from "App/Validators/user/UserStoreValidator";
|
||||
import UserUpdateValidator from "App/Validators/user/UserUpdateValidator";
|
||||
|
||||
export default class UsersController {
|
||||
|
||||
public async index({response}: HttpContextContract) {
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
users: User.query()
|
||||
})
|
||||
}
|
||||
|
||||
public async store({request, response}: HttpContextContract) {
|
||||
public async store ({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(UserStoreValidator)
|
||||
return response.status(200).send({
|
||||
user: await User.create(data)
|
||||
})
|
||||
}
|
||||
|
||||
public async show({params, response}: HttpContextContract) {
|
||||
public async show ({ params, response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
user: await User.findOrFail(params.id)
|
||||
})
|
||||
}
|
||||
|
||||
public async update({request, params, response}: HttpContextContract) {
|
||||
public async update ({ request, params, response }: HttpContextContract) {
|
||||
const user = await User.findOrFail(params.id)
|
||||
const data = await request.validate(UserUpdateValidator)
|
||||
await user.merge(data).save()
|
||||
|
||||
return response.status(200).send({
|
||||
message: 'User successfully updated!'
|
||||
user
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy({ response, params, auth }: HttpContextContract) {
|
||||
public async destroy ({ response, params, auth }: HttpContextContract) {
|
||||
const user = await User.findOrFail(params.id)
|
||||
const admin = await User.findBy('email', 'arthurdanjou@outlook.fr')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user