Skip to content

Commit

Permalink
[박현석]
Browse files Browse the repository at this point in the history
- 글쓴이 이름 보이게 하기 미완료

#7

#8

#9

#10
  • Loading branch information
hsp9781 committed Mar 24, 2023
1 parent 96cc365 commit eef3de9
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

public class FileManagerService {

public static final String FILE_UPLOAD_PATH = "D:\\web_hsp\\spring_project\\upload\\hoicegram\\image";
//
public static final String FILE_UPLOAD_PATH = "/Users/hsp9781/web_hsp/spring_project/upload/hoicegram/image";
// "D:\\web_hsp\\spring_project\\upload\\hoicegram\\image"
// "/Users/hsp9781/web_hsp/spring_project/upload/memo/image"

//파일 저장 -> 경로 생성
Expand Down
26 changes: 25 additions & 1 deletion src/main/java/com/hsp/hoicegram/post/PostController.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
package com.hsp.hoicegram.post;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hsp.hoicegram.post.bo.PostBO;
import com.hsp.hoicegram.post.model.Post;
import com.hsp.hoicegram.user.bo.UserBO;
import com.hsp.hoicegram.user.model.User;

@Controller
@RequestMapping("/post")
public class PostController {

@Autowired
private PostBO postBO;

@Autowired
private UserBO userBO;

@GetMapping("/timeline/view")
public String list() {
public String list(Model model) {

List<Post> postList = postBO.getPostList();
List<User> userList = userBO.getNicknameList();

model.addAttribute("postList", postList);
model.addAttribute("userList", userList);

return "post/list";
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/hsp/hoicegram/post/bo/PostBO.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.hsp.hoicegram.post.bo;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.hsp.hoicegram.common.FileManagerService;
import com.hsp.hoicegram.post.dao.PostDAO;
import com.hsp.hoicegram.post.model.Post;

@Service
public class PostBO {
Expand All @@ -17,5 +20,9 @@ public int addPost(int userId, String content, MultipartFile file) {
String imagePath = FileManagerService.saveFile(userId, file);
return postDAO.insertPost(userId, content, imagePath);
}

public List<Post> getPostList() {
return postDAO.selectPostList();
}

}
8 changes: 8 additions & 0 deletions src/main/java/com/hsp/hoicegram/post/dao/PostDAO.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
package com.hsp.hoicegram.post.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import com.hsp.hoicegram.post.model.Post;

@Repository
public interface PostDAO {

public int insertPost(
@Param("userId") int userId
, @Param("content") String content
, @Param("imagePath") String imagePath);

public List<Post> selectPostList();

public String selectNickname(int userId);

}
52 changes: 52 additions & 0 deletions src/main/java/com/hsp/hoicegram/post/model/Post.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.hsp.hoicegram.post.model;

import java.util.Date;

public class Post {
private int id;
private int userId;
private String content;
private String imagePath;
private Date createdAt;
private Date updatedAt;


public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getImagePath() {
return imagePath;
}
public void setImagePath(String imagePath) {
this.imagePath = imagePath;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}


}
7 changes: 7 additions & 0 deletions src/main/java/com/hsp/hoicegram/user/bo/UserBO.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.hsp.hoicegram.user.bo;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -65,6 +67,11 @@ public User getUser(String email, String password) {
String encryptPassword = EncryptService.md5(password);
return userDAO.selectUser(email, encryptPassword);
}


public List<User> getNicknameList() {
return userDAO.selectNicknameList();
}


}
4 changes: 4 additions & 0 deletions src/main/java/com/hsp/hoicegram/user/dao/UserDAO.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.hsp.hoicegram.user.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

Expand Down Expand Up @@ -30,5 +32,7 @@ public User selectUser(
@Param("email") String email
, @Param("password") String password);

public List<User> selectNicknameList();


}
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ spring:
suffix: .jsp
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/hoicegram_0316
url: jdbc:mysql://localhost:3306/hoicegram
username: root
password: root
15 changes: 15 additions & 0 deletions src/main/resources/mappers/postMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,20 @@
, now()
)
</insert>

<select id="selectPostList" resultType="com.hsp.hoicegram.post.model.Post">
SELECT
`id`
, `userId`
, `content`
, `imagePath`
, `createdAt`
, `updatedAt`
FROM
`post`
</select>




</mapper>
13 changes: 11 additions & 2 deletions src/main/resources/mappers/userMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,16 @@

</select>

<select id="selectNicknameList" resultType="com.hsp.hoicegram.user.model.User">
SELECT
`id`
, `userName`
FROM
`user`
</select>
</mapper>





</mapper>

10 changes: 0 additions & 10 deletions src/main/resources/static/css/post/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,7 @@ header {
height:70px;
}

.contents {
height:730px;
}

.contents > .img {
height:350px;
}

.contents > .like {
height:50px;
}

footer {
height:70px;
Expand Down
24 changes: 17 additions & 7 deletions src/main/webapp/WEB-INF/jsp/post/list.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,24 @@

<div id="wrap">
<header class="d-flex justify-content-between align-items-end">
<h1 class="font-weight-light Italianno">hoicegram</h1>
<c:if test="${not empty userId }">
<div class="ml-3">
<h4 class=" font-weight-light ml-1">${nickname }</h4>
</div>
<div class="mr-1"> <a href="/user/signout" class="btn btn-dark text-light">logout</a> </div>
</c:if>
</header>
<section class="contents">
<c:forEach var="post" items="${postList }">
<div class="card-box border rounded mt-3">
<div class="d-flex justify-content-between align-items-end">
<c:if test="${not empty userId }">
<div class="ml-3">
<h4 class=" font-weight-light ml-1">${nickname }</h4>
<c:forEach var="user" items="${userList }">
<c:if test="${user.id eq post.userId }">
<h4 class=" font-weight-light ml-1">${user.nickname }</h4>
</c:if>
</c:forEach>
</div>
</c:if>
<div class="menu mt-3 mr-2">
<div class="dropdown">
<button class="btn" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Expand All @@ -49,11 +54,14 @@
</div>
</div>
</div>
<c:if test="${not empty post.imagePath }">
<div class="img d-flex justify-content-center align-items-center mt-3">
<img alt="도시사진" width="600px" src="https://cdn.pixabay.com/photo/2023/03/13/04/25/buildings-7848348_960_720.jpg">
<img alt="도시사진" width="600px" src="${post.imagePath }">
</div>
<div class="mt-4 mb-4">
시티뷰 지렸다..
</c:if>
<div class="content-box mt-4 mb-4 d-flex">
<div class="nickname font-weight-bold">${post.userId }</div>
<div class="content ml-2"> ${post.content }</div>
</div>
<div class="like d-flex align-items-center">
<i class="bi bi-heart"></i>
Expand All @@ -76,7 +84,9 @@
</div>
</div>
</div>
</c:forEach>
</section>

<footer>
<div class="text-center mt-3">CopyRight</div>
</footer>
Expand Down

0 comments on commit eef3de9

Please sign in to comment.