diff --git a/.gitignore b/.gitignore
index 6492d18..d9feed9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,4 +33,5 @@ config.json
*.json
tmp
*test*
-*.png
\ No newline at end of file
+*.png
+!*/schemas/*
\ No newline at end of file
diff --git a/back/controllers/rooms.js b/back/controllers/rooms.js
new file mode 100644
index 0000000..7d60f69
--- /dev/null
+++ b/back/controllers/rooms.js
@@ -0,0 +1,17 @@
+const statusCode = require("../utils/statusCodes").statusCodes;
+const { getRooms } = require("../db/api.js");
+
+async function rooms(body, res) {
+ const { mailboxId, offset, limit } = body;
+ getRooms(mailboxId).then((rooms) => {
+ console.log(rooms)
+ res.status(statusCode.OK).json(rooms);
+ }).catch((err) => {
+ console.log(err)
+ res.status(statusCode.INTERNAL_SERVER_ERROR);
+ });
+}
+
+module.exports = {
+ rooms,
+};
diff --git a/back/db/api.js b/back/db/api.js
index 875d81b..384916d 100644
--- a/back/db/api.js
+++ b/back/db/api.js
@@ -20,7 +20,32 @@ async function getMailboxes() {
return await execQueryAsync(query, values);
}
+async function getRooms(mailboxId) {
+ const query = `
+ SELECT
+ app_room.room_id AS id,
+ app_room.room_name AS roomName,
+ address.email AS user,
+ app_room.owner_id AS userId,
+ app_room.notSeen,
+ mailbox_message.mailbox_id AS mailboxId
+ FROM app_room
+ INNER JOIN message
+ INNER JOIN mailbox_message
+ INNER JOIN address
+ WHERE
+ message.message_id = app_room.message_id AND
+ mailbox_message.mailbox_id = 1 AND
+ mailbox_message.message_id = message.message_id AND
+ address.address_id = app_room.owner_id
+ `;
+ // todo mailboxId
+ const values = [];
+ return await execQueryAsync(query, values);
+}
+
module.exports = {
registerMailbox,
- getMailboxes
+ getMailboxes,
+ getRooms
};
diff --git a/back/routes/mail.js b/back/routes/mail.js
index 20dd0e3..0f6bca8 100644
--- a/back/routes/mail.js
+++ b/back/routes/mail.js
@@ -9,6 +9,7 @@ addFormats(ajv);
const schema_mailbox = require("../schemas/mailbox_schema.json");
const { addMailbox } = require("../controllers/addMailbox.js");
const { getMailboxes } = require("../db/api.js");
+const { rooms } = require("../controllers/rooms.js");
const validate_mailbox = ajv.compile(schema_mailbox);
@@ -28,23 +29,11 @@ router.get("/mailboxes", (req, res) => {
* @param {string} token the token of the user
* @return {object} a list of room and their preview (subject)
*/
-router.get("/{mailboxId}/messages", (req, res) => {
+router.get("/:mailboxId/rooms", async (req, res) => {
const { mailboxId, offset, limit } = req.params;
// todo check token
// todo use offset
- const query = `
- SELECT app_room.room_id, app_room.room_name, app_room.owner_id, app_room.notSeen, mailbox_message.mailbox_id, address.email
- FROM app_room
- INNER JOIN message
- INNER JOIN mailbox_message
- INNER JOIN address
- WHERE
- message.message_id = app_room.message_id AND
- mailbox_message.mailbox_id = 1 AND
- mailbox_message.message_id = message.message_id AND
- address.address_id = app_room.owner_id
- `;
- const values = [mailboxId];
+ await rooms(req.params, res);
});
diff --git a/back/schemas/mailbox_schema.json b/back/schemas/mailbox_schema.json
new file mode 100644
index 0000000..258630f
--- /dev/null
+++ b/back/schemas/mailbox_schema.json
@@ -0,0 +1,14 @@
+{
+ "type": "object",
+ "properties": {
+ "email": { "type": "string", "format": "email" },
+ "pwd": { "type": "string" },
+ "xoauth": { "type": "string" },
+ "xoauth2": { "type": "string" },
+ "host": { "type": "string", "format": "hostname" },
+ "port": { "type": "number", "maximum": 65535 },
+ "tls": { "type": "boolean" }
+ },
+ "required": ["email", "host", "port", "tls"],
+ "additionalProperties": false
+}
\ No newline at end of file
diff --git a/front/src/services/imapAPI.js b/front/src/services/imapAPI.js
index 7a1ff90..a1cc460 100644
--- a/front/src/services/imapAPI.js
+++ b/front/src/services/imapAPI.js
@@ -7,4 +7,7 @@ export default {
getMailboxes() {
return API().get('/mail/mailboxes');
},
+ getRooms(mailboxId) {
+ return API().get(`/mail/${mailboxId}/rooms`);
+ }
}
\ No newline at end of file
diff --git a/front/src/store/rooms.js b/front/src/store/rooms.js
index 57955be..e1c8045 100644
--- a/front/src/store/rooms.js
+++ b/front/src/store/rooms.js
@@ -2,65 +2,80 @@ import API from "@/services/imapAPI";
import { createStore } from "vuex";
const roomsStore = createStore({
- state() {
- return {
- rooms: [
- {
- users: "clemnce",
- object:
- "Lorem magna minim cillum labore ex eiusmod proident excepteur sint irure ipsum.",
- mailbox: 1,
- },
- {
- users: "juliette",
- object:
- "Lorem magna minim cillum labore ex eiusmod proident excepteur sint irure ipsum.",
- mailbox: 1,
- },
- {
- users: "jean",
- object:
- "Lorem magna minim cillum labore ex eiusmod proident excepteur sint irure ipsum.",
- mailbox: 2,
- },
- {
- users: "luc",
- object:
- "Lorem magna minim cillum labore ex eiusmod proident excepteur sint irure ipsum.",
- mailbox: 2,
- },
- ],
- mailboxes: [],
- activeMailbox: -1
- };
- },
- mutations: {
- setActiveMailbox(state, payload) {
- state.activeMailbox = payload;
+ state() {
+ return {
+ rooms: [
+ {
+ id: 0,
+ user: "clemnce",
+ userId: 0,
+ name: "Lorem magna minim cillum labore ex eiusmod proident excepteur sint irure ipsum.",
+ mailboxId: 1,
+ },
+ {
+ user: "juliette",
+ name: "Lorem magna minim cillum labore ex eiusmod proident excepteur sint irure ipsum.",
+ mailboxId: 1,
+ },
+ {
+ user: "jean",
+ name: "Lorem magna minim cillum labore ex eiusmod proident excepteur sint irure ipsum.",
+ mailboxId: 2,
+ },
+ {
+ user: "luc",
+ name: "Lorem magna minim cillum labore ex eiusmod proident excepteur sint irure ipsum.",
+ mailboxId: 2,
+ },
+ ],
+ mailboxes: [],
+ activeMailbox: -1,
+ };
+ },
+ mutations: {
+ setActiveMailbox(state, payload) {
+ state.activeMailbox = payload;
+ const mailbox = state.mailboxes.find((mailbox) => mailbox.id == payload);
+ // todo fetched mailbox all
+ if (mailbox?.fetched == false) {
+ mailbox.fetched = true;
+ console.log("add messages")
+ API.getRooms(payload).then((res) => {
+ // todo add if not exist
+ res.data.forEach((room) => {
+ state.rooms.push(room);
+ });
+ }).catch((err) => {
+ console.log(err)
+ });
+ }
+ },
+ addMailboxes(state, payload) {
+ payload.forEach((mailbox) => {
+ mailbox.fetched = false;
+ state.mailboxes.push(mailbox);
+ });
+ },
+ },
+ getters: {
+ rooms: (state) => () => {
+ console.log(state.rooms.length)
+ if (state.activeMailbox == 0) return state.rooms;
+ return state.rooms.filter((room) => room.mailboxId == state.activeMailbox);
+ },
+ },
+ actions: {
+ async fetchMailboxes(context) {
+ console.log("add mailboxes");
+ API.getMailboxes()
+ .then((res) => {
+ context.commit("addMailboxes", res.data);
+ })
+ .catch((err) => {
+ console.log(err);
+ });
+ },
},
- addMailboxes(state, payload) {
- payload.forEach(mailbox => {
- state.mailboxes.push(mailbox);
- });
- }
- },
- getters: {
- rooms: (state) => () => {
- if (state.activeMailbox == 0) return state.rooms;
- return state.rooms.filter(room => room.mailbox == state.activeMailbox);
- }
- },
- actions: {
- async addMailboxes(context) {
- console.log("add mailboxes")
- API.getMailboxes().then((res) => {
- console.log(res.data)
- context.commit("addMailboxes", res.data);
- }).catch((err) => {
- console.log(err)
- });
- }
- }
});
export default roomsStore;
diff --git a/front/src/views/sidebar/Sidebar.vue b/front/src/views/sidebar/Sidebar.vue
index e8f389b..9256593 100644
--- a/front/src/views/sidebar/Sidebar.vue
+++ b/front/src/views/sidebar/Sidebar.vue
@@ -1,19 +1,19 @@