Skip to content

Commit

Permalink
Merge pull request #13 from TG-WinG/feature/login
Browse files Browse the repository at this point in the history
feat : getmine 추가
  • Loading branch information
SeoYoonJu authored May 21, 2024
2 parents b298985 + 27d15b6 commit ffac54f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public interface PostRepository extends JpaRepository<PostEntity, Long> {
@Override
List<PostEntity> findAll();

List<PostEntity> findByWriter(Long id);

// List<PostEntity> findByTitleContains(String search);
// List<PostEntity> findByContentContains(String search);
Page<PostEntity> findAllByOrderByIdDesc(Pageable pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import kr.tgwing.tech.blog.entity.PostEntity;
import kr.tgwing.tech.common.ApiResponse;
import kr.tgwing.tech.user.dto.ProfileDTO;
import kr.tgwing.tech.user.dto.ProfileReqDTO;
Expand All @@ -13,6 +14,7 @@
import org.springframework.web.bind.annotation.*;

import java.security.Principal;
import java.util.List;

@RestController
@RequiredArgsConstructor
Expand All @@ -32,6 +34,16 @@ public ResponseEntity<ApiResponse<ProfileDTO>> showProfile(
return ResponseEntity.ok(ApiResponse.ok(profileDTO));
}

@Operation(summary = "내가 쓴 글 가져오기" )
@GetMapping("/mine")
public ResponseEntity<ApiResponse<List<PostEntity>>> showMyPost(Principal principal){
String studentId = principal.getName();
List<PostEntity> blog = userService.showMyBlog(studentId);

return ResponseEntity.ok(ApiResponse.ok(blog));

}

@Operation(summary = "유저 정보 수정 완료" )
@PutMapping("")
public ResponseEntity<ApiResponse<Long>> changeProfile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public interface UserRepository extends JpaRepository<UserEntity, Long> {
@Query("UPDATE UserEntity U SET U.name = :name, U.phoneNumber = :phoneNumber, U.profilePicture = :profilePicture WHERE U.studentId = :id")
void changeUser(String id, String name, String phoneNumber, String profilePicture);

@Query("SELECT U FROM UserEntity U WHERE U.studentId = :studentId")
UserEntity getEntity(String studentId);

@Query("SELECT u FROM UserEntity u WHERE u.role IS NULL")
List<UserEntity> findWaitingMember();
}

8 changes: 8 additions & 0 deletions src/main/java/kr/tgwing/tech/user/service/UserService.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package kr.tgwing.tech.user.service;


import kr.tgwing.tech.blog.entity.PostEntity;
import kr.tgwing.tech.user.dto.*;
import kr.tgwing.tech.user.entity.UserEntity;

import java.util.List;

public interface UserService{
Long register(UserDTO userDTO);
Expand All @@ -12,8 +16,12 @@ public interface UserService{

Long removeUser(String name);

UserEntity getUserEntity(String studentId);

ProfileDTO showUser(String name);

List<PostEntity> showMyBlog(String studentId);

Boolean checkUser(CheckUserDTO checkUserDTO); // 본인 확인하기

String sendEmail(EmailMessageDTO emailMessage); // 메일로 인증번호 전송하기
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/kr/tgwing/tech/user/service/UserServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import jakarta.mail.MessagingException;
import jakarta.mail.internet.MimeMessage;
import kr.tgwing.tech.blog.entity.PostEntity;
import kr.tgwing.tech.blog.repository.PostRepository;
import kr.tgwing.tech.common.exception.CommonException;
import kr.tgwing.tech.user.dto.*;
import kr.tgwing.tech.user.entity.UserEntity;
Expand All @@ -19,13 +21,15 @@
import org.thymeleaf.context.Context;
import org.thymeleaf.spring6.SpringTemplateEngine;

import java.util.List;
import java.util.Optional;
import java.util.Random;

@Service
@RequiredArgsConstructor
public class UserServiceImpl implements UserService {

private final PostRepository postRepository;
private final UserRepository userRepository;
private final JavaMailSender javaMailSender;
private final SpringTemplateEngine templateEngine;
Expand Down Expand Up @@ -79,6 +83,11 @@ public Long removeUser(String studentId){
return null;
}

@Override
public UserEntity getUserEntity(String studentId) {
UserEntity getId = userRepository.getEntity(studentId);
return getId;
}


@Override
Expand All @@ -100,6 +109,16 @@ public ProfileDTO showUser(String studentId){
return profileDTO;
}

@Override
public List<PostEntity> showMyBlog(String studentId){
UserEntity id = userRepository.getEntity(studentId);
Long userId = id.getId();
System.out.println(userId);
List<PostEntity> myBlog = postRepository.findByWriter(userId);

return myBlog;
}

@Override
public Boolean checkUser(CheckUserDTO checkUserDTO) {
UserEntity user = userRepository.findByStudentId(checkUserDTO.getStudentId())
Expand Down

0 comments on commit ffac54f

Please sign in to comment.