Skip to content

Commit

Permalink
Merge pull request #81 from jenny0325/main
Browse files Browse the repository at this point in the history
내가 쓴 글 보기(#80), 코드 정리
  • Loading branch information
jenny0325 authored Dec 9, 2021
2 parents e443da0 + efea8ad commit d7b4679
Show file tree
Hide file tree
Showing 22 changed files with 341 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public String getUserProfileModify() {
return "user/user_profile_upload";
}

@GetMapping("/user/post")
public String getUserPosted() {
return "user/user_post";
}

@GetMapping("/profiles") //프로필 리스트
public String getPageProfiles(){
return "profile/profile_list";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ public String checkUsername(@RequestBody UserDto userDto) {
exists = "FALSE";
return exists;
}

//회원 탈퇴
@DeleteMapping("withdrawal/{username}")
public void delPost(@PathVariable String username){
userService.deleteUser(username);
}

//
// @PostMapping("/user/profile/check-nick")
// public String checkNickname(@RequestBody UserDto userDto) {
Expand All @@ -89,30 +96,30 @@ public String checkUsername(@RequestBody UserDto userDto) {
// }

//유저프로필 수정
@PutMapping("/userProfile")
@PutMapping("/userprofile")
public void updateUser(@Valid @RequestPart(value = "key") UserProfileRequestDto userProfileDto, @RequestPart(value = "userImage",required = false) MultipartFile userImage) throws IOException{
userProfileDto.setUserProfileImg(userImage);
userService.updateUser(userProfileDto);
}

//유저 정보 가져오기
@GetMapping(value = "/userProfile/{username}")
@GetMapping(value = "/userprofile/{username}")
public UserProfileResponseDto getUserInfo(@PathVariable String username) {
User user = userService.searchUser(username);
UserProfileResponseDto userProfileResponseDto = modelMapper.map(user, UserProfileResponseDto.class);
return userProfileResponseDto;
}

@GetMapping("/user/dogProfile")
//나의 강아지 프로필 가져오기
@GetMapping("/user/dogprofile")
public List<ProfileResponseDto> getUserDogProfile(@AuthenticationPrincipal UserDetailsImpl userDetails) {
return userService.dogProfiles(userDetails.getUser().getId());
}


//회원 탈퇴
@DeleteMapping("withdrawal/{username}")
public void delPost(@PathVariable String username){
userService.deleteUser(username);
//내가 쓴 게시물 가져오기
@GetMapping(value = "/user/posts")
public List<UserPostDto> getUserPosts(@AuthenticationPrincipal UserDetailsImpl userDetails) {
return userService.post(userDetails.getUser());
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.marumaru_sparta_verspring.domain.user;

import com.example.marumaru_sparta_verspring.domain.Timestamped;
import com.example.marumaru_sparta_verspring.domain.articles.Post;
import com.example.marumaru_sparta_verspring.domain.profile.Profile;
import com.fasterxml.jackson.annotation.JsonBackReference;
import lombok.Getter;
Expand Down Expand Up @@ -31,22 +32,30 @@ public class User extends Timestamped {
@Column(nullable = false)
private String password;

@Column
private String nickname;

@Column
private Long kakaoId;

@Column(nullable = false)
@Enumerated(value = EnumType.STRING)
private UserRole role;

private String userProfileImg;
@Column
private String userProfileImg = "/img/profile.png";

@Column
private String userContent;

@JsonBackReference
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
private List<Profile> dogProfile = new ArrayList<>();

@JsonBackReference
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
private List<Post> post = new ArrayList<>();


public User(String username, String password, Long kakaoId, UserRole role) {
this.username = username;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.Getter;
import lombok.Setter;

import java.time.LocalDateTime;
import java.util.List;

@Getter
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.marumaru_sparta_verspring.dto.user;

import com.example.marumaru_sparta_verspring.domain.articles.Post;
import com.example.marumaru_sparta_verspring.domain.user.User;
import lombok.Getter;
import lombok.Setter;

import java.time.format.DateTimeFormatter;


@Getter
@Setter
public class UserPostDto {
private long idx;
private String title;
private User user;
private String createdAt; //생성시간

public UserPostDto(Post post , User user){
this.idx = post.getIdx();
this.title = post.getTitle();
this.user = user;
this.createdAt = post.getCreatedAt().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
}
}


Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.example.marumaru_sparta_verspring.repository;

import com.example.marumaru_sparta_verspring.domain.meets.Meet;
import com.example.marumaru_sparta_verspring.domain.profile.Profile;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface MeetRepository extends JpaRepository<Meet, Long> {
List<Meet> findByUserId(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import com.example.marumaru_sparta_verspring.domain.articles.Post;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;


public interface PostRepository extends JpaRepository<Post,Long> {
List<Post> findByUserId(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected void configure(HttpSecurity http) throws Exception {
.antMatchers("/login").permitAll()
.antMatchers("/login/kakao").permitAll()
.antMatchers("/signup").permitAll()
.antMatchers("/").permitAll()
.antMatchers("/**").permitAll()
.antMatchers("/docs/**").permitAll()
.antMatchers("/meets").permitAll()
.antMatchers("/meet").permitAll()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.example.marumaru_sparta_verspring.service;

import com.example.marumaru_sparta_verspring.domain.S3Uploader;
import com.example.marumaru_sparta_verspring.domain.articles.Post;
import com.example.marumaru_sparta_verspring.domain.profile.Profile;
import com.example.marumaru_sparta_verspring.domain.user.User;
import com.example.marumaru_sparta_verspring.domain.user.UserRole;
import com.example.marumaru_sparta_verspring.dto.profile.ProfileResponseDto;
import com.example.marumaru_sparta_verspring.dto.user.SignupRequestDto;
import com.example.marumaru_sparta_verspring.dto.user.UserDto;
import com.example.marumaru_sparta_verspring.dto.user.UserProfileRequestDto;
import com.example.marumaru_sparta_verspring.dto.user.UserPostDto;
import com.example.marumaru_sparta_verspring.repository.PostRepository;
import com.example.marumaru_sparta_verspring.repository.ProfileRepository;
import com.example.marumaru_sparta_verspring.repository.UserRepository;
import com.example.marumaru_sparta_verspring.security.kakao.KakaoOAuth2;
Expand Down Expand Up @@ -36,6 +39,7 @@ public class UserService {
private final AuthenticationManager authenticationManager;
private final S3Uploader s3Uploader;
private final ProfileRepository profileRepository;
private final PostRepository postRepository;

public User registerUser(SignupRequestDto requestDto) {
String username = requestDto.getUsername();
Expand Down Expand Up @@ -127,7 +131,7 @@ public void updateUser(UserProfileRequestDto userProfileDto) throws IOException
userRepository.save(user);

}
@Transactional

public List<ProfileResponseDto> dogProfiles(Long userid) {
List<ProfileResponseDto> profileResponsetDtoList = new ArrayList<>();
List<Profile> dogProfiles = profileRepository.findByUserId(userid);
Expand All @@ -137,4 +141,15 @@ public List<ProfileResponseDto> dogProfiles(Long userid) {
}
return profileResponsetDtoList;
}


public List<UserPostDto> post(User user) {
List<UserPostDto> userPostDtoList = new ArrayList<>();
List<Post> posts = postRepository.findByUserId(user.getId());
for (Post getPost : posts) {
UserPostDto userPostDto = new UserPostDto(getPost, user);
userPostDtoList.add(userPostDto);
}
return userPostDtoList;
}
}
65 changes: 65 additions & 0 deletions src/main/resources/static/css/user/user_post.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
.wrapper {
width: 1140px;
margin: 0 auto;
max-width: 100%;
padding: 0 15px;
}

.form {
padding-top: 30px;
margin-bottom: 30px;
}

.form .header {
margin-bottom: 35px;
padding-bottom: 35px;
border-bottom: 1px solid #ddd;
}

.form .header .title {
font-size: 25px;
font-weight: bold;
color: #1259a7;
}

.post_list_wrap {
padding: 10px 150px;
}

.post_list_head,
.post_list_body .item {
padding: 10px 0;
font-size: 0;
}

.post_list_head {
border-top: 2px solid #3DB2FF;
border-bottom: 1px solid;
}

.post_list_body .item {
border-bottom: 1px solid;
}

.post_list_head > div,
.post_list_body .item > div {
display: inline-block;
font-size: 14px;
text-align: center;
}

.post_list .title {
width: 60%;
}

.post_list .post_list_body .title {
text-align: left;
}

.post_list .author {
width: 15%;
}

.post_list .date {
width: 15%;
}
2 changes: 1 addition & 1 deletion src/main/resources/static/css/user/user_profile.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ody {
body {
font-family: sans-serif;
}

Expand Down
Binary file added src/main/resources/static/img/profile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/main/resources/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<button id="login-button" onclick="location.href='/user/login'" type="button" class="btn btn-success">로그인
</button>
<div onclick="get_card()"><img id="user-profile" class="rounded-circle"
src="/img/profile_placeholder.png" width="50px"
src="/img/profile.png" width="50px"
height="50px">
</div>
</div>
Expand Down Expand Up @@ -108,7 +108,7 @@ <h2>Profile card</h2>
style="width: 18rem;">
<div class="card-body text-center">
<img style="height: 100px; width: 100px" class="rounded-circle card-profile-img"
src="/img/profile_placeholder.png">
src="/img/profile.png">

<br>
<h5 class="card-title">Name</h5>
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/static/js/articles/post_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ function show_post_list() {
contentType: 'application/json; charset=utf-8',
data: {},
success: function (response) {
console.log(response)
const articles = response;
let list_num = 0
if(articles.length>0) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/resources/static/js/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ $(document).ready(function () {
let username = localStorage.getItem("username")
$.ajax({
type: "GET",
url: `/userProfile/${username}`,
url: `/userprofile/${username}`,
contentType: 'application/json; charset=utf-8',
data: {},
success: function (response){
console.log(response)
let profile_name = response['nickname']
let username = response['username']
let profile_info = response['userContent']
Expand Down
29 changes: 29 additions & 0 deletions src/main/resources/static/js/user/user_post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
$(document).ready(function () {

if (localStorage.getItem('token')) {
$.ajaxPrefilter(function (options, originalOptions, jqXHR) {
jqXHR.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem('token'));

});
} else {
alert('로그인을 해주세요')
location.replace('/login')
}

$.ajax({
type: "GET",
url: `/user/posts`,
contentType: 'application/json; charset=utf-8',
data: {},
success: function (response) {
for(let i=0; i<response.length;i++){
let temp_html=`
<div class="title"><a href="/posts/detail/${response[i]['idx']}">${response[i]['title']}</a></div>
<div class="author">${response[i]['user']['username']}</div>
<div class="date">${response[i]['createdAt']}</div>`
$('#post_list').append(temp_html)
}
}
})
})

7 changes: 3 additions & 4 deletions src/main/resources/static/js/user/user_profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ $(document).ready(function () {
let username = localStorage.getItem("username")
$.ajax({
type: "GET",
url: `/userProfile/${username}`,
url: `/userprofile/${username}`,
contentType: 'application/json; charset=utf-8',
data: {},
success: function (response) {
console.log(response)
$('.thumbnail').attr("src", response["userProfileImg"])
$('.thumbnail').attr("src", response["userProfileImg"])
$('#username').attr("placeholder", response['username'])
$('#name').attr("placeholder", response['nickname'])
Expand All @@ -29,11 +29,10 @@ $(document).ready(function () {

$.ajax({
type: "GET",
url: `/user/dogProfile`,
url: `/user/dogprofile`,
contentType: 'application/json; charset=utf-8',
data: {},
success: function (response) {
console.log(response)
for(let i=0; i<response.length;i++){
let temp_html=`<div class="card color-card">
<ul>
Expand Down
Loading

0 comments on commit d7b4679

Please sign in to comment.