Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create adapter for new api #15

Merged
merged 36 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a8e97dd
add books cards
vbuglov Mar 2, 2024
2096720
feat(user books page): create books list
vbuglov Mar 3, 2024
f8ac250
feat(gitignore): vscode
vbuglov Mar 3, 2024
94fe819
feat(prehook):
vbuglov Mar 3, 2024
fe89b14
feat(prehook):
vbuglov Mar 3, 2024
b1b4310
feat(lint):
vbuglov Mar 3, 2024
b9582d6
feat(fix(lint): update camelCaseComponents):
vbuglov Mar 3, 2024
f1258d8
feat(feat(test&refactor): App.vue && SideMenu):
vbuglov Mar 3, 2024
7135aad
feat(feat(test&refactor): App.vue && SideMenu):
vbuglov Mar 3, 2024
35dfa8d
feat(feat(side menu): create menu books list):
vbuglov Mar 3, 2024
84298bb
feat(feat(vue.yml): lint&test only books-ui/):
vbuglov Mar 4, 2024
c512baa
feat(feat(vue.yml): lint&test only books-ui/
vbuglov Mar 4, 2024
6dd3d14
feat(feat(vue.yml): lint&test only books-ui/
vbuglov Mar 4, 2024
0470391
feat(feat(vue.yml): lint&test only books-ui/
vbuglov Mar 4, 2024
621d50a
feat(feat(vue.yml): lint&test only books-ui/
vbuglov Mar 4, 2024
022652f
feat(feat(vue.yml): lint&test only books-ui/
vbuglov Mar 4, 2024
0a3836e
feat(feat(vue.yml): lint&test only books-ui/
vbuglov Mar 4, 2024
4de3f1c
feat(feat(vue.yml): lint&test only books-ui/
vbuglov Mar 4, 2024
e9ed5b5
feat(feat(vue.yml): lint&test only books-ui/
vbuglov Mar 4, 2024
5a00223
feat(feat(vue.yml): lint&test only books-ui/
vbuglov Mar 4, 2024
7f0425b
feat(feat(vue.yml): lint&test only books-ui/
vbuglov Mar 4, 2024
b8c0a82
feat(feat vue.yml): this push without vue test&lint
vbuglov Mar 4, 2024
58d910e
feat(feat vue.yml): this push without vue test&lint, yeee
vbuglov Mar 4, 2024
b3e23dc
feat(feat vue.yml): this push with vue test&lint, yeee
vbuglov Mar 4, 2024
094ce9d
feat(feat vue.yml): this push with vue test&lint, yeee
vbuglov Mar 4, 2024
bea7d6c
feat(feat vue.yml): this push without vue test&lint
vbuglov Mar 4, 2024
fb6bc99
feat(feat vue.yml): this push with vue test&lint, 000
vbuglov Mar 4, 2024
54e562e
feat(test|lint vue.yml): remove test file
vbuglov Mar 4, 2024
c391135
Merge remote-tracking branch 'origin/main' into books-ui
vbuglov Mar 5, 2024
4c1a0b0
feat(feat(core): create services && adapter + tests):
vbuglov Mar 6, 2024
12719ee
feat(feat(core): create services && adapter + tests):
vbuglov Mar 6, 2024
81d76ee
feat(feat(tests): adapter tests):
vbuglov Mar 7, 2024
97daead
feat(upd):
vbuglov Mar 7, 2024
d25bde8
feat(fix(core): service tests):
vbuglov Mar 7, 2024
519abe1
feat(feat(core): chage books adatapter && add create book button):
vbuglov Mar 8, 2024
b8d3db9
feat(feat(core): chage books adatapter && add create book button):
vbuglov Mar 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/vue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ name: vue

on:
push:
paths:
- books-ui/**
branches:
- main
- books-ui
pull_request:
paths:
- books-ui/**
branches:
- main
- books-ui
Expand Down
3 changes: 0 additions & 3 deletions books-ui/.vscode/extensions.json

This file was deleted.

38 changes: 33 additions & 5 deletions books-ui/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
HOOK_NAME=pre-push
HOOK_PATH=../.git/hooks/$(HOOK_NAME)

restart:
docker build -t proxy-ui-vue .
docker run -d --name proxy-ui-vue --rm -p 5000:80 proxy-ui-vue
Expand All @@ -13,9 +16,34 @@ rmrestart:
docker stop proxy-ui-vue
docker run -d --name proxy-ui-vue --rm -p 5000:80 proxy-ui-vue

// feat():
// git add . && git commit -m "feat(): " && git push

prehook:
@echo "Setting up pre-push hook..."
@rm -f $(HOOK_PATH)
@echo '#!/bin/sh' >> $(HOOK_PATH)
@echo 'echo "Running lint for books-ui"' >> $(HOOK_PATH)
@echo 'cd ./books-ui' >> $(HOOK_PATH)
@echo 'yarn lint' >> $(HOOK_PATH)
@echo 'if [ $$? -ne 0 ]; then' >> $(HOOK_PATH)
@echo ' echo "Tests failed, push aborted."' >> $(HOOK_PATH)
@echo ' exit 1' >> $(HOOK_PATH)
@echo 'fi' >> $(HOOK_PATH)
@echo 'echo "Running tests for proxy-ui"' >> $(HOOK_PATH)
@echo 'yarn test_ones' >> $(HOOK_PATH)
@echo 'if [ $$? -ne 0 ]; then' >> $(HOOK_PATH)
@echo ' echo "Tests failed, push aborted."' >> $(HOOK_PATH)
@echo ' exit 1' >> $(HOOK_PATH)
@echo 'fi' >> $(HOOK_PATH)
@echo 'exit 0' >> $(HOOK_PATH)
@chmod +x $(HOOK_PATH)
@echo "Pre-push hook set successfully."



push:
git add .
git commit -m "${commit}"
git push
ifeq ($(commit),)
$(error mn is not set)
endif
make prehook
git add . && git commit -m "feat($(commit)):" && git push

1 change: 1 addition & 0 deletions books-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"axios": "^1.6.7",
"flowbite": "^2.3.0",
"flowbite-vue": "^0.1.2",
"moment": "^2.30.1",
"postcss-import": "^16.0.1",
"ramda": "^0.29.1",
"socket.io-client": "^4.7.4",
Expand Down
7 changes: 7 additions & 0 deletions books-ui/public/icons/logo2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 12 additions & 7 deletions books-ui/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<script>
import Head from '@frames/Head.vue';
import SideMenu from '@frames/SideMenu/SideMenu.vue';
import {mapActions} from "vuex";
import {mapGetters} from "vuex";
import AdapterOfBooks from "@adapters/AdapterOfBooks.js";
import ServiceOfBooks from "@services/ServiceOfBooks.js";


export default {
Expand All @@ -14,21 +16,24 @@ export default {
return {}
},
computed: {
...mapGetters('books', ['userBooks']),
pageName() {
if (!this.$route) return "pending"
return this.$route.name
}
},
mounted() {
this.initScreenSizeRecalc()
mounted() {
const url = import.meta.env.VITE_API_ADDR
const adapterOfBooks = new AdapterOfBooks(url)
const store = this.$store

const serviceOfBooks = new ServiceOfBooks(adapterOfBooks, store)
serviceOfBooks.fetchUserBooks()

},
methods: {
...mapActions('layout', ['initScreenSizeRecalc'])
}
}
</script>


<template>
<div
v-if="pageName && pageName !== 'auth'"
Expand Down
146 changes: 146 additions & 0 deletions books-ui/src/adapters/AdapterOfBooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import {get, post, put, remove} from '@helpers/apiHelpers.js'
import {convertList, convertObject} from '@helpers/adapter/adapter.js'
import {reverseObject} from '@helpers/objectUtils'
import {path} from 'ramda'

const adapterConfig = {
"id": "id",
"created_at": "createdAt",
"updated_at": "updatedAt",
"deleted_at": "deletedAt",
"owner": "owner",
"title": "title",
"author": "author",
"description": "description",
"is_public": "isPublic",
"publication": "publication",
"image_link": "imageLink",
"map_link": "mapLink",
"map_params_id": "mapParamsId",
"variables": "variables"
}


/**
* @deftypes Book
* @property {String} title "Тестовая книга",
* @property {String} author "Васильев А.В.",
* @property {String} owner "e75aae0d-c1eb-4199-a1d8-2177f57d6a1e",
* @property {String} description "test description",
* @property {Boolean} is_public false,
* @property {Any} publication null
*
*/

/**
* BooksApi class
*
* @class
*/

class AdapterOfBooks {

/**
* @constructor
* @param {Object | undefined } adapterFromApiConfig - конфигурация адаптера для преобразования объектов из API
* @param {Object | undefined | any} params - параметры
* @param {Object} params.adapterToApiConfig - конфигурация адаптера для преобразования объектов в API, по дефолту преобразование происходит в обратном порядке из adapterFromApiConfig
*/
constructor(url) {
this.adapterFromApiConfig = adapterConfig
this.adapterToApiConfig = reverseObject(this.adapterFromApiConfig)
this.url = url
}

/**
*
* @returns {Promise<Object[]>}
*/
async getBooks() {
let {books} = await get(`${this.url}/books`)
books = convertList(books, {config: this.adapterFromApiConfig})
return books
}

/**
*
* @param {Object} book
* @returns {Promise<*|void|Object>}
*/
async updateBook(book) {
const bookToApi = convertObject(book, {config: this.adapterToApiConfig})
const bookFromApi = await put(`${this.url}/books/${book.id}`, {
book: bookToApi
})

const updatedBook = convertObject(bookFromApi.book, {config: this.adapterFromApiConfig})
return updatedBook
}

/**
*
* @param {Object} book
* @returns {Promise<*|void|Object>}
*/
async createBook(book) {
const bookToApi = convertObject(book, {config: this.adapterToApiConfig})
let bookFromApi = await post(`${this.url}/books`, {
book: bookToApi
})
bookFromApi = convertObject(bookFromApi.book, {config: this.adapterFromApiConfig})
return bookFromApi
}


/**
*
* @param {Number} id
* @returns {Promise<Object>}
*/
async getBookById(id) {
const {book} = await get(`${this.url}/books/${id}`)
return convertObject(book, {config: this.adapterFromApiConfig})
}

/**
*
* @param {Number} id
* @returns {Promise<Object>}
*/
async deleteBookById(id) {
const {book} = await remove(`${this.url}/books/${id}`)
const updatedBook = convertObject(book, {config: this.adapterFromApiConfig})
return updatedBook
}

/**
* @param {Function} logFunction
* @returns {Promise<null>}
*/
async integrationTests(logFunction) {
logFunction("Список книг")
const books = await this.getBooks()
logFunction(books)
logFunction("Создание книги")
const newBook = await this.createBook({
"title": "Тестовая книга",
"author": "Васильев А.В.",
"owner": "e75aae0d-c1eb-4199-a1d8-2177f57d6a1e",
"description": "test description",
"is_public": false,
"publication": null
})
logFunction(newBook)
logFunction("Получение книги по id(Созданной)")
const bookById = await this.getBookById(newBook.id)
logFunction(bookById)
logFunction("Обновление книги")
const updatedBook = await this.updateBook({...bookById, title: "Обновленная книга"})
logFunction(updatedBook)
logFunction("Удаление книги")
const deletedBook = await this.deleteBookById(bookById.id)
logFunction(deletedBook)
}
}

export default AdapterOfBooks
28 changes: 28 additions & 0 deletions books-ui/src/components/1_atoms/BackgroundImage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<script>
export default {
name: 'BackgroundImage',
props: {
imageLink: {
type: String,
required: true
},
alt: {
type: String,
required: true
}
},
}

</script>

<template>
<div class="absolute inset-0 overflow-hidden transition-all">
<figure class="h-full w-full overflow-hidden">
<img
class="object-cover w-full h-full"
:src="imageLink"
:alt="alt"
>
</figure>
</div>
</template>
17 changes: 17 additions & 0 deletions books-ui/src/components/2_molecules/VCardsContainer.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script>
export default {
name: 'VCardsContainer',
components: {},
data() {},
computed: {},
mounted() {},
methods: {}
}

</script>

<template>
<div class="">
template
</div>
</template>
25 changes: 25 additions & 0 deletions books-ui/src/components/3_organisms/BookEditor/BookEditor.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<script>
import BookEditorHeader from "@organisms/BookEditor/BookEditorHeader.vue";
import BookEditorChaptersMenu from "@organisms/BookEditor/BookEditorChaptersMenu.vue";
import BookEditorBody from "@organisms/BookEditor/BookEditorBody.vue";

export default {
name: 'BookEditor',
components: {BookEditorHeader, BookEditorChaptersMenu, BookEditorBody},
data() {},
computed: {},
mounted() {},
methods: {}
}

</script>

<template>
<div class="w-full h-full">
<BookEditorHeader />
<div>
<BookEditorChaptersMenu />
<BookEditorBody />
</div>
</div>
</template>
17 changes: 17 additions & 0 deletions books-ui/src/components/3_organisms/BookEditor/BookEditorBody.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script>
export default {
name: 'BookEditorBody',
components: {},
data() {},
computed: {},
mounted() {},
methods: {}
}

</script>

<template>
<div class="">
template
</div>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script>
export default {
name: 'BookEditorChaptersMenu',
components: {},
data() {},
computed: {},
mounted() {},
methods: {}
}

</script>

<template>
<div class="">
template
</div>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script>
export default {
name: 'BookEditorHeader',
components: {},
data() {},
computed: {},
mounted() {},
methods: {}
}
</script>

<template>
<div class="w-full h-10 border-b border-slate-300" />
</template>
Loading
Loading