diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 93556116..1673d837 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -367,19 +367,27 @@ const fetchMutes = ({credentials}) => { }).then((data) => data.json()) } -const joinGroup = ({id, credentials}) => { - const url = `${GROUP_JOINING_URL}/id.json` +const fetchGroup = ({ groupName }) => { + const url = `${GROUP_URL}/${groupName}.json` + + return fetch(url).then((data) => data.json()) +} + +const joinGroup = ({groupName, credentials}) => { + const url = `${GROUP_JOINING_URL}/${groupName}.json` return fetch(url, { - headers: authHeaders(credentials) + headers: authHeaders(credentials), + method: 'POST' }).then((data) => data.json()) } -const leaveGroup = ({id, credentials}) => { - const url = `${GROUP_LEAVING_URL}/id.json` +const leaveGroup = ({groupName, credentials}) => { + const url = `${GROUP_LEAVING_URL}/${groupName}.json` return fetch(url, { - headers: authHeaders(credentials) + headers: authHeaders(credentials), + method: 'POST' }).then((data) => data.json()) } @@ -406,8 +414,14 @@ const fetchMemberships = ({id, credentials}) => { }).then((data) => data.json()) } -const fetchMembers = (id) => { - const url = `${GROUP_MEMBERS_URL}/${id}.json` +const fetchMembers = ({ groupName }) => { + const url = `${GROUP_MEMBERS_URL}/${groupName}.json` + + return fetch(url).then((data) => data.json()) +} + +const fetchIsMember = ({id, groupName}) => { + const url = `${GROUP_IS_MEMBER_URL}?user_id=${id}&group_name=${groupName}` return fetch(url).then((data) => data.json()) } @@ -439,11 +453,13 @@ const apiService = { updateProfile, updateBanner, externalProfile, + fetchGroup, joinGroup, leaveGroup, createGroup, fetchMemberships, - fetchMembers + fetchMembers, + fetchIsMember } export default apiService diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index c2f19bde..c95b2319 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -50,20 +50,28 @@ const backendInteractorService = (credentials) => { return apiService.setUserMute({id, muted, credentials}) } - const joinGroup = (id) => { - return apiService.joinGroup({id, credentials}) + const fetchGroup = ({ groupName }) => { + return apiService.fetchGroup({ groupName }) } - const leaveGroup = (id) => { - return apiService.leaveGroup({id, credentials}) + const joinGroup = ({ groupName }) => { + return apiService.joinGroup({groupName, credentials}) } - const fetchMemberships = (id) => { + const leaveGroup = ({ groupName }) => { + return apiService.leaveGroup({groupName, credentials}) + } + + const fetchMemberships = ({ id }) => { return apiService.fetchMemberships({id, credentials}) } - const fetchMembers = (id) => { - return apiService.fetchMemberships({id, credentials}) + const fetchMembers = ({ groupName }) => { + return apiService.fetchMembers({ groupName }) + } + + const fetchIsMember = ({id, groupName}) => { + return apiService.fetchIsMember({id, groupName}) } const createGroup = (params) => apiService.createGroup({params, credentials}) @@ -99,11 +107,13 @@ const backendInteractorService = (credentials) => { updateBanner, updateProfile, externalProfile, + fetchGroup, joinGroup, leaveGroup, createGroup, fetchMemberships, - fetchMembers + fetchMembers, + fetchIsMember } return backendInteractorServiceInstance