Skip to content

Commit

Permalink
Merge pull request EveryUniv#35 from gutanbug/dev_deploy
Browse files Browse the repository at this point in the history
feat: 단터디 신청 기능 및 내가 쓴 청원 글, 동의한 청원 글 가져오는 기능 추가
  • Loading branch information
gutanbug authored Dec 26, 2023
2 parents 81d2d5f + ee59fa0 commit 980d97c
Show file tree
Hide file tree
Showing 32 changed files with 271 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ public ResponsePage<SummarizedPetitionDto> listMyPosts(AppAuthentication auth,
return new ResponsePage<>(posts);
}

/**
* 내가 동의한 글 조회
*/
@GetMapping("/my/agreed")
@UserAuth
public ResponsePage<SummarizedPetitionDto> listMyAgreedPosts(AppAuthentication auth,
@ParameterObject Pageable pageable,
@RequestParam(defaultValue = "50") int bodySize) {
Page<SummarizedPetitionDto> posts =
petitionService.listMyAgreedPosts(auth.getUserId(), pageable, bodySize);
return new ResponsePage<>(posts);
}

/**
* 게시글 등록
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ public interface PetitionRepository extends GenericPostRepository<Petition>{
@Query("select p from Petition p where p.user.id=:userId and p.status='ACTIVE'")
Page<Petition> findAllByUserId(@Param("userId") Long userId, Pageable pageable);

@Query("select p from Petition p " +
"join fetch PetitionStatistic ps on p.id = ps.petition.id " +
"where ps.user.id=:userId and p.status='ACTIVE' ")
Page<Petition> findAllAgreedByUserId (@Param("userId") Long userId, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,21 @@ public interface PostRepository extends JpaRepository<Post, Long> {
"and p.status='ACTIVE'")
Long countAllByUserId(@Param("userId") Long userId);

/**
* user 가 작성한 청원 게시글의 총 개수를 가져옵니다.
*/
@Query("select count(*) from Post p " +
"where p.user.id=:userId and " +
"TYPE(p) IN (Petition) and " +
"p.status='ACTIVE' ")
Long countAllPetitionByUserId(@Param("userId") Long userId);

/**
* user 가 동의한 청원 게시글의 총 개수를 가져옵니다.
*/
@Query("select count(*) from Post p " +
"join PetitionStatistic as ps on p.id = ps.petition.id " +
"where ps.user.id=:userId and " +
"p.status='ACTIVE' ")
Long countAllAgreedPetitionByUserId(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,13 @@ public Page<SummarizedPetitionDto> listMyPosts(Long userId, Pageable pageable, i
return new SummarizedPetitionDto(dto, post, expiresTime, statisticService.count(post.getId()));
});
}

