-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix some UI and project things * API search * search working
- Loading branch information
1 parent
b75891f
commit 5ba50c3
Showing
13 changed files
with
222 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' | ||
import Illustration from 'App/Models/Illustration' | ||
import Place from 'App/Models/Place' | ||
import Tag from 'App/Models/Tag' | ||
import { _ } from 'lodash' | ||
|
||
export default class SearchesController { | ||
|
||
public async search({ auth, request, response }: HttpContextContract) { | ||
|
||
const { search } = request.all() | ||
|
||
if (!search) { | ||
return response.noContent() | ||
} | ||
|
||
const illustrations = await Illustration.query() | ||
.where('title', search) | ||
.orWhere('content', 'LIKE', `%${search}%`) | ||
.orWhere('author', 'LIKE', `%${search}%`) | ||
.andWhere('user_id', `${auth.user?.id}`) | ||
const tagSanitizedSearch = _.startCase(search).replace(/ /g, '-') | ||
const tags = await Tag.query().where('name',tagSanitizedSearch).andWhere('user_id', `${auth.user?.id}`) | ||
const places = await Place.query().preload('illustration').where('place',search).andWhere('user_id', `${auth.user?.id}`) | ||
|
||
// console.log({ message: 'success',user_id: `${auth.user?.id}`, searchString: search, data: { illustrations, places, tags } }) | ||
|
||
return response.send({ message: 'success', searchString: search, data: { illustrations, places, tags } }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { test } from '@japa/runner' | ||
import IllustrationFactory from 'Database/factories/IllustrationFactory' | ||
import PlaceFactory from 'Database/factories/PlaceFactory' | ||
import UserFactory from 'Database/factories/UserFactory' | ||
import TagFactory from 'Database/factories/TagFactory' | ||
import Database from '@ioc:Adonis/Lucid/Database' | ||
let goodUser | ||
|
||
test.group('Search', (group) => { | ||
// Write your test here | ||
group.each.setup(async () => { | ||
await Database.beginGlobalTransaction() | ||
return () => Database.rollbackGlobalTransaction() | ||
}) | ||
group.setup(async () => { | ||
goodUser = await UserFactory.merge({password: 'oasssadfasdf'}).create() | ||
const illustration = await IllustrationFactory.merge({ title: 'Search Test', user_id: goodUser.id }).create() | ||
const place = await PlaceFactory.merge({ illustration_id: illustration.id, place: 'Search Place', user_id: goodUser.id }).create() | ||
const tag = await TagFactory.merge({ name: 'Search Tag', user_id: goodUser.id }).create() | ||
|
||
// console.log(illustration.toJSON(),place.toJSON(),tag.toJSON()) | ||
}) | ||
|
||
group.teardown(async () => { | ||
await goodUser.delete() | ||
}) | ||
|
||
test('Can search for all', async ({ client }) => { | ||
const loggedInUser = await client.post('/login').json({ email: goodUser.email, password: 'oasssadfasdf' }) | ||
const response = await client.post(`/search`).json({ search: 'Search' }).bearerToken(loggedInUser.body().token) | ||
// console.log(response.body()) | ||
response.assertStatus(200) | ||
response.assertBodyContains({message: "success"}) | ||
response.assertBodyContains({ searchString: "Search" }) | ||
// not working :( | ||
// response.assertBodyContains({ data: { illustrations: [{title: 'Search Test',}] } }) | ||
// response.assertBodyContains({ data: { tags: [{name: 'Search Tag',}] } }) | ||
// response.assertBodyContains({ data: { places: [{place: 'Search Place',}] } }) | ||
}) | ||
|
||
test('No seach string', async ({ client }) => { | ||
const loggedInUser = await client.post('/login').json({ email: goodUser.email, password: 'oasssadfasdf' }) | ||
|
||
const response = await client.post(`/search`).json({}).bearerToken(loggedInUser.body().token) | ||
response.assertStatus(204) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export type placeType = { | ||
place: string, | ||
location: string, | ||
used: Date, | ||
illustration_id: number | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters