Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ public ResponseEntity<Object> postCommunity(@RequestBody CommunityRequestDto com
@GetMapping()
public ResponseEntity<Object> getCommunity(@RequestParam(value = "query", required = false, defaultValue = "all") String query,
@RequestParam(value = "tag", required = false, defaultValue = "") String tag,
@RequestParam(value = "userId", required = false, defaultValue = "") String userId,
@RequestParam(value = "size", required = false, defaultValue = "10") int size,
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
log.info("[CommunityController] 글 목록 조회 시작");
try{
return ResponseEntity.ok(communityService.getCommunityList(query, tag, size, page));
return ResponseEntity.ok(communityService.getCommunityList(query, tag, userId, size, page));
} catch (CustomException e) {
log.error(e.getMessage());
return ResponseEntity.badRequest().body(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ResponseEntity<Object> getAllContent(@RequestParam(value = "query", requi
} else if(userId.isEmpty()){
return ResponseEntity.ok(contentService.getContentQueryWithLevel(query, level, size, page));
} else {
return ResponseEntity.ok(contentService.getContentWithUserId(userId));
return ResponseEntity.ok(contentService.getContentWithUserId(userId, query, level, size, page));
}
} catch (CustomException e) {
log.error("[getAllContent] 컨텐츠 조회 실패", e);
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/com/example/prdoit/controller/UserController.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.example.prdoit.controller;

import com.example.prdoit.dto.user.ChangePasswordDto;
import com.example.prdoit.dto.user.LoginDto;
import com.example.prdoit.dto.user.UserDto;
import com.example.prdoit.exception.CustomException;
import com.example.prdoit.service.user.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;


Expand Down Expand Up @@ -88,4 +90,55 @@ public ResponseEntity<Object> login(@RequestBody LoginDto loginDto) {
return ResponseEntity.badRequest().body(e.getMessage());
}
}

@GetMapping("/findId/{email}")
public ResponseEntity<Object> findId(@PathVariable String email){
log.info("[findId] 아이디 찾기 시작");

try{
return ResponseEntity.ok(userService.findId(email));
} catch (CustomException e) {
log.error("[findId] 아이디 찾기 실패 - 이유: {}", e.getMessage());
return ResponseEntity.badRequest().body(e.getMessage());
}
}

@GetMapping("/confirm/{userId}/{email}")
public ResponseEntity<Object> checkIdAndEmail(@PathVariable String userId, @PathVariable String email){
log.info("[checkIdAndEmail] 아이디와 이메일 확인 시작");

try{
userService.checkIdAndEmail(userId, email);
return ResponseEntity.ok("아이디와 이메일이 일치합니다.");
} catch (CustomException e) {
log.error("[checkIdAndEmail] 아이디와 이메일 확인 실패 - 이유: {}", e.getMessage());
return ResponseEntity.badRequest().body(e.getMessage());
}
}

@PatchMapping("/changePassword")
public ResponseEntity<Object> changePassword(@RequestBody ChangePasswordDto changePasswordDto){
log.info("[changePassword] 비밀번호 변경 시작");
try {
userService.changePassword(changePasswordDto.getUserId(), changePasswordDto.getNewPassword());
return ResponseEntity.ok("비밀번호 변경에 성공했습니다.");
} catch (CustomException e) {
log.error("[changePassword] 비밀번호 변경 실패 - 이유: {}", e.getMessage());
return ResponseEntity.badRequest().body(e.getMessage());
}
}

@PostMapping("/auth/password")
public ResponseEntity<Object> checkPassword(@RequestBody LoginDto loginDto) {
log.info("[checkPassword] 비밀번호 확인 시작");

try {
userService.checkPassword(loginDto.getUserId(), loginDto.getPassword());
return ResponseEntity.ok("비밀번호가 일치합니다.");
} catch (CustomException e) {
log.error("[checkPassword] 비밀번호 불일치 - 이유: {}", e.getMessage());
return ResponseEntity.badRequest().body(e.getMessage());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

import lombok.*;

import java.util.List;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ContentResponseDto {

private String contentId;
private String contentTitle;
private int contentView;
private int contentLike;
private int contentLevel;
private String writer;
private int total;
private List<ContentTitleDto> contentList;

}
18 changes: 18 additions & 0 deletions src/main/java/com/example/prdoit/dto/content/ContentTitleDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.prdoit.dto.content;

import lombok.*;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ContentTitleDto {

private String contentId;
private String contentTitle;
private int contentView;
private int contentLike;
private int contentLevel;
private String writer;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public class TotalContentDto {
private int totalView;
private int totalLike;

private List<ContentResponseDto> ContentList;
private List<ContentTitleDto> ContentList;

}
14 changes: 14 additions & 0 deletions src/main/java/com/example/prdoit/dto/user/ChangePasswordDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.prdoit.dto.user;

import lombok.*;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ChangePasswordDto {

private String userId;
private String newPassword;
}
12 changes: 1 addition & 11 deletions src/main/java/com/example/prdoit/dto/user/UserDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,5 @@ public class UserDto {
private String name;
private String email;
private String nickname;
//
@Override
public String toString() {
return "UserDto{" +
"id='" + id + '\'' +
", password='" + password + '\'' +
", name='" + name + '\'' +
", email='" + email + '\'' +
", nickname='" + nickname + '\'' +
'}';
}

}
1 change: 1 addition & 0 deletions src/main/java/com/example/prdoit/model/ContentTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class ContentTable {

@ManyToOne
@JoinColumn(name = "userId")
@JsonIgnore
private IdTable userId;

@OneToMany(mappedBy = "contentId", cascade = CascadeType.REMOVE, orphanRemoval = true, fetch = FetchType.EAGER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ public interface CommunityTableRepository extends JpaRepository<CommunityTable,
@Query("SELECT c FROM CommunityTable c WHERE c.communityTitle LIKE %:query% OR c.communityContent LIKE %:query%")
Page<CommunityTable> findAllByCommunityTitleContaining(String query, Pageable pageable);

@Query("SELECT c FROM CommunityTable c WHERE c.id.id = :userId")
Page<CommunityTable> findAllByUserId(String userId, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -1,57 +1,88 @@
package com.example.prdoit.repository;

import com.example.prdoit.dto.content.ContentResponseDto;
import com.example.prdoit.dto.content.ContentTitleDto;
import com.example.prdoit.model.ContentTable;
import com.example.prdoit.model.IdTable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.swing.text.AbstractDocument;
import java.util.List;

public interface ContentTableRepository extends JpaRepository<ContentTable, String> {

@Query("SELECT new com.example.prdoit.dto.content.ContentResponseDto" +
@Query("SELECT new com.example.prdoit.dto.content.ContentTitleDto" +
"(c.contentId, c.contentTitle, c.contentView, c.contentLike, c.contentLevel, c.userId.nickname) " +
"FROM ContentTable c LEFT JOIN CommentTable cc ON c.contentId = cc.contentId.contentId " +
"WHERE c.contentTitle LIKE %:query% GROUP BY c.contentId, c.contentTitle, c.contentView, c.contentLike, c.contentLevel " +
"ORDER BY (c.contentView * 0.33) + (c.contentLike * 0.33) + (COUNT(cc.commentId) * 0.33) DESC " +
"LIMIT :size OFFSET :offset")
List<ContentResponseDto> findAllByQueryContaining(@Param("query") String query, @Param("size") int size, @Param("offset") int offset);
List<ContentTitleDto> findAllByQueryContaining(@Param("query") String query, @Param("size") int size, @Param("offset") int offset);

@Query("SELECT new com.example.prdoit.dto.content.ContentResponseDto" +
@Query("SELECT c FROM ContentTable c WHERE c.contentTitle LIKE %:query% OR c.contentContent LIKE %:query%")
List<ContentTable> findAllByContentTitleContaining(String query);

@Query("SELECT new com.example.prdoit.dto.content.ContentTitleDto" +
"(c.contentId, c.contentTitle, c.contentView, c.contentLike, c.contentLevel, c.userId.nickname) " +
"FROM ContentTable c LEFT JOIN CommentTable cc ON c.contentId = cc.contentId.contentId " +
"GROUP BY c.contentId, c.contentTitle, c.contentView, c.contentLike, c.contentLevel " +
"ORDER BY (c.contentView * 0.33) + (c.contentLike * 0.33) + (COUNT(cc.commentId) * 0.33) DESC " +
"LIMIT :size OFFSET :offset")
List<ContentResponseDto> findAllList(@Param("size") int size, @Param("offset") int offset);
List<ContentTitleDto> findAllList(@Param("size") int size, @Param("offset") int offset);


@Query("SELECT new com.example.prdoit.dto.content.ContentResponseDto" +
@Query("SELECT new com.example.prdoit.dto.content.ContentTitleDto" +
"(c.contentId, c.contentTitle, c.contentView, c.contentLike, c.contentLevel, c.userId.nickname) " +
"FROM ContentTable c LEFT JOIN CommentTable cc on c.contentId = cc.contentId.contentId WHERE c.contentTitle LIKE %:query% AND c.contentLevel = :level " +
"GROUP BY c.contentId, c.contentTitle, c.contentView, c.contentLike, c.contentLevel " +
"ORDER BY (c.contentView * 0.33) + (c.contentLike * 0.33) + (COUNT(cc.commentId) * 0.33) DESC " +
"LIMIT :size OFFSET :offset")
List<ContentResponseDto> findAllQueryContainingAndContentLevel(@Param("query")String query, @Param("level")int level, @Param("size") int size, @Param("offset") int offset);
List<ContentTitleDto> findAllQueryContainingAndContentLevel(@Param("query")String query, @Param("level")int level, @Param("size") int size, @Param("offset") int offset);

@Query("SELECT new com.example.prdoit.dto.content.ContentResponseDto" +
@Query("SELECT c FROM ContentTable c WHERE (c.contentTitle LIKE %:query% OR c.contentContent LIKE %:query%) AND c.contentLevel = :level")
List<ContentTable> findAllByQueryContainingAndContentLevel(String query, int level);

@Query("SELECT new com.example.prdoit.dto.content.ContentTitleDto" +
"(c.contentId, c.contentTitle, c.contentView, c.contentLike, c.contentLevel, c.userId.nickname) " +
"FROM ContentTable c LEFT JOIN CommentTable cc ON c.contentId = cc.contentId.contentId WHERE c.contentLevel = :level " +
"GROUP BY c.contentId, c.contentTitle, c.contentView, c.contentLike, c.contentLevel " +
"ORDER BY (c.contentView * 0.33) + (c.contentLike * 0.33) + (COUNT(cc.commentId) * 0.33) DESC " +
"LIMIT :size OFFSET :offset")
List<ContentResponseDto> findAllByContentLevel(@Param("level") int level, @Param("size") int size, @Param("offset") int offset);
List<ContentTitleDto> findAllByContentLevel(@Param("level") int level, @Param("size") int size, @Param("offset") int offset);

List<ContentTable> findAllByContentLevel(int level);

@Query("SELECT new com.example.prdoit.dto.content.ContentResponseDto" +
@Query("SELECT new com.example.prdoit.dto.content.ContentTitleDto" +
"(c.contentId, c.contentTitle, c.contentView, c.contentLike, c.contentLevel, c.userId.nickname) " +
"FROM ContentTable c WHERE c.userId.id = :userId")
List<ContentResponseDto> findAllByUserId(@Param("userId") String userId);
Page<ContentTitleDto> findAllByUserIdPagination(@Param("userId") String userId, Pageable pageable);

@Query("SELECT new com.example.prdoit.dto.content.ContentResponseDto" +
List<ContentTable> findAllByUserId(IdTable userId);

@Query("SELECT new com.example.prdoit.dto.content.ContentTitleDto" +
"(c.contentId, c.contentTitle, c.contentView, c.contentLike, c.contentLevel, c.userId.nickname) " +
"FROM ContentTable c WHERE c.userId.id = :userId")
Page<ContentResponseDto> findAllByUserIdPagination(@Param("userId") String userId, Pageable pageable);
"FROM ContentTable c WHERE c.userId.id = :userId AND c.contentLevel = :level")
Page<ContentTitleDto> findAllByUserIdAndContentLevel(String userId, int level, Pageable pageable);

List<ContentTable> findAllByUserIdAndContentLevel(IdTable userId, int level);

@Query("SELECT new com.example.prdoit.dto.content.ContentTitleDto" +
"(c.contentId, c.contentTitle, c.contentView, c.contentLike, c.contentLevel, c.userId.nickname) " +
"FROM ContentTable c WHERE c.userId.id = :userId AND c.contentTitle LIKE %:query%")
Page<ContentTitleDto> findAllByUserIdAndQueryContaining(String userId, String query, Pageable pageable);

@Query("SELECT c FROM ContentTable c WHERE c.userId = :userId AND (c.contentTitle LIKE %:query% or c.contentContent LIKE %:query%)")
List<ContentTable> findAllByUserIdAndQueryContaining(IdTable userId, String query);

@Query("SELECT new com.example.prdoit.dto.content.ContentTitleDto" +
"(c.contentId, c.contentTitle, c.contentView, c.contentLike, c.contentLevel, c.userId.nickname) " +
"FROM ContentTable c WHERE c.userId.id = :userId AND c.contentLevel = :level AND c.contentTitle LIKE %:query%")
Page<ContentTitleDto> findAllByUserIdAndContentLevelAndQueryContaining(String userId, int level, String query, Pageable pageable);

@Query("SELECT c FROM ContentTable c WHERE c.userId = :userId AND c.contentLevel = :level AND (c.contentTitle LIKE %:query% or c.contentContent LIKE %:query%)")
List<ContentTable> findAllByUserIdAndContentLevelAndQueryContaining(IdTable userId, int level, String query);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.example.prdoit.model.IdTable;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface IdTableRepository extends JpaRepository<IdTable, String> {
IdTable findByEmail(String userEmail);
Optional<IdTable> findByEmail(String userEmail);
IdTable findByNickname(String userNickname);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface CommunityService {

void postCommunity(CommunityRequestDto communityRequestDto);

List<CommunityResponseDto> getCommunityList(String query, String tag, int size, int page);
List<CommunityResponseDto> getCommunityList(String query, String tag, String userId, int size, int page);

void patchCommunity(CommunityPatchDto communityPatchDto);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void postCommunity(CommunityRequestDto communityRequestDto) {
}

@Override
public List<CommunityResponseDto> getCommunityList(String query, String tag, int size, int page){
public List<CommunityResponseDto> getCommunityList(String query, String tag, String userId, int size, int page){
log.info("[CommunityServiceImpl] 글 목록 조회 시작");
Pageable pageable = PageRequest.of(page - 1, size);
try {
Expand Down Expand Up @@ -98,6 +98,25 @@ public List<CommunityResponseDto> getCommunityList(String query, String tag, int
.toList();
}

if(!userId.isEmpty()) {
List<CommunityTable> communityTableList = communityTableRepository.findAllByUserId(userId, pageable).toList();
return communityTableList.stream()
.map(communityTable -> CommunityResponseDto.builder()
.communityId(communityTable.getCommunityId())
.communityTitle(communityTable.getCommunityTitle())
.commentCount(communityTable.getCommentTable().size())
.userNickname(communityTable.getId().getNickname())
.communityCreatedDate(communityTable.getCommunityDate())
.communityTagList(communityTable.getCommunityTagTable().stream()
.map(CommunityTagTable -> CommunityTagResponseDto.builder()
.communityTagId(CommunityTagTable.getCommunityTagId())
.communityTag(CommunityTagTable.getCommunityTag())
.build())
.toList())
.build())
.toList();
}

return communityTableRepository.findAll(pageable).stream()
.map(communityTable -> CommunityResponseDto.builder()
.communityId(communityTable.getCommunityId())
Expand Down Expand Up @@ -163,6 +182,8 @@ public CommunityDetailResponseDto getCommunityDetail(String communityId) {
log.info("[CommunityServiceImpl] 글 상세 조회 시작");
CommunityTable communityTable = communityTableRepository.findById(communityId).orElseThrow(() -> new IllegalArgumentException("해당 글이 없습니다."));
try {
communityTable.setCommunityView(communityTable.getCommunityView() + 1);
communityTableRepository.save(communityTable);
return CommunityDetailResponseDto.builder()
.communityId(communityTable.getCommunityId())
.communityTitle(communityTable.getCommunityTitle())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
//
public interface ContentService {

List<ContentResponseDto> getContentQuery(String query, int size, int page);
ContentResponseDto getContentQuery(String query, int size, int page);

List<ContentResponseDto> getContentQueryWithLevel(String query, int level, int size, int page);
ContentResponseDto getContentQueryWithLevel(String query, int level, int size, int page);

List<ContentResponseDto> getContentWithUserId(String userId);
ContentResponseDto getContentWithUserId(String userId, String query, int level, int size, int page);

void updateContent(ContentUpdateDto contentUpdateDto);

Expand Down
Loading