Skip to content

Commit

Permalink
Merge pull request #13 from gutanbug/fix/study
Browse files Browse the repository at this point in the history
fix: 단터디 게시판 신청 기능 추가 및 엔티티 클래스 수정, 오픈채팅방 링크 제거
  • Loading branch information
gutanbug authored Dec 26, 2023
2 parents b4067f0 + 7c71063 commit f1aa1e4
Show file tree
Hide file tree
Showing 26 changed files with 223 additions and 56 deletions.
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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,21 @@ public class ResponseSingleWithDankookDto {
@Schema(description = "작성자", example = "익명")
private final String author;

@Schema(description = "성별", example = "남자")
private final String gender;

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

@Schema(description = "소속 대학", example = "SW융합대학")
private final String department;

@Schema(description = "소속 학과", example = "소프트웨어학과")
private final String major;

@Schema(description = "생성 날짜")
private final LocalDateTime createdAt;

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

@Schema(description = "좋아요 수", example = "26")
private final int likes;

Expand All @@ -36,8 +45,11 @@ public class ResponseSingleWithDankookDto {
public ResponseSingleWithDankookDto(int likes, boolean isMine, boolean isLiked, WithDankook withDankook) {
this.id = withDankook.getId();
this.author = withDankook.getDisplayingUsername();
this.gender = withDankook.getMasterUser().getGender();
this.studentId = withDankook.getMasterUser().getStudentId();
this.major = withDankook.getMasterUser().getMajor().getName();
this.department = withDankook.getMasterUser().getMajor().getDepartment();
this.createdAt = withDankook.getCreatedAt();
this.chatLink = withDankook.getChatLink();
this.likes = likes;
this.isMine = isMine;
this.isLiked = isLiked;
Expand All @@ -47,8 +59,11 @@ public ResponseSingleWithDankookDto(int likes, boolean isMine, boolean isLiked,
public ResponseSingleWithDankookDto(ResponseSingleWithDankookDto copy) {
this.id = copy.id;
this.author = copy.author;
this.gender = copy.gender;
this.studentId = copy.studentId;
this.major = copy.major;
this.department = copy.department;
this.createdAt = copy.createdAt;
this.chatLink = copy.chatLink;
this.likes = copy.likes;
this.isMine = copy.isMine;
this.isLiked = copy.isLiked;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,11 @@ public abstract class WithDankook extends BaseEntity {
@OneToMany(mappedBy = "withDankook", cascade = CascadeType.ALL, orphanRemoval = true)
private List<WithDankookUser> users = new ArrayList<>();

@NonNull
@Lob
@Column(name = "chat_link")
private String chatLink;

@Enumerated(STRING)
private WithDankookStatus withDankookStatus;

protected WithDankook(User user, String chatLink) {
protected WithDankook(User user) {
this.masterUser = user;
this.chatLink = chatLink;
this.withDankookStatus = ACTIVE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public class BearEats extends WithDankook {


@Builder
private BearEats(User user, String chatLink, String restaurant, String deliveryPlace, LocalDateTime deliveryTime, String content) {
super(user, chatLink);
private BearEats(User user, String restaurant, String deliveryPlace, LocalDateTime deliveryTime, String content) {
super(user);
this.restaurant = restaurant;
this.deliveryPlace = deliveryPlace;
this.deliveryTime = deliveryTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class Dormitory extends WithDankook {
private String duration;

@Builder
private Dormitory(User user, String chatLink, String title, int minStudentId, String livingHall, String duration) {
super(user, chatLink);
private Dormitory(User user, String title, int minStudentId, String livingHall, String duration) {
super(user);
this.title = title;
this.minStudentId = minStudentId;
this.livingHall = livingHall;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class EatingAlong extends WithDankook {
private String content;

@Builder
private EatingAlong(User user, String chatLink, String title, String content) {
super(user, chatLink);
private EatingAlong(User user, String title, String content) {
super(user);
this.title = title;
this.content = content;
}
Expand Down
Loading

0 comments on commit f1aa1e4

Please sign in to comment.