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 image post backend oli #13

Open
wants to merge 109 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
3853508
Update README.md
olikelly00 Mar 25, 2024
84d687f
Initial commit
Hyrozdmr Mar 25, 2024
cb3767f
Merge branch 'main' of https://github.com/olikelly00/xenon-go-react-a…
Hyrozdmr Mar 25, 2024
8a0858e
Merge branch 'makersacademy:main' into main
JohnForster Mar 25, 2024
055a961
Comments on errors, env, DB and seed file done
gdloparco Mar 26, 2024
7bfe1d5
Updates on seed file and extra notes on db.go
gdloparco Mar 26, 2024
8275f95
initial commit for this branch and notes added on tokens and authenti…
pirateking92 Mar 26, 2024
6211972
HomePage Styling
Hyrozdmr Mar 26, 2024
df7fbc7
last db changes
gdloparco Mar 26, 2024
fd028cf
last db changes
gdloparco Mar 26, 2024
12fc4e9
katrinas comments on posts added
katrinamichanicou Mar 26, 2024
d2b85df
katrinas post comments added
katrinamichanicou Mar 26, 2024
178e53a
katrinas user comments added
katrinamichanicou Mar 26, 2024
8f234ee
include changes by John that I hadn't pulled
pirateking92 Mar 26, 2024
b546dea
HomePage finilased
Hyrozdmr Mar 27, 2024
edb1a37
HomePage done
Hyrozdmr Mar 27, 2024
bf1ec23
users can create posts
ttyhktup Mar 27, 2024
389ee1b
some progress made to login and signup css
SGDraper Mar 27, 2024
fae7a77
unregistered user error
ttyhktup Mar 27, 2024
3ac7029
add potential readable createdAt function
pirateking92 Mar 27, 2024
c5f48ba
add readable time function
pirateking92 Mar 27, 2024
d5318cd
Merge pull request #4 from olikelly00/create_posts
ttyhktup Mar 27, 2024
15fe9ab
adds more changes to signup and login
SGDraper Mar 27, 2024
c5a5410
push for oli
pirateking92 Mar 27, 2024
cd3c704
fixes package.json
SGDraper Mar 27, 2024
f408d96
Merge branch 'main' into login_styling
SGDraper Mar 27, 2024
7c8eaab
Merge pull request #1 from olikelly00/login_styling
SGDraper Mar 27, 2024
7a1d337
fixes the package json issue on main
SGDraper Mar 27, 2024
c3387b5
add inspectable created_at time function for chronology
pirateking92 Mar 27, 2024
c6f9e51
Account created successfully message when sign-up completes
Hyrozdmr Mar 27, 2024
5c5e840
fixed login/signup pages
ttyhktup Mar 27, 2024
c5d4fcc
CreateUser function in controllers/users.go now allows for image and …
gdloparco Mar 27, 2024
b7b8c57
Merge pull request #5 from olikelly00/create_posts
ttyhktup Mar 27, 2024
103b83d
removes white border from signup page
SGDraper Mar 27, 2024
8331515
start research on implementing likes counter
pirateking92 Mar 27, 2024
bff197d
play with UpdatePostLikes
pirateking92 Mar 27, 2024
546c61f
Merge branch 'main' into SignUp
Hyrozdmr Mar 27, 2024
bbda648
Merge pull request #10 from olikelly00/SignUp
Hyrozdmr Mar 27, 2024
6e81d76
Account created successfully message updated
Hyrozdmr Mar 27, 2024
9596825
Merge pull request #11 from olikelly00/SignUp
Hyrozdmr Mar 27, 2024
67e0b98
login and sign up styles fixed
ttyhktup Mar 28, 2024
09ac958
Merge branch 'main' into JSONandStructsDB
pirateking92 Mar 28, 2024
df4195b
fixed bug with form on loginpage
ttyhktup Mar 28, 2024
ecd0d6e
Merge pull request #12 from olikelly00/create_posts
ttyhktup Mar 28, 2024
320b756
Merge pull request #9 from olikelly00/JSONandStructsDB
pirateking92 Mar 28, 2024
582d14d
Merge branch 'main' into Likes
olikelly00 Mar 28, 2024
dfff201
Merge branch 'main' of https://github.com/olikelly00/xenon-go-react-a…
katrinamichanicou Mar 28, 2024
229f3d6
Merge pull request #7 from olikelly00/username_images
katrinamichanicou Mar 28, 2024
ca303e9
all posts ordered by newest first
SGDraper Mar 28, 2024
46427ca
first commit
SGDraper Mar 28, 2024
ffe3059
Merge pull request #13 from olikelly00/ordering-posts
SGDraper Mar 28, 2024
05f7e75
added backend like functionality
olikelly00 Mar 28, 2024
ebdcc12
merged with main
ttyhktup Mar 28, 2024
55f062a
Merge pull request #14 from olikelly00/create_posts
ttyhktup Mar 28, 2024
46e2269
Testing comment Section
Hyrozdmr Mar 28, 2024
8242ded
Merge branch 'main' into comment_and_like
Hyrozdmr Mar 28, 2024
1e7514d
add like functionality
pirateking92 Mar 28, 2024
abdaf63
Merge pull request #16 from olikelly00/Likes
pirateking92 Mar 28, 2024
3e7b1ce
get user backend added
katrinamichanicou Mar 28, 2024
c07baf3
intitial commit, got likes showing under each post, tried and failed …
SGDraper Mar 28, 2024
248500b
put feedpage back
SGDraper Mar 28, 2024
c540380
add getspecificpost and working towards deleteFunction
pirateking92 Mar 28, 2024
c42da11
some scss on feed page
SGDraper Mar 28, 2024
48415af
Merge pull request #17 from olikelly00/likes-on-fe
SGDraper Mar 28, 2024
297d6f0
Merge pull request #18 from olikelly00/username_images
katrinamichanicou Mar 28, 2024
09c6fd6
added token to signup
ttyhktup Mar 28, 2024
8f11037
Merge branch 'main' of https://github.com/olikelly00/xenon-go-react-a…
ttyhktup Mar 28, 2024
5690919
added get specific post functionality
olikelly00 Mar 28, 2024
a387e72
Merge pull request #19 from olikelly00/deleteFunc
olikelly00 Mar 28, 2024
d088644
signup redirects to posts correctly <3
ttyhktup Mar 28, 2024
5f0c509
Merge pull request #20 from olikelly00/create_posts
ttyhktup Mar 28, 2024
195771a
added email formatting validation and email-already-in-database check…
olikelly00 Mar 29, 2024
9536446
added functioanlity to check password length and special characters o…
olikelly00 Mar 29, 2024
53b7fc6
user id on CreatePost function, Post struct changed, jsonStruct changed
pirateking92 Mar 29, 2024
02f8b31
adding post deletion functionality for backend
olikelly00 Mar 30, 2024
86212d0
Merge pull request #22 from olikelly00/delete_post_backend_oli
olikelly00 Apr 2, 2024
9f3005e
Merge pull request #23 from olikelly00/email_validation_backend_oli
olikelly00 Apr 2, 2024
cd9dac6
Merge branch 'main' into password_validation_backend_oli
olikelly00 Apr 2, 2024
d660163
Merge pull request #24 from olikelly00/password_validation_backend_oli
olikelly00 Apr 2, 2024
9e4ccc0
Merge branch 'main' into katrinas_comments
katrinamichanicou Apr 2, 2024
0c19ac2
Merge pull request #25 from olikelly00/katrinas_comments
katrinamichanicou Apr 2, 2024
1c55d34
Comment Section has added on Post
Hyrozdmr Apr 2, 2024
dc284e8
update for dom
pirateking92 Apr 2, 2024
5b4730d
Merge branch 'main' into comment_and_like
Hyrozdmr Apr 2, 2024
1623816
Merge pull request #15 from olikelly00/comment_and_like
Hyrozdmr Apr 2, 2024
eb6d647
Comment Section has been added on Post
Hyrozdmr Apr 2, 2024
76f0483
Merge pull request #26 from olikelly00/comment_and_like
Hyrozdmr Apr 2, 2024
42e63e5
CreatePost now returns user info
katrinamichanicou Apr 2, 2024
843e240
user id hardcoded to 18 in CreatePost
katrinamichanicou Apr 2, 2024
5af5617
merged with main
ttyhktup Apr 2, 2024
9402083
updated posts.go to use FindUser instead of GetUser func
katrinamichanicou Apr 2, 2024
375e8ef
Get user route should return user info
katrinamichanicou Apr 2, 2024
c60bb53
get route does not require ID as parameter
katrinamichanicou Apr 2, 2024
f4968d1
initial commit
SGDraper Apr 2, 2024
ae4822d
original change
pirateking92 Apr 2, 2024
93c2d84
Comment Section Completed
Hyrozdmr Apr 2, 2024
d73ef25
Merge pull request #28 from olikelly00/comment_frontend
Hyrozdmr Apr 2, 2024
685c15c
removes notes
SGDraper Apr 2, 2024
49d015d
Merge branch 'main' into extract-user-id-from-token
gdloparco Apr 2, 2024
3d571d4
Merge pull request #21 from olikelly00/extract-user-id-from-token
gdloparco Apr 2, 2024
8406518
merge conflicts
SGDraper Apr 2, 2024
bda3150
Merge pull request #27 from olikelly00/add-like-button
SGDraper Apr 2, 2024
1d2282d
feed style
ttyhktup Apr 2, 2024
5528939
back to functionality from posts -matt
pirateking92 Apr 2, 2024
066b83d
merged with main
ttyhktup Apr 2, 2024
e9e08c3
Merge branch 'main' into create_posts
ttyhktup Apr 2, 2024
48b619e
Merge pull request #29 from olikelly00/create_posts
ttyhktup Apr 2, 2024
a66677c
added functionality for uses to create posts with one image, backend
olikelly00 Apr 2, 2024
6c92ec6
Merge branch 'main' into create_image_post_backend_oli
olikelly00 Apr 2, 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ the application works.

