Skip to content

Commit

Permalink
[DEV-10] Fix Zone API 리팩토링 및 Fix Zone Comment API 개발 (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
wonjunYou authored Jul 26, 2024
1 parent 70ff3a8 commit 4c44f5b
Show file tree
Hide file tree
Showing 31 changed files with 729 additions and 398 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ddingdong.ddingdongBE.common.converter;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.lang.reflect.Type;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;
import org.springframework.stereotype.Component;

@Component
public class MultipartJackson2HttpMessageConverter extends AbstractJackson2HttpMessageConverter {

public MultipartJackson2HttpMessageConverter(ObjectMapper objectMapper) {
super(objectMapper, MediaType.APPLICATION_OCTET_STREAM);
}

@Override
public boolean canWrite(Class<?> clazz, MediaType mediaType) {
return false;
}

@Override
public boolean canWrite(Type type, Class<?> clazz, MediaType mediaType) {
return false;
}

@Override
protected boolean canWrite(MediaType mediaType) {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@Getter
@RequiredArgsConstructor
public enum ErrorMessage {
AUTHENTICATION_ERROR("알 수 없는 인증 관련 오류가 발생하였습니다."),
INTERNAL_SERVER_ERROR("서버에 문제가 발생했습니다."),
ILLEGAL_CLUB_LOCATION_PATTERN("올바르지 않은 동아리 위치 양식입니다."),
ILLEGAL_CLUB_PHONE_NUMBER_PATTERN("올바르지 않은 동아리 전화번호 양식입니다."),
Expand All @@ -21,9 +22,10 @@ public enum ErrorMessage {
INVALID_STAMP_COUNT_FOR_APPLY("스탬프를 모두 모아야 이벤트에 참여할 수 있어요!"),
ACCESS_DENIED("접근권한이 없습니다."),
UNREGISTER_ID("등록되지 않은 ID입니다."),
NO_SUCH_BANNER("해당 배너가 존재하지 않습니다."),
NON_VALIDATED_TOKEN("유효하지 않은 토큰입니다."),
NO_SUCH_BANNER("해당 배너가 존재하지 않습니다."),
NO_SUCH_FIX("해당 수리 신청서가 존재하지 않습니다."),
NO_SUCH_FIX_ZONE_COMMENT("존재하지 않는 픽스존 댓글입니다."),
NO_SUCH_DOCUMENT("해당 자료가 존재하지 않습니다.");

private final String text;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ddingdong.ddingdongBE.domain.activityreport.api;

import ddingdong.ddingdongBE.auth.PrincipalDetails;
import ddingdong.ddingdongBE.domain.activityreport.controller.dto.request.CreateActivityTermInfoRequest;
import ddingdong.ddingdongBE.domain.activityreport.controller.dto.response.ActivityReportTermInfoResponse;
import ddingdong.ddingdongBE.domain.activityreport.controller.dto.response.AllActivityReportResponse;
Expand All @@ -9,7 +8,6 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -29,16 +27,12 @@ public interface AdminActivityReportApi {
@GetMapping("/term")
@ResponseStatus(HttpStatus.OK)
@SecurityRequirement(name = "AccessToken")
List<ActivityReportTermInfoResponse> getActivityTermInfos(
@AuthenticationPrincipal PrincipalDetails principalDetails);
List<ActivityReportTermInfoResponse> getActivityTermInfos();

@Operation(summary = "활동 보고서 회차별 기간 설정 API")
@PostMapping("/term")
@ResponseStatus(HttpStatus.CREATED)
@SecurityRequirement(name = "AccessToken")
void createActivityTermInfo(
@AuthenticationPrincipal PrincipalDetails principalDetails,
@RequestBody CreateActivityTermInfoRequest request
);
void createActivityTermInfo(@RequestBody CreateActivityTermInfoRequest request);

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ddingdong.ddingdongBE.domain.activityreport.controller;

import ddingdong.ddingdongBE.auth.PrincipalDetails;
import ddingdong.ddingdongBE.domain.activityreport.api.AdminActivityReportApi;
import ddingdong.ddingdongBE.domain.activityreport.controller.dto.request.CreateActivityTermInfoRequest;
import ddingdong.ddingdongBE.domain.activityreport.controller.dto.response.ActivityReportTermInfoResponse;
Expand All @@ -9,7 +8,6 @@
import ddingdong.ddingdongBE.domain.activityreport.service.ActivityReportTermInfoService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -26,16 +24,12 @@ public List<AllActivityReportResponse> getActivityReports() {
}

@Override
public List<ActivityReportTermInfoResponse> getActivityTermInfos(
@AuthenticationPrincipal PrincipalDetails principalDetails) {
public List<ActivityReportTermInfoResponse> getActivityTermInfos() {
return activityReportTermInfoService.getAll();
}

@Override
public void createActivityTermInfo(
@AuthenticationPrincipal PrincipalDetails principalDetails,
CreateActivityTermInfoRequest request
) {
public void createActivityTermInfo(CreateActivityTermInfoRequest request) {
activityReportTermInfoService.create(request.startDate(), request.totalTermCount());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public CurrentTermResponse(String term) {
this.term = term;
}

public static CurrentTermResponse of(String term) {
public static CurrentTermResponse from(String term) {
return new CurrentTermResponse(term);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package ddingdong.ddingdongBE.domain.activityreport.controller.dto.response;

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

import com.fasterxml.jackson.annotation.JsonFormat;

import ddingdong.ddingdongBE.domain.activityreport.domain.ActivityReport;
import ddingdong.ddingdongBE.domain.activityreport.domain.Participant;
import java.time.LocalDateTime;
import java.util.List;
import lombok.Getter;

@Getter
Expand Down Expand Up @@ -38,7 +36,7 @@ public DetailActivityReportResponse(Long id, String name, String content, String
this.createdAt = createdAt;
}

public static DetailActivityReportResponse from(ActivityReport activityReport, List<String> imageUrls) {
public static DetailActivityReportResponse of(ActivityReport activityReport, List<String> imageUrls) {
return new DetailActivityReportResponse(
activityReport.getId(),
activityReport.getClub().getName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public List<DetailActivityReportResponse> getActivityReport(final String term,
return activityReports.stream().map(activityReport -> {
List<String> imageUrls = fileInformationService.getImageUrls(
IMAGE.getFileType() + ACTIVITY_REPORT.getFileDomain() + activityReport.getId());
return DetailActivityReportResponse.from(activityReport, imageUrls);
return DetailActivityReportResponse.of(activityReport, imageUrls);
}).collect(Collectors.toList());
}

Expand Down Expand Up @@ -112,7 +112,7 @@ public CurrentTermResponse getCurrentTerm() {
LocalDate currentDate = LocalDate.now();

int gapOfDays = calculateGapOfDays(startDate, currentDate);
return CurrentTermResponse.of(calculateCurrentTerm(gapOfDays));
return CurrentTermResponse.from(calculateCurrentTerm(gapOfDays));
}

private int calculateGapOfDays(final LocalDate startDate, final LocalDate currentDate) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package ddingdong.ddingdongBE.domain.club.service;

import static ddingdong.ddingdongBE.common.exception.ErrorMessage.*;
import static ddingdong.ddingdongBE.domain.club.entity.RecruitmentStatus.*;
import static ddingdong.ddingdongBE.common.exception.ErrorMessage.NO_SUCH_CLUB;
import static ddingdong.ddingdongBE.domain.club.entity.RecruitmentStatus.BEFORE_RECRUIT;
import static ddingdong.ddingdongBE.domain.club.entity.RecruitmentStatus.END_RECRUIT;
import static ddingdong.ddingdongBE.domain.club.entity.RecruitmentStatus.RECRUITING;
import static ddingdong.ddingdongBE.domain.fileinformation.entity.FileDomainCategory.CLUB_INTRODUCE;
import static ddingdong.ddingdongBE.domain.fileinformation.entity.FileDomainCategory.CLUB_PROFILE;
import static ddingdong.ddingdongBE.domain.fileinformation.entity.FileTypeCategory.IMAGE;
Expand All @@ -15,16 +17,17 @@
import ddingdong.ddingdongBE.domain.club.controller.dto.response.DetailClubResponse;
import ddingdong.ddingdongBE.domain.club.entity.Club;
import ddingdong.ddingdongBE.domain.club.entity.RecruitmentStatus;
import ddingdong.ddingdongBE.domain.scorehistory.entity.Score;
import ddingdong.ddingdongBE.domain.club.repository.ClubRepository;
import ddingdong.ddingdongBE.domain.fileinformation.entity.FileInformation;
import ddingdong.ddingdongBE.domain.fileinformation.repository.FileInformationRepository;
import ddingdong.ddingdongBE.domain.fileinformation.service.FileInformationService;
import ddingdong.ddingdongBE.domain.scorehistory.entity.Score;
import ddingdong.ddingdongBE.domain.user.entity.User;
import ddingdong.ddingdongBE.file.FileStore;
import java.time.LocalDateTime;
import java.util.List;
import java.util.NoSuchElementException;
import ddingdong.ddingdongBE.file.FileStore;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -66,7 +69,7 @@ public List<AdminClubResponse> getAllForAdmin() {

@Transactional(readOnly = true)
public DetailClubResponse getClub(Long clubId) {
Club club = findClubByClubId(clubId);
Club club = getByClubId(clubId);

List<String> profileImageUrl = fileInformationService.getImageUrls(
IMAGE.getFileType() + CLUB_PROFILE.getFileDomain() + clubId);
Expand All @@ -83,7 +86,7 @@ public DetailClubResponse getClub(Long clubId) {

@Transactional(readOnly = true)
public DetailClubResponse getMyClub(Long userId) {
Club club = findClubByUserId(userId);
Club club = getByUserId(userId);

List<String> profileImageUrl = fileInformationService.getImageUrls(
IMAGE.getFileType() + CLUB_PROFILE.getFileDomain() + club.getId());
Expand All @@ -99,32 +102,36 @@ public DetailClubResponse getMyClub(Long userId) {
}

public void delete(Long clubId) {
Club club = findClubByClubId(clubId);
Club club = getByClubId(clubId);

clubRepository.delete(club);
}

public float editClubScore(Long clubId, float score) {
Club club = findClubByClubId(clubId);
Club club = getByClubId(clubId);

return club.editScore(generateNewScore(club.getScore(), score));
}

public Long update(Long userId, UpdateClubRequest request) {
Club club = findClubByUserId(userId);
Club club = getByUserId(userId);
updateIntroduceImageInformation(request, club);
updateProfileImageInformation(request, club);

club.updateClubInfo(request);
return club.getId();
}

public Club findClubByUserId(final Long userId) {
public Optional<Club> findByUserId(final Long userId) {
return clubRepository.findByUserId(userId);
}

public Club getByUserId(final Long userId) {
return clubRepository.findByUserId(userId)
.orElseThrow(() -> new NoSuchElementException(NO_SUCH_CLUB.getText()));
}

public Club findClubByClubId(final Long clubId) {
public Club getByClubId(final Long clubId) {
return clubRepository.findById(clubId)
.orElseThrow(() -> new NoSuchElementException(NO_SUCH_CLUB.getText()));
}
Expand Down Expand Up @@ -175,4 +182,5 @@ private RecruitmentStatus checkRecruit(LocalDateTime now, Club club) {

return club.getEndRecruitPeriod().isAfter(now) ? RECRUITING : END_RECRUIT;
}

}
Original file line number Diff line number Diff line change
@@ -1,41 +1,69 @@
package ddingdong.ddingdongBE.domain.fixzone.controller;

import java.util.List;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import ddingdong.ddingdongBE.domain.fixzone.controller.dto.request.UpdateFiXCompletionRequest;
import ddingdong.ddingdongBE.domain.fixzone.controller.dto.request.UpdateFixRequest;
import ddingdong.ddingdongBE.domain.fixzone.controller.dto.response.AdminDetailFixResponse;
import ddingdong.ddingdongBE.domain.fixzone.controller.dto.response.AdminFixResponse;
import ddingdong.ddingdongBE.auth.PrincipalDetails;
import ddingdong.ddingdongBE.domain.club.entity.Club;
import ddingdong.ddingdongBE.domain.club.service.ClubService;
import ddingdong.ddingdongBE.domain.fixzone.controller.api.AdminFixZoneApi;
import ddingdong.ddingdongBE.domain.fixzone.controller.dto.request.CreateFixZoneCommentRequest;
import ddingdong.ddingdongBE.domain.fixzone.controller.dto.response.GetFixZoneResponse;
import ddingdong.ddingdongBE.domain.fixzone.entity.FixZone;
import ddingdong.ddingdongBE.domain.fixzone.service.FixZoneCommentService;
import ddingdong.ddingdongBE.domain.fixzone.service.FixZoneService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/server/admin/fix")
@RequiredArgsConstructor
public class AdminFixZoneController {
public class AdminFixZoneController implements AdminFixZoneApi {

private final FixZoneService fixZoneService;
private final FixZoneCommentService fixZoneCommentService;
private final ClubService clubService;

@Override
public List<GetFixZoneResponse> getFixZones() {
return fixZoneService.getAll();
}

@Override
public void updateFixZoneToComplete(Long fixZoneId) {
fixZoneService.updateToComplete(fixZoneId);
}

@Override
public void createFixZoneComment(
PrincipalDetails principalDetails,
CreateFixZoneCommentRequest request,
Long fixZoneId
) {
FixZone fixZone = fixZoneService.getById(fixZoneId);
Club club = clubService.getByClubId(principalDetails.getUser().getId());

fixZoneCommentService.create(fixZone, club, request);
}

@Override
public void updateFixZoneComment(
PrincipalDetails principalDetails,
CreateFixZoneCommentRequest request,
Long fixZoneId,
Long commentId
) {
Club club = clubService.getByClubId(principalDetails.getUser().getId());

fixZoneCommentService.update(club.getId(), commentId, request);
}

@GetMapping
public List<AdminFixResponse> getAllFixForAdmin() {
return fixZoneService.getAllForAdmin();
}
@Override
public void deleteFixZoneComment(
PrincipalDetails principalDetails,
Long fixZoneId,
Long commentId
) {
Club club = clubService.getByClubId(principalDetails.getUser().getId());

@GetMapping("/{fixId}")
public AdminDetailFixResponse getFixForAdmin(@PathVariable Long fixId) {
return fixZoneService.getForAdmin(fixId);
}
fixZoneCommentService.delete(commentId);
}

@PatchMapping("/{fixId}")
public void updateFix(@PathVariable Long fixId, @RequestBody UpdateFiXCompletionRequest request) {
fixZoneService.updateIsCompleted(fixId, request);
}
}
Loading

0 comments on commit 4c44f5b

Please sign in to comment.