Skip to content

Commit

Permalink
Merge pull request #89 from gutanbug/dev
Browse files Browse the repository at this point in the history
Release dev_deploy
  • Loading branch information
gutanbug authored Apr 8, 2024
2 parents d8650dd + e187148 commit 536f3b2
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.renew.sw.mentoring.domain.admin.request;

import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class RequestCreateAdminDto {

private final String studentId;
private final String password;
private final String name;
private final String nickname;
private String studentId;
private String password;
private String name;
private String nickname;

public RequestCreateAdminDto(String studentId, String password, String name, String nickname) {
this.studentId = studentId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Optional;

public interface CompletedMissionRepository extends JpaRepository<CompletedMission, Long> {

@Query("select c from CompletedMission c where c.team.id = :teamId")
Expand All @@ -16,4 +18,7 @@ public interface CompletedMissionRepository extends JpaRepository<CompletedMissi
@Modifying
@Query("delete from CompletedMission c where c.team.id = :teamId and c.mission.id = :missionId ")
void deleteByTeamIdAndMissionId(@Param("teamId") Long teamId, @Param("missionId") Long missionId);

@Query("select c from CompletedMission c where c.team.id = :teamId and c.mission.id = :missionId ")
Optional<CompletedMission> existsByTeamIdAndMissionId(@Param("teamId") Long teamId, @Param("missionId") Long missionId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public Page<SummarizedMissionDto> list(Pageable pageable, Long teamId) {
public Page<SummarizedMissionDto> listMyTeam(Pageable pageable, Long userId) {
Page<CompletedMission> completedMissions;

Long teamId = userRepository.findById(userId).orElseThrow(UserNotFoundException::new).getId();
Long teamId = userRepository.findById(userId).orElseThrow(UserNotFoundException::new).getTeam().getId();
completedMissions = completedMissionRepository.findAllByTeamId(pageable, teamId);

return completedMissions.map(completedMission -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ public ResponseMissionBoardDto findOne(AppAuthentication auth,
}

/**
* 내가 쓴 글 조회
* 팀이 작성한 쓴 글 조회
* @return 내가 작성한 미션 인증 게시글 정보들
*
* <p>
* 멘토들에 해당됩니다.
* </p>
*/
@GetMapping("/my")
@MentorAuth
@GetMapping("/my-team")
@UserAuth
public ResponsePage<SummarizedMissionBoardDto> listMyPosts(AppAuthentication auth,
@ParameterObject Pageable pageable,
@RequestParam(defaultValue = "10") int bodySize) {
Page<SummarizedMissionBoardDto> posts = missionBoardService.listMyPosts(auth.getUserId(), pageable, bodySize);
Page<SummarizedMissionBoardDto> posts = missionBoardService.listMyTeamPosts(auth.getUserId(), pageable, bodySize);
return new ResponsePage<>(posts);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.renew.sw.mentoring.domain.post.exception;

import com.renew.sw.mentoring.global.error.exception.LocalizedMessageException;
import org.springframework.http.HttpStatus;

public class AlreadyMissionBoardException extends LocalizedMessageException {

public AlreadyMissionBoardException() {
super(HttpStatus.BAD_REQUEST, "already.mission-board");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;

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

@Getter
Expand All @@ -33,6 +34,12 @@ public class SummarizedGenericPostDto {
@Schema(description = "댓글 수", example = "16")
private final int commentCount;

@Schema(description = "게시글 생성 날짜", example = "2021-08-01T00:00:00")
private final LocalDateTime createdAt;

@Schema(description = "게시글 마지막 수정 날짜", example = "2021-08-01T00:00:00")
private final LocalDateTime lastModifiedAt;

public SummarizedGenericPostDto(AWSObjectStorageService s3service, int bodySize, Post post) {
this.id = post.getId();
this.title = post.getTitle();
Expand All @@ -41,6 +48,8 @@ public SummarizedGenericPostDto(AWSObjectStorageService s3service, int bodySize,
this.images = PostImageDto.listOf(s3service, post.getImages());
this.files = PostFileDto.listOf(s3service, post.getFiles());
this.commentCount = post.getComments().size();
this.createdAt = post.getCreatedAt();
this.lastModifiedAt = post.getLastModifiedAt();
}

private static String slice(String text, int maxLen) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Optional;

public interface MissionBoardRepository extends GenericPostRepository<MissionBoard> {
@Query("select m from MissionBoard m where m.user.id = :userId and m.registerStatus = 'IN_PROGRESS' ")
@Query("select m from MissionBoard m where m.user.id = :userId and (m.registerStatus = 'IN_PROGRESS' or m.registerStatus = 'ACCEPTED') order by m.createdAt desc ")
Page<MissionBoard> findAllByUserId(@Param("userId") Long userId, Pageable pageable);

@Query("select m from MissionBoard m where m.registerStatus = 'IN_PROGRESS' ")
@Query("select m from MissionBoard m where m.registerStatus = 'IN_PROGRESS' order by m.createdAt asc ")
Page<MissionBoard> findAllProgressPosts(Pageable pageable);

@Query("select m from MissionBoard m where m.registerStatus = 'IN_PROGRESS' and m.user.id = :userId and m.missionId = :missionId")
Optional<MissionBoard> findByMissionIdAndUserId(@Param("missionId") Long missionId, @Param("userId") Long userId);
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package com.renew.sw.mentoring.domain.post.service;

import com.renew.sw.mentoring.domain.completedmission.repository.CompletedMissionRepository;
import com.renew.sw.mentoring.domain.mission.exception.MissionNotFoundException;
import com.renew.sw.mentoring.domain.mission.repository.MissionRepository;
import com.renew.sw.mentoring.domain.post.exception.AlreadyMissionBoardAcceptedException;
import com.renew.sw.mentoring.domain.post.exception.AlreadyMissionBoardException;
import com.renew.sw.mentoring.domain.post.exception.PostNotFoundException;
import com.renew.sw.mentoring.domain.post.model.entity.dto.list.SummarizedGenericPostDto;
import com.renew.sw.mentoring.domain.post.model.entity.dto.list.SummarizedMissionBoardDto;
import com.renew.sw.mentoring.domain.post.model.entity.dto.request.RequestCreateMissionBoardDto;
import com.renew.sw.mentoring.domain.post.model.entity.dto.request.RequestUpdateMissionBoardDto;
import com.renew.sw.mentoring.domain.post.model.entity.dto.response.ResponseMissionBoardDto;
import com.renew.sw.mentoring.domain.post.model.entity.type.MissionBoard;
import com.renew.sw.mentoring.domain.post.model.entity.type.Notice;
import com.renew.sw.mentoring.domain.post.repository.MissionBoardRepository;
import com.renew.sw.mentoring.domain.post.repository.spec.PostSpec;
import com.renew.sw.mentoring.domain.team.exception.TeamNotFoundException;
import com.renew.sw.mentoring.domain.team.model.entity.Team;
import com.renew.sw.mentoring.domain.team.repository.TeamRepository;
import com.renew.sw.mentoring.domain.user.exception.UserNotFoundException;
import com.renew.sw.mentoring.domain.user.model.UserRole;
import com.renew.sw.mentoring.domain.user.model.entity.User;
import com.renew.sw.mentoring.domain.user.repository.UserRepository;
import com.renew.sw.mentoring.global.error.exception.NotGrantedException;
import com.renew.sw.mentoring.infra.s3.service.AWSObjectStorageService;
import lombok.RequiredArgsConstructor;
Expand All @@ -22,15 +28,25 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Objects;

@Service
@RequiredArgsConstructor
public class MissionBoardService {
private final GenericPostService<MissionBoard> postService;
private final AWSObjectStorageService s3service;

private final MissionBoardRepository repository;
private final UserRepository userRepository;
private final TeamRepository teamRepository;
private final CompletedMissionRepository completedMissionRepository;

public Long create(Long userId, RequestCreateMissionBoardDto dto) {
Team team = teamRepository.findByUserId(userId).orElseThrow(TeamNotFoundException::new);
if (completedMissionRepository.existsByTeamIdAndMissionId(team.getId(), dto.getMissionId()).isPresent() ||
repository.findByMissionIdAndUserId(dto.getMissionId(), userId).isPresent()) {
throw new AlreadyMissionBoardException();
}
return postService.create(repository, userId, dto);
}

Expand All @@ -45,7 +61,12 @@ public Page<SummarizedMissionBoardDto> list(String keyword, Pageable pageable, i
}

@Transactional(readOnly = true)
public Page<SummarizedMissionBoardDto> listMyPosts(Long userId, Pageable pageable, int bodySize) {
public Page<SummarizedMissionBoardDto> listMyTeamPosts(Long userId, Pageable pageable, int bodySize) {
User user = userRepository.findById(userId).orElseThrow(MissionNotFoundException::new);
if(user.getUserRole() != UserRole.MENTOR) {
Team team = teamRepository.findByUserId(userId).orElseThrow(TeamNotFoundException::new);
userId = team.getUsers().stream().filter(u -> u.getUserRole() == UserRole.MENTOR).findFirst().orElseThrow(UserNotFoundException::new).getId();
}
return repository.findAllByUserId(userId, pageable)
.map(post -> new SummarizedMissionBoardDto(s3service, bodySize, post));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.renew.sw.mentoring.domain.user.model.dto.request;

import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class RequestLoginDto {
private final String studentId;
private final String password;
private String studentId;
private String password;

public RequestLoginDto(String studentId, String password) {
this.studentId = studentId;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/errors.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ already.nickname=\uC774\uBBF8 \uC0AC\uC6A9\uC911\uC778 \uB2C9\uB124\uC784\uC785\
already.team=\uC774\uBBF8 \uC874\uC7AC\uD558\uB294 \uD300\uC785\uB2C8\uB2E4.
already.student.id=\uC774\uBBF8 \uC874\uC7AC\uD558\uB294 \uD559\uBC88\uC785\uB2C8\uB2E4.
already.mission-board.accepted=\uC774\uBBF8 \uC2B9\uC778\uB41C \uBBF8\uC158 \uC778\uC99D \uAE00\uC785\uB2C8\uB2E4.
already.mission-board=\uC774\uBBF8 \uBBF8\uC158 \uC778\uC99D\uAE00\uC774 \uC874\uC7AC\uD569\uB2C8\uB2E4.

notfound.user=\uD574\uB2F9 \uC720\uC800\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.
notfound.team=\uD574\uB2F9 \uD300\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/errors_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ already.nickname=The nickname is already in use.
already.team=The team already exists.
already.student.id=The student ID is already in use.
already.mission-board.accepted=This is a mission certificated post that has already been approved.
already.mission-board=This is a mission board post that has already been created.

notfound.user=Cannot find that user.
notfound.team=Cannot find that team.
Expand Down

0 comments on commit 536f3b2

Please sign in to comment.