### Card wall

REPLACE THIS TEXT WITH A LINK TO YOUR CARD WALL
https://trello.com/invite/b/YyHEoIyD/ATTIe230926302b5d8daad7ead41ef861018888CCDA1/xenon-acebook-meta

### Quickstart

Expand Down
Binary file added api/explanations/PostgreSQL Render Database.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-faker/faker/v4 v4.3.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.19.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
github.com/go-faker/faker/v4 v4.3.0 h1:UXOW7kn/Mwd0u6MR30JjUKVzguT20EB/hBOddAAO+DY=
github.com/go-faker/faker/v4 v4.3.0/go.mod h1:F/bBy8GH9NxOxMInug5Gx4WYeG6fHJZ8Ol/dhcpRub4=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
Expand Down
61 changes: 61 additions & 0 deletions api/seeds/seed.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
DROP TABLE IF EXISTS comments;
DROP SEQUENCE IF EXISTS comments_id_seq;
DROP TABLE IF EXISTS posts;
DROP SEQUENCE IF EXISTS posts_id_seq;
DROP TABLE IF EXISTS users;
DROP SEQUENCE IF EXISTS users_id_seq;

CREATE SEQUENCE IF NOT EXISTS users_id_seq;
CREATE TABLE users (
id text PRIMARY KEY,
email text,
username text,
password text
);