@Transactional(readOnly = true)
public Page<SummarizedPetitionDto> listMyAgreedPosts(Long userId, Pageable pageable, int bodySize) {
return repository.findAllAgreedByUserId(userId, pageable)
.map(post -> {
SummarizedGenericPostDto dto = postService.makeListDto(bodySize, post);
return new SummarizedPetitionDto(dto, post, expiresTime, statisticService.count(post.getId()));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ public class ResponseUserInfoDto {
private final Long writePostCount;
private final Long commentedPostCount;
private final Long likedPostCount;
private final Long petitionCount;
private final Long agreedPetitionCount;
private final boolean admin;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ public ResponseUserInfoDto getFullUserInfo(Long userId) {
Long writePostCount = postRepository.countAllByUserId(userId);
Long commentedPostCount = commentRepository.countAllCommentedByUserId(userId);
Long likedPostCount = likeService.getCountOfLikedElements(userId, LikeTarget.POST);
Long petitionCount = postRepository.countAllPetitionByUserId(userId);
Long agreedPetitionCount = postRepository.countAllAgreedPetitionByUserId(userId);

return new ResponseUserInfoDto(user.getStudentId(), user.getName(),
user.getNickname(), user.getAge(), user.getGender(), year,
major.getName(), major.getDepartment(), phoneNumber,
writePostCount, commentedPostCount, likedPostCount,
user.getUserRole().isAdmin());
petitionCount, agreedPetitionCount, user.getUserRole().isAdmin());
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ public ResponseIdDto create(AppAuthentication auth,
return new ResponseIdDto(id);
}

/**
* 단터디 게시글 신청
*
* @param id 게시글 id
*/
@PostMapping("/{id}/enter")
@UserAuth
public void enter(AppAuthentication auth, @PathVariable @Valid Long id) {
studyService.enter(id, auth.getUserId(), auth.getUserRole());
}

/**
* 단터디 게시글 삭제
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
import com.dku.council.domain.like.model.LikeTarget;
import com.dku.council.domain.like.service.LikeService;
import com.dku.council.domain.post.model.dto.response.ResponsePage;
import com.dku.council.domain.with_dankook.model.WithDankookStatus;
import com.dku.council.domain.with_dankook.model.dto.list.SummarizedTradeDto;
import com.dku.council.domain.with_dankook.model.dto.request.RequestCreateTradeDto;
import com.dku.council.domain.with_dankook.model.dto.response.ResponseSingleTradeDto;
import com.dku.council.domain.with_dankook.model.entity.type.Trade;
import com.dku.council.domain.with_dankook.service.TradeService;
import com.dku.council.domain.with_dankook.service.WithDankookService;
import com.dku.council.global.auth.jwt.AppAuthentication;
import com.dku.council.global.auth.role.UserAuth;
import com.dku.council.global.model.dto.ResponseIdDto;
Expand All @@ -22,7 +19,6 @@
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

@Tag(name = "단국 거래 게시판", description = "단국 거래 게시판 API")
@RestController
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.dku.council.domain.with_dankook.exception;

import com.dku.council.global.error.exception.LocalizedMessageException;
import org.springframework.http.HttpStatus;

public class AlreadyEnteredException extends LocalizedMessageException {

public AlreadyEnteredException() {
super(HttpStatus.BAD_REQUEST, "already.entered");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.dku.council.domain.with_dankook.exception;

import com.dku.council.global.error.exception.LocalizedMessageException;
import org.springframework.http.HttpStatus;

public class AlreadyFullRecruitedException extends LocalizedMessageException {

public AlreadyFullRecruitedException() {
super(HttpStatus.BAD_REQUEST, "already.full-recruited");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.dku.council.domain.with_dankook.exception;

import com.dku.council.global.error.exception.LocalizedMessageException;
import org.springframework.http.HttpStatus;

public class InvalidMinStudentIdException extends LocalizedMessageException {

public InvalidMinStudentIdException() {
super(HttpStatus.BAD_REQUEST, "invalid.student-id");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.dku.council.domain.with_dankook.exception;

import com.dku.council.global.error.exception.LocalizedMessageException;
import org.springframework.http.HttpStatus;

public class InvalidStatusException extends LocalizedMessageException {

public InvalidStatusException() {
super(HttpStatus.BAD_REQUEST, "invalid.status");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.dku.council.domain.with_dankook.model.dto;

import com.dku.council.domain.with_dankook.model.entity.WithDankookUser;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;

@Getter
public class RecruitedUsersDto {

@Schema(description = "닉네임", example = "닉네임")
private final String nickname;

@Schema(description = "학과", example = "컴퓨터공학과")
private final String majorName;

@Schema(description = "학번", example = "19")
private final String studentId;

public RecruitedUsersDto(WithDankookUser user) {
this.nickname = user.getParticipant().getNickname();
this.majorName = user.getParticipant().getMajor().getName();
this.studentId = user.getParticipant().getStudentId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public class SummarizedStudyDto extends SummarizedWithDankookDto {
private final String tag;

@Schema(description = "모집된 인원", example = "1")
private final int recruited;
private final int recruitedCount;

public SummarizedStudyDto(SummarizedWithDankookDto dto, Study study, int recruited) {
public SummarizedStudyDto(SummarizedWithDankookDto dto, Study study, int recruitedCount) {
super(dto);
this.title = study.getTitle();
this.content = study.getContent();
this.tag = study.getTag().getName();
this.recruited = recruited;
this.recruitedCount = recruitedCount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,20 @@ public class SummarizedWithDankookDto {
@Schema(description = "생성 날짜")
private final LocalDateTime createdAt;

@Schema(description = "채팅 링크", example = "https://open.kakao.com/o/ghjgjgjg")
private final String chatLink;

@Schema(description = "게시글 타입", example = "TRADE")
private final String type;

public SummarizedWithDankookDto(int bodySize, WithDankook withDankook) {
this.id = withDankook.getId();
this.author = withDankook.getDisplayingUsername();
this.createdAt = withDankook.getCreatedAt();
this.chatLink = withDankook.getChatLink();
this.type = withDankook.getClass().getSimpleName().toUpperCase();
}

public SummarizedWithDankookDto(SummarizedWithDankookDto copy) {
this.id = copy.getId();
this.author = copy.getAuthor();
this.createdAt = copy.getCreatedAt();
this.chatLink = copy.getChatLink();
this.type = copy.getType();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.dku.council.domain.user.model.entity.User;
import com.dku.council.domain.with_dankook.model.entity.type.Study;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;

Expand All @@ -20,11 +21,13 @@ public class RequestCreateStudyDto extends RequestCreateWithDankookDto<Study> {
private final int minStudentId;

@NotNull
@Schema(description = "스터디 시작 시간", example = "2023-12-25 17:30:00")
@JsonFormat(pattern = "yyyy-MM-dd HH:MM")
@Schema(description = "스터디 시작 시간", example = "2023-12-25 17:30")
private final LocalDateTime startTime;

@NotNull
@Schema(description = "스터디 끝나는 시간", example = "2023-12-25 18:30:00")
@JsonFormat(pattern = "yyyy-MM-dd HH:MM")
@Schema(description = "스터디 끝나는 시간", example = "2023-12-25 18:30")
private final LocalDateTime endTime;

@Schema(description = "해시태그", example = "자격증")
Expand All @@ -34,24 +37,18 @@ public class RequestCreateStudyDto extends RequestCreateWithDankookDto<Study> {
@Schema(description = "본문", example = "내용")
private final String content;

@NotBlank
@Schema(description = "오픈채팅방 링크", example = "https://open.kakao.com/o/abc123")
private final String chatLink;

public RequestCreateStudyDto (@NotBlank String title,
@NotBlank int minStudentId,
@NotBlank LocalDateTime startTime,
@NotBlank LocalDateTime endTime,
String tag,
@NotBlank String content,
@NotBlank String chatLink) {
@NotBlank String content) {
this.title = title;
this.minStudentId = minStudentId;
this.startTime = startTime;
this.endTime = endTime;
this.tag = tag;
this.content = content;
this.chatLink = chatLink;
}

public Study toEntity(User user) {
Expand All @@ -62,7 +59,6 @@ public Study toEntity(User user) {
.endTime(endTime)
.content(content)
.user(user)
.chatLink(chatLink)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,12 @@ public class RequestCreateTradeDto extends RequestCreateWithDankookDto<Trade> {
@Schema(description = "이미지 파일 목록")
private final List<MultipartFile> images;

@NotBlank
@Schema(description = "오픈채팅방 링크", example = "https://open.kakao.com/o/abc123")
private final String chatLink;

public RequestCreateTradeDto(@NotBlank String title, @NotBlank int price, @NotBlank String content, @NotBlank String tradePlace, List<MultipartFile> images, @NotBlank String chatLink) {
public RequestCreateTradeDto(@NotBlank String title, @NotBlank int price, @NotBlank String content, @NotBlank String tradePlace, List<MultipartFile> images) {
this.title = title;
this.price = price;
this.content = content;
this.tradePlace = tradePlace;
this.images = Objects.requireNonNullElseGet(images, ArrayList::new);
this.chatLink = chatLink;
}

public Trade toEntity(User user) {
Expand All @@ -55,7 +50,6 @@ public Trade toEntity(User user) {
.content(content)
.tradePlace(tradePlace)
.user(user)
.chatLink(chatLink)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.dku.council.domain.with_dankook.model.dto.response;

import com.dku.council.domain.with_dankook.model.dto.RecruitedUsersDto;
import com.dku.council.domain.with_dankook.model.entity.type.Study;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;

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

@Getter
public class ResponseSingleStudyDto extends ResponseSingleWithDankookDto {
Expand All @@ -28,16 +31,22 @@ public class ResponseSingleStudyDto extends ResponseSingleWithDankookDto {
private final String content;

@Schema(description = "모집된 인원", example = "1")
private final int recruited;
private final int recruitedCount;

public ResponseSingleStudyDto(ResponseSingleWithDankookDto dto, Study study, int recruited) {
@Schema(description = "모집된 사용자들")
private final List<RecruitedUsersDto> recruitedUsers;

public ResponseSingleStudyDto(ResponseSingleWithDankookDto dto, Study study, int recruitedCount) {
super(dto);
this.title = study.getTitle();
this.minStudentId = study.getMinStudentId();
this.startTime = study.getStartTime();
this.endTime = study.getEndTime();
this.content = study.getContent();
this.tag = study.getTag().getName();
this.recruited = recruited;
this.recruitedCount = recruitedCount;
this.recruitedUsers = study.getUsers().stream()
.map(RecruitedUsersDto::new)
.collect(Collectors.toList());
}
}
Loading

0 comments on commit 980d97c

Please sign in to comment.