Skip to content

Commit

Permalink
FE 단 대규모 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Jungsu-lilly committed Jul 25, 2024
1 parent f963876 commit fe33b35
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 46 deletions.
10 changes: 7 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ jib {
from {
image = 'openjdk:21'
}
to {
image = { { IMAGE_URL } }
tags = ['0.0.1']
to{
image = 'public.ecr.aws/o4o3m8u3/sns-frontend'
tags = ['0.0.5']
auth{
username = 'AWS'
password = System.getenv('AWS_ECR_PASSWORD') ?: 'default_password' // 기본값으로 null 방지
}
}
container {
creationTime = 'USE_CURRENT_TIMESTAMP'
Expand Down
2 changes: 1 addition & 1 deletion frontend-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ spec:
spec:
containers:
- name: sns-container
image: { IMAGE_URL }
image: public.ecr.aws/o4o3m8u3/sns-frontend:0.0.5
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
import java.util.stream.Collectors;

@Controller
public class TimelineController {
public class HomeController {

private final RestTemplate restTemplate;

public TimelineController() {
public HomeController() {
this.restTemplate = new RestTemplate();
}

@GetMapping
public String listAllFeed(Model model) {
List<LinkedHashMap> posts = restTemplate.getForObject("https://a.simple-sns.link/api/timeline/random", List.class);
List<LinkedHashMap> posts = restTemplate.getForObject("http://localhost:8080/api/feeds/random", List.class);

List<SocialPost> transformedPosts = posts.stream()
.map(this::transformPost)
Expand Down
9 changes: 8 additions & 1 deletion src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
server:
port: 3000
port: 3000

spring:
thymeleaf:
prefix: classpath:/templates/
suffix: .html
mode: HTML
cache: false
4 changes: 2 additions & 2 deletions src/main/resources/templates/createpost.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ <h2>Create Post</h2>
formData.append('image', fileInput.files[0]);

try {
const uploadResponse = await fetch('https://a.simple-sns.link/api/images/upload', {
const uploadResponse = await fetch('http://localhost:8080/api/images/upload', {
method: 'POST',
body: formData,
credentials: 'include' // 쿠키 포함
Expand All @@ -111,7 +111,7 @@ <h2>Create Post</h2>

const imageId = await uploadResponse.text();

const feedResponse = await fetch('https://a.simple-sns.link/api/feeds', {
const feedResponse = await fetch('http://localhost:8080/api/feeds', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
Expand Down
28 changes: 8 additions & 20 deletions src/main/resources/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@
<div class="container">
<div class="feed" id="feed-container">
<div th:each="post : ${posts}" class="feed-item">
<img th:src="@{'https://a.simple-sns.link/api/images/view/' + ${post.imageId} + '?thumbnail=true'}"
th:data-fullsize-src="@{'https://a.simple-sns.link/api/images/view/' + ${post.imageId}}"
<img th:src="@{'https://flickerimage.s3.ap-northeast-2.amazonaws.com/thumbnail/' + ${post.imageId}}"
th:data-fullsize-src="@{'https://flickerimage.s3.ap-northeast-2.amazonaws.com/feed/' + ${post.imageId}}"
alt="Feed Image"
onclick="openModal(this)">
<p th:text="${post.formattedDate}">2024. 5. 23. 오후 11:05:24</p>
Expand Down Expand Up @@ -230,23 +230,10 @@
window.location.href = '/userposts?userId=' + userId;
}

async function fetchRandomPosts() {
try {
const response = await fetch('https://a.simple-sns.link/api/timeline', {
credentials: 'include' // 쿠키 포함
});
let posts = await response.json();
// Shuffle and limit to 15 posts
posts = posts.sort(() => 0.5 - Math.random()).slice(0, 15);
renderPosts(posts);
} catch (error) {
console.error('Error fetching random posts:', error);
}
}

async function fetchUserPosts(userId) {
try {
const response = await fetch(`https://a.simple-sns.link/api/timeline/${userId}?includeFollowingFeed=false`, {
const response = await fetch(`http://localhost:8080/api/feeds/?userId=${userId}`, {
credentials: 'include' // 쿠키 포함
});
const posts = await response.json();
Expand All @@ -263,8 +250,8 @@
const postElement = document.createElement('div');
postElement.className = 'feed-item';
postElement.innerHTML = `
<img src="https://a.simple-sns.link/api/images/view/${post.imageId}?thumbnail=true"
data-fullsize-src="https://a.simple-sns.link/api/images/view/${post.imageId}"
<img src="https://flickerimage.s3.ap-northeast-2.amazonaws.com/thumbnail/${post.imageId}"
data-fullsize-src="https://flickerimage.s3.ap-northeast-2.amazonaws.com/feed/${post.imageId}"
alt="Feed Image"
onclick="openModal(this)">
<p>${new Date(post.uploadDatetime).toLocaleString()}</p>
Expand All @@ -276,6 +263,7 @@
});
}


async function toggleLike(feedId, element) {
var userInfo = localStorage.getItem('userInfo'); // 변수 재할당
if (!userInfo) {
Expand All @@ -284,8 +272,8 @@
window.location.href = '/login';
} else {
try {
const response = await fetch(`https://a.simple-sns.link/api/timeline/like/${feedId}`, {
method: 'GET',
const response = await fetch(`http://localhost:8080/api/like?feedId=${feedId}`, {
method: 'POST',
credentials: 'include' // 쿠키 포함
});
const result = await response.json();
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ <h2>Sign In</h2>
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;

const response = await fetch('https://a.simple-sns.link/api/users/login', {
const response = await fetch('http://localhost:8080/api/users/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
Expand Down Expand Up @@ -126,7 +126,7 @@ <h2>Sign In</h2>
document.getElementById('logoutButton').addEventListener('click', async function(event) {
event.preventDefault();

const response = await fetch('https://a.simple-sns.link/api/users/logout', {
const response = await fetch('http://localhost:8080/api/users/logout', {
method: 'GET',
credentials: 'include' // include cookies in the request
});
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/templates/mypage.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ <h2>I'm Following</h2>

// 팔로워 목록을 가져오는 함수
function fetchFollowers() {
fetch('https://a.simple-sns.link/api/follows/followers', {
fetch('http://localhost:8080/api/follows/followers', {
credentials: 'include' // 쿠키 포함
})
.then(response => response.json())
Expand All @@ -106,7 +106,7 @@ <h2>I'm Following</h2>

// 팔로우 목록을 가져오는 함수
function fetchFollowings() {
fetch('https://a.simple-sns.link/api/follows/followings', {
fetch('http://localhost:8080/api/follows/followings', {
credentials: 'include' // 쿠키 포함
})
.then(response => response.json())
Expand All @@ -124,7 +124,7 @@ <h2>I'm Following</h2>

// 언팔로우 함수
window.unfollow = function(userId, element) {
fetch(`https://a.simple-sns.link/api/follows/unfollow`, {
fetch(`http://localhost:8080/api/follows/unfollow`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ <h2>Sign Up</h2>
return;
}

const response = await fetch('https://a.simple-sns.link/api/users', {
const response = await fetch('http://localhost:8080/api/users', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
Expand Down
20 changes: 10 additions & 10 deletions src/main/resources/templates/userposts.html
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@

fetchUserPosts();

fetch(`https://a.simple-sns.link/api/users/${userId}`)
fetch(`http://localhost:8080/api/users/${userId}`)
.then(response => response.json())
.then(user => {
document.getElementById('username').innerText = `@${user.username}`;
Expand Down Expand Up @@ -303,7 +303,7 @@
const userId = urlParams.get('userId');

try {
const response = await fetch(`https://a.simple-sns.link/api/timeline/${userId}?includeFollowingFeed=false`, {
const response = await fetch(`http://localhost:8080/api/feeds?userId=${userId}`, {
credentials: 'include' // 쿠키 포함
});
const posts = await response.json();
Expand All @@ -313,7 +313,7 @@
renderPosts(posts);
} else {
// 사용자의 이름을 가져오기 위해 추가 요청 수행
const userResponse = await fetch(`https://a.simple-sns.link/api/users/${userId}`, {
const userResponse = await fetch(`http://localhost:8080/api/users/${userId}`, {
credentials: 'include' // 쿠키 포함
});
const user = await userResponse.json();
Expand Down Expand Up @@ -362,8 +362,8 @@
const postElement = document.createElement('div');
postElement.className = 'feed-item';
postElement.innerHTML = `
<img src="https://a.simple-sns.link/api/images/view/${post.imageId}?thumbnail=true"
data-fullsize-src="https://a.simple-sns.link/api/images/view/${post.imageId}"
<img src="https://flickerimage.s3.ap-northeast-2.amazonaws.com/thumbnail/${post.imageId}"
data-fullsize-src="https://flickerimage.s3.ap-northeast-2.amazonaws.com/feed/${post.imageId}"
alt="Feed Image"
onclick="openModal(this)">
<p>${new Date(post.uploadDatetime).toLocaleString()}</p>
Expand All @@ -384,7 +384,7 @@
async function deletePost(feedId, element) {
if (confirm('정말 삭제하시겠습니까?')) {
try {
const response = await fetch(`https://a.simple-sns.link/api/feeds/${feedId}`, {
const response = await fetch(`http://localhost:8080/api/feeds/${feedId}`, {
method: 'DELETE',
credentials: 'include'
});
Expand All @@ -408,8 +408,8 @@
window.location.href = '/login';
} else {
try {
const response = await fetch(`https://a.simple-sns.link/api/timeline/like/${feedId}`, {
method: 'GET',
const response = await fetch(`http://localhost:8080/api/like?feedId=${feedId}`, {
method: 'POST',
credentials: 'include' // 쿠키 포함
});
const result = await response.json();
Expand All @@ -435,7 +435,7 @@
};
return;
}
const response = await fetch(`https://a.simple-sns.link/api/follows/follow/${userId}`, {
const response = await fetch(`http://localhost:8080/api/follows/follow/${userId}`, {
credentials: 'include' // 쿠키 포함
});
const isFollow = await response.json();
Expand All @@ -444,7 +444,7 @@
}

function toggleFollow(isFollow, userId, followerId) {
const url = `https://a.simple-sns.link/api/follows/${isFollow ? 'unfollow' : 'follow'}`;
const url = `http://localhost:8080/api/follows/${isFollow ? 'unfollow' : 'follow'}`;
if (!followerId) { // 비로그인 사용자
alert('Please sign in to follow users.');
localStorage.setItem('redirectAfterLogin', window.location.href); // 현재 URL 저장
Expand Down

0 comments on commit fe33b35

Please sign in to comment.