-- Then the table with the foreign key second.
CREATE SEQUENCE IF NOT EXISTS posts_id_seq;
CREATE TABLE posts (
id SERIAL PRIMARY KEY,
content text,
likes int,
-- The foreign key name is always {other_table_singular}_id
user_id text,
constraint fk_user foreign key(user_id)
references users(id)
on delete cascade
);

CREATE SEQUENCE IF NOT EXISTS comments_id_seq;
CREATE TABLE comments (
id SERIAL PRIMARY KEY,
content text,
likes int,
-- The foreign key name is always {other_table_singular}_id
post_id int,
constraint fk_post foreign key(post_id)
references posts(id)
on delete cascade
);

-- Seed the table with data
-- users first

INSERT INTO users (id, email, username, password)
VALUES
('9dc86cat-37bb-4c02-aab9-108ed9b2a261', '[email protected]', 'SuperCat', 'cat.123'),
('9dc86dog-37bb-4c02-aab9-108ed9b2a262', '[email protected]', 'LoyalDog', 'dog.456'),
('9dc86rab-37bb-4c02-aab9-108ed9b2a263', '[email protected]', 'BBunny', 'looney.123');

INSERT INTO posts (content, likes, user_id)
VALUES
('Post of a cat', 64, '9dc86cat-37bb-4c02-aab9-108ed9b2a261'),
('Post of a dog', 16, '9dc86dog-37bb-4c02-aab9-108ed9b2a262'),
('Another post of a dog', 134, '9dc86dog-37bb-4c02-aab9-108ed9b2a262'),
('A rabbit post', 92, '9dc86rab-37bb-4c02-aab9-108ed9b2a263');

