Skip to content

Commit

Permalink
Merge branch 'develop-back' of github.com:kookmin-sw/capstone-2024-30…
Browse files Browse the repository at this point in the history
… into feature/be/#159-ApiRateLimiter
  • Loading branch information
mclub4 committed May 7, 2024
2 parents ad1f0a4 + 93f68f9 commit 3675cf5
Show file tree
Hide file tree
Showing 22 changed files with 45 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class QHelp extends EntityPathBase<Help> {

public final DateTimePath<java.time.LocalDateTime> updatedDate = createDateTime("updatedDate", java.time.LocalDateTime.class);

public final ComparablePath<java.util.UUID> uuid = createComparable("uuid", java.util.UUID.class);
public final StringPath uuid = createString("uuid");

public QHelp(String variable) {
super(Help.class, forVariable(variable));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class QAnswer extends EntityPathBase<Answer> {

public final DateTimePath<java.time.LocalDateTime> updatedDate = createDateTime("updatedDate", java.time.LocalDateTime.class);

public final ComparablePath<java.util.UUID> uuid = createComparable("uuid", java.util.UUID.class);
public final StringPath uuid = createString("uuid");

public QAnswer(String variable) {
this(Answer.class, forVariable(variable), INITS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class QQuestion extends EntityPathBase<Question> {

public final DateTimePath<java.time.LocalDateTime> updatedDate = createDateTime("updatedDate", java.time.LocalDateTime.class);

public final ComparablePath<java.util.UUID> uuid = createComparable("uuid", java.util.UUID.class);
public final StringPath uuid = createString("uuid");

public QQuestion(String variable) {
super(Question.class, forVariable(variable));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

@Controller
@RequiredArgsConstructor
@RequestMapping("/api/help")
Expand Down Expand Up @@ -48,10 +46,9 @@ public ResponseEntity<ApiResult<HelpResponse>> readHelp(
@PutMapping("/update")
@Operation(summary = "헬퍼글 수정", description = "request 정보를 기반으로 글을 수정합니다.")
@ApiResponse(responseCode = "200", description = "완료시 200을 리턴합니다.")
public ResponseEntity<ApiResult<Integer>> updateHelp(/*@RequestHeader String token,*/
public ResponseEntity<ApiResult<Integer>> updateHelp(@RequestHeader("X-User-ID") String userId,
@Parameter(description = "수정할 헬퍼글의 id와 헬퍼글의 request가 들어갑니다.", required = true)
@RequestBody HelpPutRequest request) {
String userId = UUID.randomUUID().toString();//jwtTokenProvider.extractUUID(token);
helpService.updateHelp(userId, request);
return ResponseEntity
.ok(new ApiResult<>("Successfully update help", 200));
Expand Down Expand Up @@ -83,10 +80,10 @@ public ResponseEntity<ApiResult<HelpSliceResponse>> listHelp(
@PutMapping("/done")
@Operation(summary = "헬퍼글 모집 종료", description = "id에 맞는 헬퍼글을 모집 종료합니다.")
@ApiResponse(responseCode = "200", description = "완료시 200을 반환합니다.")
public ResponseEntity<ApiResult<Integer>> doneHelp(
public ResponseEntity<ApiResult<Integer>> doneHelp(@RequestHeader("X-User-ID") String userId,
@Parameter(description = "모집 종료할 헬퍼글의 id입니다.", required = true)
@RequestParam Long id) {
helpService.doneHelp(id);
helpService.doneHelp(userId, id);
return ResponseEntity
.ok(new ApiResult<>("Successfully done help", 200));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.example.capstone.domain.help.dto;

import java.util.UUID;

public record HelpListRequest(
Long cursorId,
Boolean isDone,
Boolean isHelper,
UUID isMine
String isMine
) {
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.capstone.domain.help.dto;

import java.time.LocalDateTime;
import java.util.UUID;

public record HelpListResponse(
Long id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.capstone.domain.help.dto;

import java.time.LocalDateTime;
import java.util.UUID;

public record HelpPostRequest(
String title,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.example.capstone.domain.help.dto;

import jakarta.persistence.Column;

import java.time.LocalDateTime;
import java.util.UUID;

public record HelpResponse(
Long id,
Expand All @@ -24,6 +21,6 @@ public record HelpResponse(

LocalDateTime updatedDate,

UUID uuid
String uuid
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.*;

import java.time.LocalDateTime;
import java.util.UUID;

@Entity
@Table(name = "helps")
Expand Down Expand Up @@ -45,7 +44,7 @@ public class Help {
private LocalDateTime updatedDate;

@Column(name = "uuid", nullable = false)
private UUID uuid;
private String uuid;

public void update(String title, String context, LocalDateTime updatedDate) {
this.title = title;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package com.example.capstone.domain.help.repository;

import com.example.capstone.domain.help.dto.HelpListResponse;
import com.example.capstone.domain.help.dto.HelpSliceResponse;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;

import java.util.Map;
import java.util.UUID;

public interface HelpListRepository {
HelpSliceResponse getHelpListByPaging(Long cursorId, Pageable page, Boolean isDone, Boolean isHelper, UUID isMine);
HelpSliceResponse getHelpListByPaging(Long cursorId, Pageable page, Boolean isDone, Boolean isHelper, String isMine);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.SliceImpl;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@RequiredArgsConstructor
public class HelpRepositoryImpl implements HelpListRepository {
Expand All @@ -23,7 +19,7 @@ public class HelpRepositoryImpl implements HelpListRepository {
private QHelp help = QHelp.help;

@Override
public HelpSliceResponse getHelpListByPaging(Long cursorId, Pageable page, Boolean isDone, Boolean isHelper, UUID isMine) {
public HelpSliceResponse getHelpListByPaging(Long cursorId, Pageable page, Boolean isDone, Boolean isHelper, String isMine) {
List<HelpListResponse> helpList = jpaQueryFactory
.select(
Projections.constructor(
Expand Down Expand Up @@ -69,7 +65,7 @@ private BooleanExpression helperEq(Boolean isHelper) {
return isHelper == null ? null : help.isHelper.eq(isHelper);
}

private BooleanExpression mineEq(UUID isMine) {
return isMine == null ? null : help.uuid.eq(isMine);
private BooleanExpression mineEq(String isMine) {
return StringUtils.hasText(isMine) ? help.uuid.eq(isMine) : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.Map;
import java.util.UUID;

@Service
@RequiredArgsConstructor
Expand All @@ -24,7 +22,7 @@ public HelpResponse createHelp(String userId, HelpPostRequest request) {
LocalDateTime current = LocalDateTime.now();
Help help = helpRepository.save(Help.builder().title(request.title()).context(request.context())
.author(request.author()).createdDate(current).updatedDate(current).isHelper(request.isHelper())
.isDone(false).country(request.country()).uuid(UUID.fromString(userId)).build());
.isDone(false).country(request.country()).uuid(userId).build());

return help.toDTO();
}
Expand All @@ -38,7 +36,9 @@ public HelpResponse getHelp(Long id) {
public void updateHelp(String userId, HelpPutRequest request) {
LocalDateTime current = LocalDateTime.now();
Help help = helpRepository.findById(request.id()).get();
help.update(request.title(), request.context(), current);
if(help.getUuid().equals(userId)){
help.update(request.title(), request.context(), current);
}
}

public void eraseHelp(Long id){
Expand All @@ -55,8 +55,10 @@ public HelpSliceResponse getHelpList(HelpListRequest request) {
}

@Transactional
public void doneHelp(Long id) {
public void doneHelp(String userId, Long id) {
Help help = helpRepository.findById(id).get();
help.done();
if(help.getUuid().equals(userId)){
help.done();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.UUID;

@Controller
@RequiredArgsConstructor
@RequestMapping("/api/answer")
Expand Down Expand Up @@ -47,10 +44,9 @@ public ResponseEntity<ApiResult<AnswerSliceResponse>> listAnswer(@Parameter(desc
@PutMapping("/update")
@Operation(summary = "댓글 수정", description = "request 정보를 기반으로 댓글을 수정합니다.")
@ApiResponse(responseCode = "200", description = "완료시 200을 반환됩니다.")
public ResponseEntity<ApiResult<Integer>> updateAnswer(/*@RequestHeader String token,*/
public ResponseEntity<ApiResult<Integer>> updateAnswer(@RequestHeader("X-User-ID") String userId,
@Parameter(description = "댓글 수정을 위한 파라미터입니다. 댓글 id, 질문글 id, 작성자, 댓글 내용이 필요합니다.", required = true)
@RequestBody AnswerPutRequest request) {
String userId = UUID.randomUUID().toString(); //jwtTokenProvider.extractUUID(token);
answerService.updateAnswer(userId, request);
return ResponseEntity
.ok(new ApiResult<>("Successfully update answer", 200));
Expand All @@ -69,19 +65,21 @@ public ResponseEntity<ApiResult<Integer>> eraseAnswer( @Parameter(description
@PutMapping("/like")
@Operation(summary = "댓글 추천", description = "해당 id의 댓글을 추천합니다. 현재 추천 댓글 여부를 관리하지 않습니다.")
@ApiResponse(responseCode = "200", description = "완료시 200을 반환합니다.")
public ResponseEntity<ApiResult<Integer>> upLikeCount( @Parameter(description = "추천할 댓글의 id가 필요합니다.", required = true)
public ResponseEntity<ApiResult<Integer>> upLikeCount(@RequestHeader("X-User-ID") String userId,
@Parameter(description = "추천할 댓글의 id가 필요합니다.", required = true)
@RequestParam Long id) {
answerService.upLikeCountById(id);
answerService.upLikeCountById(userId, id);
return ResponseEntity
.ok(new ApiResult<>("Successfully like answer", 200));
}

@PutMapping("/unlike")
@Operation(summary = "댓글 추천 해제", description = "해당 id의 댓글을 추천 해제합니다. 현재 추천 댓글 여부를 관리하지 않습니다.")
@ApiResponse(responseCode = "200", description = "완료시 200을 반환합니다.")
public ResponseEntity<ApiResult<Integer>> downLikeCount( @Parameter(description = "추천 해제할 댓글의 id가 필요합니다.", required = true)
public ResponseEntity<ApiResult<Integer>> downLikeCount(@RequestHeader("X-User-ID") String userId,
@Parameter(description = "추천 해제할 댓글의 id가 필요합니다.", required = true)
@RequestParam Long id) {
answerService.downLikeCountById(id);
answerService.downLikeCountById(userId, id);
return ResponseEntity
.ok(new ApiResult<>("Successfully unlike answer", 200));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ public ResponseEntity<ApiResult<QuestionEntireResponse>> readQuestion(
@PutMapping("/update")
@Operation(summary = "질문글 수정", description = "request 정보를 기반으로 질문글을 수정합니다.")
@ApiResponse(responseCode = "200", description = "완료시 200을 리턴합니다.")
public ResponseEntity<ApiResult<Integer>> updateQuestion(/*@RequestHeader String token,*/
public ResponseEntity<ApiResult<Integer>> updateQuestion(@RequestHeader("X-User-ID") String userId,
@Parameter(description = "수정할 질문글의 id와 질문글의 request가 들어갑니다.", required = true)
@RequestBody QuestionPutRequest request) {
String userId = UUID.randomUUID().toString();//jwtTokenProvider.extractUUID(token);
questionService.updateQuestion(userId, request);
return ResponseEntity
.ok(new ApiResult<>("Successfully update question", 200));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import jakarta.persistence.ManyToOne;

import java.time.LocalDateTime;
import java.util.UUID;

public record AnswerResponse(
Long id,
Expand All @@ -17,6 +16,6 @@ public record AnswerResponse(
Long likeCount,
LocalDateTime createdDate,
LocalDateTime updatedDate,
UUID uuid
String uuid
) {
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.capstone.domain.qna.dto;

import java.time.LocalDateTime;
import java.util.UUID;

public record QuestionResponse(
Long id,
Expand All @@ -12,6 +11,6 @@ public record QuestionResponse(
LocalDateTime updatedDate,
String tag,
String country,
UUID uuid
String uuid
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
import lombok.*;

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

@Entity
@Table(name = "answers")
Expand Down Expand Up @@ -40,8 +37,8 @@ public class Answer {
@Column(name = "updated_date", nullable = false)
private LocalDateTime updatedDate;

@Column(name = "uuid", nullable = false, unique = true)
private UUID uuid;
@Column(name = "uuid", nullable = false)
private String uuid;

public void update(String context, LocalDateTime updatedDate) {
this.context = context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
import lombok.*;

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

@Entity
@Table(name = "questions")
Expand Down Expand Up @@ -44,7 +41,7 @@ public class Question {
private String country;

@Column(name = "uuid", nullable = false)
private UUID uuid;
private String uuid;

public void update(String title, String context, LocalDateTime updatedDate) {
this.title = title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.Map;
import java.util.UUID;

@Service
@RequiredArgsConstructor
Expand All @@ -27,7 +25,7 @@ public AnswerResponse createAnswer(String userId, AnswerPostRequest request) {
LocalDateTime current = LocalDateTime.now();
Question questionId = questionRepository.findById(request.questionId()).get();
Answer answer = answerRepository.save(Answer.builder().question(questionId).author(request.author())
.context(request.context()).createdDate(current).updatedDate(current).likeCount(0L).uuid(UUID.fromString(userId)).build());
.context(request.context()).createdDate(current).updatedDate(current).likeCount(0L).uuid(userId).build());
return answer.toDTO();
}

Expand All @@ -43,21 +41,23 @@ public AnswerSliceResponse getAnswerList(Long questionId, Long cursorId, String
public void updateAnswer(String userId, AnswerPutRequest request) {
LocalDateTime current = LocalDateTime.now();
Answer answer = answerRepository.findById(request.id()).get();
answer.update(request.context(), current);
if(answer.getUuid().equals(userId)){
answer.update(request.context(), current);
}
}

public void eraseAnswer(Long id) {
answerRepository.deleteById(id);
}

@Transactional
public void upLikeCountById(Long id) {
public void upLikeCountById(String userId, Long id) {
Answer answer = answerRepository.findById(id).get();
answer.upLikeCount();
}

@Transactional
public void downLikeCountById(Long id) {
public void downLikeCountById(String userId, Long id) {
Answer answer = answerRepository.findById(id).get();
answer.downLikeCount();
}
Expand Down
Loading

0 comments on commit 3675cf5

Please sign in to comment.