Skip to content

Commit

Permalink
Merge pull request #375 from KEEPER31337/feature/#372-게시글-QA-버그수정
Browse files Browse the repository at this point in the history
Feature/게시글 QA 버그수정
  • Loading branch information
shkisme authored Oct 4, 2023
2 parents cf3ba8c + 139c2a9 commit 73bb672
Show file tree
Hide file tree
Showing 14 changed files with 182 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.keeper.homepage.domain.attendance.api;

import com.keeper.homepage.domain.attendance.application.AttendanceService;
import com.keeper.homepage.domain.attendance.dto.response.AttendanceContinuousRankResponse;
import com.keeper.homepage.domain.attendance.dto.response.AttendanceInfoResponse;
import com.keeper.homepage.domain.attendance.dto.response.AttendancePointResponse;
import com.keeper.homepage.domain.attendance.dto.response.AttendanceRankResponse;
import com.keeper.homepage.domain.attendance.dto.response.AttendanceResponse;
import com.keeper.homepage.domain.attendance.dto.response.AttendanceTodayRankResponse;
import com.keeper.homepage.domain.member.entity.Member;
import com.keeper.homepage.global.config.security.annotation.LoginMember;
import jakarta.validation.constraints.PositiveOrZero;
Expand All @@ -31,15 +32,15 @@ public class AttendanceController {
private final AttendanceService attendanceService;

@GetMapping("/today-rank")
public ResponseEntity<Page<AttendanceRankResponse>> getTodayRanks(
public ResponseEntity<Page<AttendanceTodayRankResponse>> getTodayRanks(
@RequestParam(defaultValue = "0") @PositiveOrZero int page,
@RequestParam(defaultValue = "10") @PositiveOrZero int size
) {
return ResponseEntity.ok(attendanceService.getTodayRanks(PageRequest.of(page, size)));
}

@GetMapping("/continuous-rank")
public ResponseEntity<List<AttendanceRankResponse>> getContinuousRanks() {
public ResponseEntity<List<AttendanceContinuousRankResponse>> getContinuousRanks() {
return ResponseEntity.ok(attendanceService.getContinuousRanks());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import static com.keeper.homepage.global.error.ErrorCode.ATTENDANCE_NOT_FOUND;

import com.keeper.homepage.domain.attendance.dao.AttendanceRepository;
import com.keeper.homepage.domain.attendance.dto.response.AttendanceContinuousRankResponse;
import com.keeper.homepage.domain.attendance.dto.response.AttendanceInfoResponse;
import com.keeper.homepage.domain.attendance.dto.response.AttendancePointResponse;
import com.keeper.homepage.domain.attendance.dto.response.AttendanceRankResponse;
import com.keeper.homepage.domain.attendance.dto.response.AttendanceResponse;
import com.keeper.homepage.domain.attendance.dto.response.AttendanceTodayRankResponse;
import com.keeper.homepage.domain.attendance.entity.Attendance;
import com.keeper.homepage.domain.member.application.convenience.MemberFindService;
import com.keeper.homepage.domain.member.entity.Member;
Expand Down Expand Up @@ -109,18 +110,18 @@ private int getContinuousPoint(int continuousDay) {
.orElse(0);
}

public Page<AttendanceRankResponse> getTodayRanks(Pageable pageable) {
public Page<AttendanceTodayRankResponse> getTodayRanks(Pageable pageable) {
LocalDate now = LocalDate.now();
Page<Attendance> attendances = attendanceRepository.findAllByDateOrderByRankAsc(now, pageable);
return attendances.map(AttendanceRankResponse::from);
return attendances.map(AttendanceTodayRankResponse::from);
}

public List<AttendanceRankResponse> getContinuousRanks() {
public List<AttendanceContinuousRankResponse> getContinuousRanks() {
LocalDate now = LocalDate.now();
List<Attendance> attendances = attendanceRepository.findAllByDateOrderByContinuousDayDesc(now);
return attendances.stream()
.limit(4)
.map(AttendanceRankResponse::from)
.map(AttendanceContinuousRankResponse::from)
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Getter
@Builder
@AllArgsConstructor(access = PRIVATE)
public class AttendanceRankResponse {
public class AttendanceContinuousRankResponse {

private Integer rank;
private String thumbnailPath;
Expand All @@ -23,8 +23,8 @@ public class AttendanceRankResponse {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime time;

public static AttendanceRankResponse from(Attendance attendance) {
return AttendanceRankResponse.builder()
public static AttendanceContinuousRankResponse from(Attendance attendance) {
return AttendanceContinuousRankResponse.builder()
.rank(attendance.getRank())
.thumbnailPath(attendance.getMember().getThumbnailPath())
.realName(attendance.getMember().getRealName())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.keeper.homepage.domain.attendance.dto.response;

import static lombok.AccessLevel.PRIVATE;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.keeper.homepage.domain.attendance.entity.Attendance;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
@AllArgsConstructor(access = PRIVATE)
public class AttendanceTodayRankResponse {

private Integer rank;
private String thumbnailPath;
private String realName;
private String generation;
private Integer totalAttendance;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime time;

public static AttendanceTodayRankResponse from(Attendance attendance) {
return AttendanceTodayRankResponse.builder()
.rank(attendance.getRank())
.thumbnailPath(attendance.getMember().getThumbnailPath())
.realName(attendance.getMember().getRealName())
.generation(attendance.getMember().getGeneration())
.totalAttendance(attendance.getMember().getTotalAttendance())
.time(attendance.getTime())
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void updateProfileThumbnail(Member member, MultipartFile thumbnail) {

@Transactional
public void updateProfile(Member member, Profile newProfile) {
if (!member.getProfile().getStudentId().equals(newProfile.getStudentId())) {
if (!member.getProfile().getStudentId().get().equals(newProfile.getStudentId().get())) {
checkIsDuplicateStudentId(newProfile.getStudentId());
}
Profile profile = member.getProfile();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package com.keeper.homepage.domain.point.api;

import static org.springframework.data.domain.Sort.Direction.DESC;

import com.keeper.homepage.domain.member.entity.Member;
import com.keeper.homepage.domain.point.application.GivePointService;
import com.keeper.homepage.domain.point.application.PointLogService;
import com.keeper.homepage.domain.point.dto.request.presentPointRequest;
import com.keeper.homepage.domain.point.dto.response.FindAllPointLogResponse;
import com.keeper.homepage.domain.point.entity.PointLog;
import com.keeper.homepage.global.config.security.annotation.LoginMember;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.PositiveOrZero;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
Expand Down Expand Up @@ -50,7 +52,7 @@ public ResponseEntity<Page<FindAllPointLogResponse>> findAllPointLogs(
@LoginMember Member member
) {
return ResponseEntity.ok(
pointLogService.findAllPointLogs(PageRequest.of(page, size), member.getId())
pointLogService.findAllPointLogs(PageRequest.of(page, size, Sort.by(DESC, "time")), member.getId())
.map(FindAllPointLogResponse::from)
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.keeper.homepage.domain.post.api;

import static org.springframework.data.domain.Sort.Direction.DESC;

import com.keeper.homepage.domain.file.application.FileService;
import com.keeper.homepage.domain.file.entity.FileEntity;
import com.keeper.homepage.domain.member.entity.Member;
Expand Down Expand Up @@ -27,6 +29,7 @@
import org.springframework.core.io.Resource;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand Down Expand Up @@ -207,7 +210,8 @@ public ResponseEntity<Page<MemberPostResponse>> getMemberPosts(
@RequestParam(defaultValue = "0") @PositiveOrZero int page,
@RequestParam(defaultValue = "10") @PositiveOrZero int size
) {
Page<MemberPostResponse> responses = postService.getMemberPosts(memberId, PageRequest.of(page, size));
Page<MemberPostResponse> responses = postService.getMemberPosts(memberId,
PageRequest.of(page, size, Sort.by(DESC, "registerTime")));
return ResponseEntity.ok(responses);
}

Expand All @@ -217,7 +221,8 @@ public ResponseEntity<Page<TempPostResponse>> getTempPosts(
@RequestParam(defaultValue = "0") @PositiveOrZero int page,
@RequestParam(defaultValue = "10") @PositiveOrZero int size
) {
Page<TempPostResponse> responses = postService.getTempPosts(member, PageRequest.of(page, size));
Page<TempPostResponse> responses = postService.getTempPosts(member,
PageRequest.of(page, size, Sort.by(DESC, "registerTime")));
return ResponseEntity.ok(responses);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public Long create(Post post, Long categoryId, MultipartFile thumbnail, List<Mul
if (!post.isTemp()) {
checkContent(post.getContent());
}
if (categoryId == 익명게시판.getId()) {
Member virtualMember = memberFindService.getVirtualMember();
post.changeWriter(virtualMember);
}

savePostThumbnail(post, thumbnail);
savePostFiles(post, multipartFiles);
Expand Down Expand Up @@ -131,7 +135,7 @@ public PostDetailResponse find(Member member, long postId, String password) {
boolean isDislike = member.isDislike(post);

if (post.isCategory(익명게시판)) {
return PostDetailResponse.of(post, ANONYMOUS_NAME, null, isLike, isDislike, previousPost, nextPost);
return PostDetailResponse.of(post, ANONYMOUS_NAME, isLike, isDislike, previousPost, nextPost);
}
if (post.isCategory(시험게시판) && !post.isMine(member)) {
boolean isRead = member.isRead(post);
Expand Down Expand Up @@ -341,14 +345,14 @@ public Page<PostResponse> getPosts(long categoryId, String searchType, String se

private PostResponse getPostResponse(Post post) {
if (post.isCategory(익명게시판)) {
return PostResponse.of(post, ANONYMOUS_NAME, null);
return PostResponse.of(post, ANONYMOUS_NAME);
}
return PostResponse.from(post);
}

private MainPostResponse getMainPostResponse(Post post) {
if (post.isCategory(익명게시판)) {
return MainPostResponse.of(post, ANONYMOUS_NAME, null);
return MainPostResponse.of(post, ANONYMOUS_NAME);
}
return MainPostResponse.from(post);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public static MainPostResponse from(Post post) {
.build();
}

public static MainPostResponse of(Post post, String writerName, String writerThumbnailPath) {
public static MainPostResponse of(Post post, String writerName) {
return MainPostResponse.builder()
.id(post.getId())
.title(post.getTitle())
.thumbnailPath(post.getThumbnailPath())
.categoryId(post.getCategory().getId())
.categoryName(post.getCategory().getType().getName())
.writerName(writerName)
.writerThumbnailPath(writerThumbnailPath)
.writerThumbnailPath(post.getMember().getThumbnailPath())
.visitCount(post.getVisitCount())
.isSecret(post.isSecret())
.registerTime(post.getRegisterTime())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ public static PostDetailResponse of(Post post, boolean isLike, boolean isDislike
.build();
}

public static PostDetailResponse of(Post post, String writerName, String writerThumbnailPath, boolean isLike,
boolean isDislike, Post previousPost, Post nextPost) {
public static PostDetailResponse of(Post post, String writerName, boolean isLike, boolean isDislike,
Post previousPost, Post nextPost) {
return PostDetailResponse.builder()
.categoryId(post.getCategory().getId())
.categoryName(post.getCategory().getType().toString())
.title(post.getTitle())
.writerId(1L)
.writerId(post.getMember().getId())
.writerName(writerName)
.writerThumbnailPath(writerThumbnailPath)
.writerThumbnailPath(post.getMember().getThumbnailPath())
.registerTime(post.getRegisterTime())
.updateTime(post.getUpdateTime())
.visitCount(post.getVisitCount())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ public static PostResponse from(Post post) {
.build();
}

public static PostResponse of(Post post, String writerName, String writerThumbnailPath) {
public static PostResponse of(Post post, String writerName) {
return PostResponse.builder()
.id(post.getId())
.title(post.getTitle())
.writerName(writerName)
.writerThumbnailPath(writerThumbnailPath)
.writerThumbnailPath(post.getMember().getThumbnailPath())
.visitCount(post.getVisitCount())
.commentCount(post.getComments().size())
.isSecret(post.isSecret())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void setUp() {
.optional()
),
responseFields(
pageHelper(getAttendanceResponse())
pageHelper(getTodayAttendanceResponse())
)));
}

Expand All @@ -95,11 +95,22 @@ void setUp() {
.description("ACCESS TOKEN %s".formatted(securedValue))
),
responseFields(
listHelper("", getAttendanceResponse())
listHelper("", getContinuousAttendanceResponse())
)));
}

FieldDescriptor[] getAttendanceResponse() {
FieldDescriptor[] getTodayAttendanceResponse() {
return new FieldDescriptor[]{
fieldWithPath("rank").description("회원 당일 출석 순위"),
fieldWithPath("thumbnailPath").description("회원 썸네일 경로"),
fieldWithPath("realName").description("회원 실명"),
fieldWithPath("generation").description("회원 기수"),
fieldWithPath("totalAttendance").description("회원 연속 출석 일수"),
fieldWithPath("time").description("회원 출석 시간")
};
}

FieldDescriptor[] getContinuousAttendanceResponse() {
return new FieldDescriptor[]{
fieldWithPath("rank").description("회원 당일 출석 순위"),
fieldWithPath("thumbnailPath").description("회원 썸네일 경로"),
Expand Down
Loading

0 comments on commit 73bb672

Please sign in to comment.