Skip to content

Commit

Permalink
[DDING-32] FixZone 도메인 리팩토링 및 presignedUrl 적용 (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
5uhwann authored Oct 25, 2024
1 parent ea7fa58 commit cda9c6b
Show file tree
Hide file tree
Showing 42 changed files with 1,440 additions and 452 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;
import java.util.List;
import java.util.Objects;

@Converter
public class StringListConverter implements AttributeConverter<List<String>, String> {
Expand All @@ -16,7 +17,7 @@ public class StringListConverter implements AttributeConverter<List<String>, Str
@Override
public String convertToDatabaseColumn(List<String> dataList) {
try {
return mapper.writeValueAsString(dataList);
return mapper.writeValueAsString(Objects.requireNonNullElseGet(dataList, List::of));
} catch (JsonProcessingException e) {
throw new ListToStringConvertException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public void updateClubInfo(Club club) {
this.activity = club.getActivity();
this.ideal = club.getIdeal();
this.formUrl = club.getFormUrl();
this.profileImageKey = club.getProfileImageKey();
this.introductionImageKey = club.getIntroductionImageKey();
}

public BigDecimal editScore(Score score) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package ddingdong.ddingdongBE.domain.fixzone.controller;

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 ddingdong.ddingdongBE.domain.fixzone.controller.dto.request.UpdateFixZoneCommentRequest;
import ddingdong.ddingdongBE.domain.fixzone.controller.dto.response.AdminFixZoneListResponse;
import ddingdong.ddingdongBE.domain.fixzone.controller.dto.response.AdminFixZoneResponse;
import ddingdong.ddingdongBE.domain.fixzone.service.FacadeAdminFixZoneCommentService;
import ddingdong.ddingdongBE.domain.fixzone.service.FacadeAdminFixZoneService;
import ddingdong.ddingdongBE.domain.fixzone.service.dto.query.AdminFixZoneQuery;
import ddingdong.ddingdongBE.domain.user.entity.User;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -17,51 +18,45 @@
@RequiredArgsConstructor
public class AdminFixZoneController implements AdminFixZoneApi {

private final FixZoneService fixZoneService;
private final FixZoneCommentService fixZoneCommentService;
private final ClubService clubService;
private final FacadeAdminFixZoneService facadeAdminFixZoneService;
private final FacadeAdminFixZoneCommentService facadeAdminFixZoneCommentService;

@Override
public List<GetFixZoneResponse> getFixZones() {
return fixZoneService.getAll();
public List<AdminFixZoneListResponse> getFixZones() {
return facadeAdminFixZoneService.getAll().stream()
.map(AdminFixZoneListResponse::from)
.toList();
}

@Override
public AdminFixZoneResponse getFixZoneDetail(Long fixZoneId) {
AdminFixZoneQuery query = facadeAdminFixZoneService.getFixZone(fixZoneId);
return AdminFixZoneResponse.from(query);
}

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

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

fixZoneCommentService.create(fixZone, club, request);
User admin = principalDetails.getUser();
facadeAdminFixZoneCommentService.create(request.toCommand(admin.getId(), fixZoneId));
}

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

fixZoneCommentService.update(club.getId(), commentId, request);
public void updateFixZoneComment(UpdateFixZoneCommentRequest request, Long fixZoneId, Long commentId) {
facadeAdminFixZoneCommentService.update(request.toCommand(commentId));
}

@Override
public void deleteFixZoneComment(
PrincipalDetails principalDetails,
Long fixZoneId,
Long commentId
) {
fixZoneCommentService.delete(commentId);
public void deleteFixZoneComment(Long fixZoneId, Long commentId) {
facadeAdminFixZoneCommentService.delete(commentId);
}

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

import static ddingdong.ddingdongBE.domain.fileinformation.entity.FileDomainCategory.FIX_ZONE;
import static ddingdong.ddingdongBE.domain.fileinformation.entity.FileTypeCategory.IMAGE;

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.ClubFixZoneApi;
import ddingdong.ddingdongBE.domain.fixzone.controller.dto.request.CreateFixZoneRequest;
import ddingdong.ddingdongBE.domain.fixzone.controller.dto.request.UpdateFixZoneRequest;
import ddingdong.ddingdongBE.domain.fixzone.controller.dto.response.GetDetailFixZoneResponse;
import ddingdong.ddingdongBE.domain.fixzone.controller.dto.response.GetFixZoneResponse;
import ddingdong.ddingdongBE.domain.fixzone.service.FixZoneService;
import ddingdong.ddingdongBE.file.service.FileService;
import ddingdong.ddingdongBE.domain.fixzone.controller.dto.response.CentralFixZoneResponse;
import ddingdong.ddingdongBE.domain.fixzone.controller.dto.response.CentralMyFixZoneListResponse;
import ddingdong.ddingdongBE.domain.fixzone.service.FacadeCentralFixZoneServiceImpl;
import ddingdong.ddingdongBE.domain.fixzone.service.dto.query.CentralFixZoneQuery;
import ddingdong.ddingdongBE.domain.user.entity.User;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequiredArgsConstructor
public class ClubFixZoneController implements ClubFixZoneApi {
private final ClubService clubService;
private final FixZoneService fixZoneService;
private final FileService fileService;

@Override
public List<GetFixZoneResponse> getMyFixZones(PrincipalDetails principalDetails) {
Club club = clubService.getByUserId(principalDetails.getUser().getId());
private final FacadeCentralFixZoneServiceImpl facadeCentralFixZoneServiceImpl;

return fixZoneService.getMyFixZones(club.getId());
@Override
public List<CentralMyFixZoneListResponse> getMyFixZones(PrincipalDetails principalDetails) {
User user = principalDetails.getUser();
return facadeCentralFixZoneServiceImpl.getMyFixZones(user.getId()).stream()
.map(CentralMyFixZoneListResponse::from)
.toList();
}

@Override
public GetDetailFixZoneResponse getFixZoneDetail(Long fixZoneId) {
return fixZoneService.getFixZoneDetail(fixZoneId);
public CentralFixZoneResponse getFixZoneDetail(Long id) {
CentralFixZoneQuery query = facadeCentralFixZoneServiceImpl.getFixZone(id);
return CentralFixZoneResponse.from(query);
}

@Override
public void createFixZone(
PrincipalDetails principalDetails,
CreateFixZoneRequest request,
List<MultipartFile> images
) {
Club club = clubService.getByUserId(principalDetails.getUser().getId());
Long createdFixZoneId = fixZoneService.create(club, request);

fileService.uploadFile(createdFixZoneId, images, IMAGE, FIX_ZONE);
public void createFixZone(PrincipalDetails principalDetails, CreateFixZoneRequest request) {
User user = principalDetails.getUser();
facadeCentralFixZoneServiceImpl.create(request.toCommand(user.getId()));
}

@Override
public void updateFixZone(
PrincipalDetails principalDetails,
Long fixZoneId,
UpdateFixZoneRequest request,
List<MultipartFile> images
) {
clubService.getByUserId(principalDetails.getUser().getId());
public void updateFixZone(Long fixZoneId, UpdateFixZoneRequest request) {
facadeCentralFixZoneServiceImpl.update(request.toCommand(fixZoneId));

fixZoneService.update(fixZoneId, request);

fileService.deleteFile(fixZoneId, IMAGE, FIX_ZONE);
fileService.uploadFile(fixZoneId, images, IMAGE, FIX_ZONE);
}

@Override
public void deleteFixZone(
PrincipalDetails principalDetails,
Long fixZoneId
) {
clubService.getByUserId(principalDetails.getUser().getId());

fixZoneService.delete(fixZoneId);

fileService.deleteFile(fixZoneId, IMAGE, FIX_ZONE);
public void deleteFixZone(Long fixZoneId) {
facadeCentralFixZoneServiceImpl.delete(fixZoneId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

import ddingdong.ddingdongBE.auth.PrincipalDetails;
import ddingdong.ddingdongBE.domain.fixzone.controller.dto.request.CreateFixZoneCommentRequest;
import ddingdong.ddingdongBE.domain.fixzone.controller.dto.response.GetFixZoneResponse;
import ddingdong.ddingdongBE.domain.fixzone.controller.dto.request.UpdateFixZoneCommentRequest;
import ddingdong.ddingdongBE.domain.fixzone.controller.dto.response.AdminFixZoneListResponse;
import ddingdong.ddingdongBE.domain.fixzone.controller.dto.response.AdminFixZoneResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -28,7 +30,13 @@ public interface AdminFixZoneApi {
@GetMapping
@ResponseStatus(HttpStatus.OK)
@SecurityRequirement(name = "AccessToken")
List<GetFixZoneResponse> getFixZones();
List<AdminFixZoneListResponse> getFixZones();

@Operation(summary = "Fix Zone 상세 조회")
@GetMapping("/{fixZoneId}")
@ResponseStatus(HttpStatus.OK)
@SecurityRequirement(name = "AccessToken")
AdminFixZoneResponse getFixZoneDetail(@PathVariable("fixZoneId") Long fixZoneId);

@Operation(summary = "Fix Zone 요청 처리 완료 API")
@PatchMapping("/{fixZoneId}")
Expand All @@ -51,8 +59,7 @@ void createFixZoneComment(
@ResponseStatus(HttpStatus.NO_CONTENT)
@SecurityRequirement(name = "AccessToken")
void updateFixZoneComment(
@AuthenticationPrincipal PrincipalDetails principalDetails,
@RequestBody CreateFixZoneCommentRequest request,
@RequestBody UpdateFixZoneCommentRequest request,
@PathVariable("fixZoneId") Long fixZoneId,
@PathVariable("commentId") Long commentId
);
Expand All @@ -62,7 +69,6 @@ void updateFixZoneComment(
@ResponseStatus(HttpStatus.NO_CONTENT)
@SecurityRequirement(name = "AccessToken")
void deleteFixZoneComment(
@AuthenticationPrincipal PrincipalDetails principalDetails,
@PathVariable("fixZoneId") Long fixZoneId,
@PathVariable("commentId") Long commentId
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,70 +5,61 @@
import ddingdong.ddingdongBE.auth.PrincipalDetails;
import ddingdong.ddingdongBE.domain.fixzone.controller.dto.request.CreateFixZoneRequest;
import ddingdong.ddingdongBE.domain.fixzone.controller.dto.request.UpdateFixZoneRequest;
import ddingdong.ddingdongBE.domain.fixzone.controller.dto.response.GetDetailFixZoneResponse;
import ddingdong.ddingdongBE.domain.fixzone.controller.dto.response.GetFixZoneResponse;
import ddingdong.ddingdongBE.domain.fixzone.controller.dto.response.CentralFixZoneResponse;
import ddingdong.ddingdongBE.domain.fixzone.controller.dto.response.CentralMyFixZoneListResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.DeleteMapping;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.multipart.MultipartFile;

@Tag(name = "Fix Zone - Club", description = "Fix Zone Club API")
@RequestMapping(value = "/server/club/fix-zones", produces = APPLICATION_JSON_VALUE)
@RequestMapping(value = "/server/central/fix-zones", produces = APPLICATION_JSON_VALUE)
public interface ClubFixZoneApi {

@Operation(summary = "클럽별 등록한 Fix Zone 조회")
@GetMapping
@ResponseStatus(HttpStatus.OK)
@SecurityRequirement(name = "AccessToken")
List<GetFixZoneResponse> getMyFixZones(@AuthenticationPrincipal PrincipalDetails principalDetails);
List<CentralMyFixZoneListResponse> getMyFixZones(@AuthenticationPrincipal PrincipalDetails principalDetails);

@Operation(summary = "Fix Zone 상세 조회")
@GetMapping("/{fixZoneId}")
@ResponseStatus(HttpStatus.OK)
@SecurityRequirement(name = "AccessToken")
GetDetailFixZoneResponse getFixZoneDetail(@PathVariable("fixZoneId") Long fixZoneId);
CentralFixZoneResponse getFixZoneDetail(@PathVariable("fixZoneId") Long fixZoneId);

@Operation(summary = "Fix Zone 등록 API")
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = APPLICATION_JSON_VALUE)
@PostMapping()
@ResponseStatus(HttpStatus.CREATED)
@SecurityRequirement(name = "AccessToken")
void createFixZone(
@AuthenticationPrincipal PrincipalDetails principalDetails,
@ModelAttribute CreateFixZoneRequest request,
@RequestPart(name = "images", required = false) List<MultipartFile> images
);
void createFixZone(@AuthenticationPrincipal PrincipalDetails principalDetails,
@RequestBody CreateFixZoneRequest request);

@Operation(summary = "Fix Zone 수정 API")
@PatchMapping(value = "/{fixZoneId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = APPLICATION_JSON_VALUE)
@PatchMapping(value = "/{fixZoneId}")
@ResponseStatus(HttpStatus.NO_CONTENT)
@SecurityRequirement(name = "AccessToken")
void updateFixZone(
@AuthenticationPrincipal PrincipalDetails principalDetails,
@PathVariable("fixZoneId") Long fixZoneId,
@ModelAttribute UpdateFixZoneRequest request,
@RequestPart(name = "images", required = false) List<MultipartFile> images
@PathVariable("fixZoneId") Long fixZoneId,
@RequestBody UpdateFixZoneRequest request
);

@Operation(summary = "Fix Zone 삭제 API")
@DeleteMapping("/{fixZoneId}")
@ResponseStatus(HttpStatus.NO_CONTENT)
@SecurityRequirement(name = "AccessToken")
void deleteFixZone(
@AuthenticationPrincipal PrincipalDetails principalDetails,
@PathVariable("fixZoneId") Long fixZoneId
@PathVariable("fixZoneId") Long fixZoneId
);

}
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
package ddingdong.ddingdongBE.domain.fixzone.controller.dto.request;

import ddingdong.ddingdongBE.domain.club.entity.Club;
import ddingdong.ddingdongBE.domain.fixzone.entity.FixZone;
import ddingdong.ddingdongBE.domain.fixzone.entity.FixZoneComment;
import ddingdong.ddingdongBE.domain.fixzone.service.dto.command.CreateFixZoneCommentCommand;
import io.swagger.v3.oas.annotations.media.Schema;

@Schema(name = "CreateFixZoneCommentRequest", description = "Admin - 픽스존 댓글 등록 요청")
public record CreateFixZoneCommentRequest(
@Schema(description = "댓글 내용")
String content
@Schema(description = "댓글 내용")
String content
) {

public FixZoneComment toEntity(FixZone fixZone, Club club) {
return FixZoneComment.builder()
.fixZone(fixZone)
.club(club)
.content(content)
.build();
public CreateFixZoneCommentCommand toCommand(Long userId, Long fixZoneId) {
return new CreateFixZoneCommentCommand(userId, fixZoneId, content);
}

}

Loading

0 comments on commit cda9c6b

Please sign in to comment.