INSERT INTO comments (content, likes, post_id)
VALUES
('Comment to a cat post', 14, 1),
('One more comment to the cat post', 54, 1);

23 changes: 21 additions & 2 deletions api/src/auth/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,25 @@ type AuthToken struct {
func GenerateToken(userID string) (string, error) {
secret := os.Getenv("JWT_SECRET")
now := time.Now()
/*
* Creates a token variable that creates a new webtoken, signs it, and maps its three values with a userID,
* a time and date which will be now, and an expiration time with now plus 10 minutes
*/
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
"sub": userID,
"iat": jwt.NewNumericDate(now),
"exp": jwt.NewNumericDate(now.Add(time.Minute * 10)),
"exp": jwt.NewNumericDate(now.Add(time.Minute * 1)),
})
// This is then returned and signed into a string of bytes, and into our secret environment variable
return token.SignedString([]byte(secret))
}

func DecodeToken(tokenString string) (AuthToken, error) {
secret := os.Getenv("JWT_SECRET")

/*
* First two lines take the code and parse it using the jwt package. Within it,
* there is a pointer to the jwt.Token, presumably to pull this function and apply it to the tokenString.
*/
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
return []byte(secret), nil
})
Expand All @@ -46,10 +54,17 @@ func DecodeToken(tokenString string) (AuthToken, error) {

func (authToken AuthToken) IsValid() bool {
now := time.Now()
// Basically checks if the AuthToken is valid by verifying the time it was
// created is within the parameters set earlier,
// that the time it was issued is not after now, and before the expiry time
return now.After(authToken.IssuedAt) && now.Before(authToken.ExpiresAt)
}

func createAuthTokenFromClaims(claims jwt.MapClaims) (AuthToken, error) {
/*
* From the previously issued AuthToken from claims in the decode function,
* this function is what powers the ending of the Decode Token and so is only callable from within this package
*/
expiresAt, err := claims.GetExpirationTime()
if err != nil {
return AuthToken{}, err
Expand All @@ -65,6 +80,10 @@ func createAuthTokenFromClaims(claims jwt.MapClaims) (AuthToken, error) {
return AuthToken{}, err
}

// Function checks the expiration time, when it was issued, the user id,
// using jwt.MapClaims to do so, and returning errors if there are any.
// If there are no errors, it will return the AuthToken in the format of the
// AuthToken struct
return AuthToken{
ExpiresAt: expiresAt.Time,
IssuedAt: issuedAt.Time,
Expand Down
13 changes: 13 additions & 0 deletions api/src/controllers/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,23 @@ import (
"github.com/gin-gonic/gin"
)

// This function is designed to handle internal server errors within
// the context of a Gin web server at CONTROLLERS LEVEL and send
// an appropriate response to the client.

func SendInternalError(ctx *gin.Context, err error) {
// The gin.Context object represents the HTTP request and response
// context, while the error object contains information about the
// error that occurred.
if gin.Mode() == "release" {
// If the mode is set to "release," it implies that the application is running
// in production mode, where detailed err messages should not be exposed to clients.
ctx.JSON(http.StatusInternalServerError, gin.H{"err": "Something went wrong"})
// In that case it sends a generic error response with HTTP status code 500
// (Internal Server Error) and a JSON object containing a generic error message.
} else {
ctx.JSON(http.StatusInternalServerError, gin.H{"err": err.Error()})
// If not, the application is running in a development or debug mode therefore
// a JSON object containing the specific error message is sent back.
}
}
Loading