Skip to content

Commit

Permalink
[feature #166241006] Listing the Users profile (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
UhiriweAudace authored and Quantum-35 committed Jun 21, 2019
1 parent 7f4afa4 commit 81eb968
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 153 deletions.
20 changes: 15 additions & 5 deletions src/api/controllers/profiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,28 @@ export default class ProfilesController {
static async updateProfile(req, res) {
const { body, user } = req;
try {
if (Object.keys(body) < 1) return res.status(400).send({ message: 'Nothing Changed to your Profile' });
const updatedUser = await User.update(
{ ...body },
{ where: { id: user.id } },
);

if (!updatedUser[0]) {
return res.status(404).json({ message: `Could not find user with id: ${user.id}` });
}

return res.status(200).json({ user: { updatedUser } });
} catch (error) {
return res.status(500).json({ error: `${error}` });
}
}

/**
* @Author - Audace Uhiriwe
* @param {object} req
* @param {object} res
* @return {object} returns an object containing the user's profiles
*/
static async getAllProfile(req, res) {
const fetchedProfile = await User.findAll({ attributes: ['username', 'firstName', 'lastName', 'bio', 'image'] });
if (!fetchedProfile[0]) return res.status(200).send({ message: 'No Users Profiles found!', data: fetchedProfile });
return res.status(200).send({
profiles: fetchedProfile
});
}
}
3 changes: 2 additions & 1 deletion src/api/routes/profilesRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { Router } from 'express';
import ProfilesController from '../controllers/profiles';

const profilesRouter = Router();
const { getProfile } = ProfilesController;
const { getProfile, getAllProfile } = ProfilesController;

profilesRouter.get('/', getAllProfile);
profilesRouter.get('/:username', getProfile);

export default profilesRouter;
309 changes: 163 additions & 146 deletions swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@
}
}
},
"/user": {
"/api/user": {
"put": {
"tags": [
Expand Down Expand Up @@ -740,163 +739,123 @@
}
}
},
"/articles/{slug}/comments": {
"post": {
"tags": [
"comment"
],
"description": "User is able to add a comment on an article",
"parameters": [
{
"name": "token",
"in": "header",
"description": "Client authentication token",
"required": true
},
{
"name": "slug",
"in": "path",
"description": "Article slug",
"required": true
},
{
"name": "comment",
"in": "body",
"required": true,
"description": "User comments an article",
"schema": {
"$ref": "#/definitions/comment"
}
}
],
"produces": [
"application/json"
],
"responses": {
"201": {
"description": "Dear ..., Thank you for contributing to this article",
"schema": {
"$ref": "#/definitions/comment"
}
"/articles/{slug}/comments": {
"post": {
"tags": [
"comment"
],
"description": "User is able to add a comment on an article",
"parameters": [
{
"name": "token",
"in": "header",
"description": "Client authentication token",
"required": true
},
{
"name": "slug",
"in": "path",
"description": "Article slug",
"required": true
},
{
"name": "comment",
"in": "body",
"required": true,
"description": "User comments an article",
"schema": {
"$ref": "#/definitions/comment"
}
}
},
"get": {
"tags": [
"comment"
],
"description": "User is able to get an article with its comments",
"parameters": [
{
"name": "slug",
"in": "path",
"description": "Article slug",
"required": true
}
],
"produces": [
"application/json"
],
"responses": {
"200": {
],
"produces": [
"application/json"
],
"responses": {
"201": {
"description": "Dear ..., Thank you for contributing to this article",
"schema": {
"$ref": "#/definitions/comment"
}
}
}
},
"/articles/{slug}/comments/{commentId}": {
"post": {
"tags": [
"comment"
],
"description": "User is able to comment a comment",
"parameters": [
{
"name": "token",
"in": "header",
"description": "Client authentication token",
"required": true
},
{
"name": "slug",
"in": "path",
"description": "Article slug",
"required": true
},
{
"name": "commentId",
"in": "path",
"description": "The comment Id",
"required": true
},
{
"name": "comment",
"in": "body",
"required": true,
"description": "User comments a comment",
"schema": {
"$ref": "#/definitions/comment"
}
}
],
"produces": [
"application/json"
],
"responses": {
"201": {
"description": "Dear ..., Thank you for contributing to this comment",
"schema": {
"$ref": "#/definitions/comment"
}
}
"get": {
"tags": [
"comment"
],
"description": "User is able to get an article with its comments",
"parameters": [
{
"name": "slug",
"in": "path",
"description": "Article slug",
"required": true
}
],
"produces": [
"application/json"
],
"responses": {
"200": {
}
}
},
"/articles/comments/{commentId}": {
"patch": {
"tags": [
"comment"
],
"description": "User is able to edit a comment",
"parameters": [
{
"name": "token",
"in": "header",
"description": "Client authentication token",
"required": true
},
{
"name": "commentId",
"in": "path",
"description": "The comment Id",
"required": true
},
{
"name": "comment",
"in": "body",
"required": true,
"description": "User edits a comment",
"schema": {
"$ref": "#/definitions/comment"
}
}
},
"/articles/{slug}/comments/{commentId}": {
"post": {
"tags": [
"comment"
],
"description": "User is able to comment a comment",
"parameters": [
{
"name": "token",
"in": "header",
"description": "Client authentication token",
"required": true
},
{
"name": "slug",
"in": "path",
"description": "Article slug",
"required": true
},
{
"name": "commentId",
"in": "path",
"description": "The comment Id",
"required": true
},
{
"name": "comment",
"in": "body",
"required": true,
"description": "User comments a comment",
"schema": {
"$ref": "#/definitions/comment"
}
],
"produces": [
"application/json"
],
"responses": {
"201": {
"description": "Your comment has been edited",
"schema": {
"$ref": "#/definitions/comment"
}
}
],
"produces": [
"application/json"
],
"responses": {
"201": {
"description": "Dear ..., Thank you for contributing to this comment",
"schema": {
"$ref": "#/definitions/comment"
}
}
},
"delete": {
}
}
},
"/articles/comments/{commentId}": {
"patch": {
"tags": [
"comment"
],
"description": "User is able to delete a comment",
"description": "User is able to edit a comment",
"parameters": [
{
"name": "token",
Expand All @@ -909,18 +868,76 @@
"in": "path",
"description": "The comment Id",
"required": true
},
{
"name": "comment",
"in": "body",
"required": true,
"description": "User edits a comment",
"schema": {
"$ref": "#/definitions/comment"
}
}
],
"produces": [
"application/json"
],
"responses": {
"201": {
"description": "Your comment has been edited",
"schema": {
"$ref": "#/definitions/comment"
}
}
}
},
"delete": {
"tags": [
"comment"
],
"description": "User is able to delete a comment",
"parameters": [
{
"name": "token",
"in": "header",
"description": "Client authentication token",
"required": true
},
{
"name": "commentId",
"in": "path",
"description": "The comment Id",
"required": true
}
],
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "Comment deleted!"
}
}
}
},
"/profiles":{
"get": {
"tags": [
"Listing All Users Profiles"
],
"description": "Any User will be able to view a list of User's Profiles",
"parameters": [

],
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "Comment deleted!"
"description": "the list of All User's profile has been successfully fetched"
}
}
}
}
}
}
}
Loading

0 comments on commit 81eb968

Please sign in to comment.