diff --git a/src/main/java/com/mtvs/devlinkbackend/ether/controller/EtherController.java b/src/main/java/com/mtvs/devlinkbackend/ether/controller/EtherCommandController.java similarity index 52% rename from src/main/java/com/mtvs/devlinkbackend/ether/controller/EtherController.java rename to src/main/java/com/mtvs/devlinkbackend/ether/controller/EtherCommandController.java index 5867567..0f03ce5 100644 --- a/src/main/java/com/mtvs/devlinkbackend/ether/controller/EtherController.java +++ b/src/main/java/com/mtvs/devlinkbackend/ether/controller/EtherCommandController.java @@ -1,6 +1,5 @@ package com.mtvs.devlinkbackend.ether.controller; -import com.mtvs.devlinkbackend.ether.dto.response.EtherListResponseDTO; import com.mtvs.devlinkbackend.ether.dto.response.EtherSingleResponseDTO; import com.mtvs.devlinkbackend.common.util.JwtUtil; import com.mtvs.devlinkbackend.ether.dto.request.EtherRegistRequestDTO; @@ -14,11 +13,11 @@ @RestController @RequestMapping("/api/ether") -public class EtherController { +public class EtherCommandController { private final EtherService etherService; private final JwtUtil jwtUtil; - public EtherController(EtherService etherService, JwtUtil jwtUtil) { + public EtherCommandController(EtherService etherService, JwtUtil jwtUtil) { this.etherService = etherService; this.jwtUtil = jwtUtil; } @@ -31,51 +30,12 @@ public EtherController(EtherService etherService, JwtUtil jwtUtil) { }) @PostMapping public ResponseEntity registEther( - @RequestBody EtherRegistRequestDTO etherRegistRequestDTO, - @RequestHeader(name = "Authorization") String authorizationHeader) throws Exception { + @RequestBody EtherRegistRequestDTO etherRegistRequestDTO) { - String accountId = jwtUtil.getSubjectFromAuthHeaderWithoutAuth(authorizationHeader); - EtherSingleResponseDTO newEther = etherService.registEther(etherRegistRequestDTO, accountId); + EtherSingleResponseDTO newEther = etherService.registEther(etherRegistRequestDTO); return ResponseEntity.ok(newEther); } - @Operation(summary = "Ether ID로 Ether 조회", description = "Ether ID를 사용하여 Ether를 조회합니다.") - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Ether를 성공적으로 찾음"), - @ApiResponse(responseCode = "401", description = "인증되지 않음"), - @ApiResponse(responseCode = "404", description = "Ether를 찾을 수 없음") - }) - @GetMapping("/{etherId}") - public ResponseEntity findEtherByEtherId(@PathVariable Long etherId) { - EtherSingleResponseDTO ether = etherService.findEtherByEtherId(etherId); - return ether != null ? ResponseEntity.ok(ether) : ResponseEntity.notFound().build(); - } - - @Operation(summary = "계정 ID로 Ether 목록 조회", description = "계정 ID를 사용하여 관련된 모든 Ether를 조회합니다.") - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Ether 목록을 성공적으로 찾음"), - @ApiResponse(responseCode = "401", description = "인증되지 않음") - }) - @GetMapping("/account") - public ResponseEntity findEthersByAccountId( - @RequestHeader(name = "Authorization") String authorizationHeader) throws Exception { - - String accountId = jwtUtil.getSubjectFromAuthHeaderWithoutAuth(authorizationHeader); - EtherListResponseDTO ethers = etherService.findEthersByAccountId(accountId); - return ResponseEntity.ok(ethers); - } - - @Operation(summary = "이유로 Ether 목록 조회", description = "지정된 이유로 관련된 모든 Ether를 조회합니다.") - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Ether 목록을 성공적으로 찾음"), - @ApiResponse(responseCode = "401", description = "인증되지 않음") - }) - @GetMapping("/reason/{reason}") - public ResponseEntity findEthersByReason(@PathVariable String reason) { - EtherListResponseDTO ethers = etherService.findEthersByReason(reason); - return ResponseEntity.ok(ethers); - } - @Operation(summary = "Ether 수정", description = "제공된 데이터를 기반으로 특정 Ether를 수정합니다.") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Ether가 성공적으로 수정됨"), @@ -83,7 +43,8 @@ public ResponseEntity findEthersByReason(@PathVariable Str @ApiResponse(responseCode = "401", description = "인증되지 않음") }) @PatchMapping - public ResponseEntity updateEther(@RequestBody EtherUpdateRequestDTO etherUpdateRequestDTO) { + public ResponseEntity updateEther( + @RequestBody EtherUpdateRequestDTO etherUpdateRequestDTO) { try { EtherSingleResponseDTO updatedEther = etherService.updateEther(etherUpdateRequestDTO); return ResponseEntity.ok(updatedEther); diff --git a/src/main/java/com/mtvs/devlinkbackend/ether/controller/EtherQueryController.java b/src/main/java/com/mtvs/devlinkbackend/ether/controller/EtherQueryController.java new file mode 100644 index 0000000..955b4ac --- /dev/null +++ b/src/main/java/com/mtvs/devlinkbackend/ether/controller/EtherQueryController.java @@ -0,0 +1,63 @@ +package com.mtvs.devlinkbackend.ether.controller; + +import com.mtvs.devlinkbackend.common.util.JwtUtil; +import com.mtvs.devlinkbackend.ether.dto.response.EtherPagingResponseDTO; +import com.mtvs.devlinkbackend.ether.dto.response.EtherSingleResponseDTO; +import com.mtvs.devlinkbackend.ether.dto.response.UserEtherAmountResponseDTO; +import com.mtvs.devlinkbackend.ether.service.EtherViewService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/api/ether") +public class EtherQueryController { + + private final EtherViewService etherViewService; + private final JwtUtil jwtUtil; + + public EtherQueryController(EtherViewService etherViewService, JwtUtil jwtUtil) { + this.etherViewService = etherViewService; + this.jwtUtil = jwtUtil; + } + + @Operation(summary = "Ether ID로 Ether 조회", description = "Ether ID를 사용하여 Ether를 조회합니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Ether를 성공적으로 찾음"), + @ApiResponse(responseCode = "401", description = "인증되지 않음"), + @ApiResponse(responseCode = "404", description = "Ether를 찾을 수 없음") + }) + @GetMapping("/{etherId}") + public ResponseEntity findEtherByEtherId(@PathVariable Long etherId) { + EtherSingleResponseDTO ether = etherViewService.findEtherByEtherId(etherId); + return ether != null ? ResponseEntity.ok(ether) : ResponseEntity.notFound().build(); + } + + @Operation(summary = "계정 ID로 Ether 목록 조회", description = "계정 ID를 사용하여 관련된 모든 Ether를 15개씩 조회합니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Ether 목록을 성공적으로 찾음"), + @ApiResponse(responseCode = "401", description = "인증되지 않음") + }) + @GetMapping("/list/{page}") + public ResponseEntity findEthersByAccountId( + @RequestHeader(name = "Authorization") String authorizationHeader, + @PathVariable Integer page) throws Exception { + + String accountId = jwtUtil.getSubjectFromAuthHeaderWithoutAuth(authorizationHeader); + EtherPagingResponseDTO ethers = etherViewService.findEthersByAccountIdWithPagination(accountId, page); + return ResponseEntity.ok(ethers); + } + + @Operation(summary = "사용자의 총 Ether 양 조회", description = "사용자의 총 Ether 양을 조회합니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Ether 목록을 성공적으로 찾음"), + @ApiResponse(responseCode = "401", description = "인증되지 않음") + }) + @GetMapping("/history/{userId}") + public ResponseEntity findTotalEtherAmountByUserId(@PathVariable Long userId) { + UserEtherAmountResponseDTO ethers = etherViewService.findTotalEtherAmountByUserId(userId); + return ResponseEntity.ok(ethers); + } +} diff --git a/src/main/java/com/mtvs/devlinkbackend/ether/dto/request/EtherRegistRequestDTO.java b/src/main/java/com/mtvs/devlinkbackend/ether/dto/request/EtherRegistRequestDTO.java index b0a5394..0740f0b 100644 --- a/src/main/java/com/mtvs/devlinkbackend/ether/dto/request/EtherRegistRequestDTO.java +++ b/src/main/java/com/mtvs/devlinkbackend/ether/dto/request/EtherRegistRequestDTO.java @@ -7,6 +7,8 @@ @AllArgsConstructor @ToString public class EtherRegistRequestDTO { - private Long amount; - private String reason; + private Long userId; + private Integer goldAmount; + private Integer silverAmount; + private String cause; } diff --git a/src/main/java/com/mtvs/devlinkbackend/ether/dto/request/EtherUpdateRequestDTO.java b/src/main/java/com/mtvs/devlinkbackend/ether/dto/request/EtherUpdateRequestDTO.java index b6005d6..7a7c27f 100644 --- a/src/main/java/com/mtvs/devlinkbackend/ether/dto/request/EtherUpdateRequestDTO.java +++ b/src/main/java/com/mtvs/devlinkbackend/ether/dto/request/EtherUpdateRequestDTO.java @@ -9,6 +9,9 @@ @ToString public class EtherUpdateRequestDTO { private Long etherId; - private Long amount; - private String reason; + private Long userId; + private Integer goldAmount; + private Integer + silverAmount; + private String cause; } diff --git a/src/main/java/com/mtvs/devlinkbackend/ether/dto/response/EtherListResponseDTO.java b/src/main/java/com/mtvs/devlinkbackend/ether/dto/response/EtherPagingResponseDTO.java similarity index 70% rename from src/main/java/com/mtvs/devlinkbackend/ether/dto/response/EtherListResponseDTO.java rename to src/main/java/com/mtvs/devlinkbackend/ether/dto/response/EtherPagingResponseDTO.java index 7e54eb2..8270296 100644 --- a/src/main/java/com/mtvs/devlinkbackend/ether/dto/response/EtherListResponseDTO.java +++ b/src/main/java/com/mtvs/devlinkbackend/ether/dto/response/EtherPagingResponseDTO.java @@ -9,6 +9,8 @@ @NoArgsConstructor @AllArgsConstructor @ToString -public class EtherListResponseDTO { +public class EtherPagingResponseDTO { private List data; + private Integer totalPages; + private Long totalEtherCnt; } diff --git a/src/main/java/com/mtvs/devlinkbackend/ether/dto/response/UserEtherAmountResponseDTO.java b/src/main/java/com/mtvs/devlinkbackend/ether/dto/response/UserEtherAmountResponseDTO.java new file mode 100644 index 0000000..442af17 --- /dev/null +++ b/src/main/java/com/mtvs/devlinkbackend/ether/dto/response/UserEtherAmountResponseDTO.java @@ -0,0 +1,13 @@ +package com.mtvs.devlinkbackend.ether.dto.response; + +import com.mtvs.devlinkbackend.ether.dto.response.sub.UserIdAndAmountDTO; +import lombok.*; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString +public class UserEtherAmountResponseDTO { + private UserIdAndAmountDTO data; +} diff --git a/src/main/java/com/mtvs/devlinkbackend/ether/dto/response/sub/UserIdAndAmountDTO.java b/src/main/java/com/mtvs/devlinkbackend/ether/dto/response/sub/UserIdAndAmountDTO.java new file mode 100644 index 0000000..7c0d199 --- /dev/null +++ b/src/main/java/com/mtvs/devlinkbackend/ether/dto/response/sub/UserIdAndAmountDTO.java @@ -0,0 +1,14 @@ +package com.mtvs.devlinkbackend.ether.dto.response.sub; + +import lombok.*; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString +public class UserIdAndAmountDTO { + private Long userId; + private Integer goldAmount; + private Integer silverAmount; +} diff --git a/src/main/java/com/mtvs/devlinkbackend/ether/entity/Ether.java b/src/main/java/com/mtvs/devlinkbackend/ether/entity/Ether.java index 2177ac9..9852c43 100644 --- a/src/main/java/com/mtvs/devlinkbackend/ether/entity/Ether.java +++ b/src/main/java/com/mtvs/devlinkbackend/ether/entity/Ether.java @@ -19,11 +19,17 @@ public class Ether { @Column(name = "ETHER_ID") private Long etherId; - @Column(name = "AMOUNT") - private Long amount; + @Column(name = "USER_ID") + private Long userId; - @Column(name = "REASON") - private String reason; + @Column(name = "CAUSE") + private String cause; + + @Column(name = "GOLD_AMOUNT") + private Integer goldAmount; + + @Column(name = "SILVER_AMOUNT") + private Integer silverAmount; @CreationTimestamp @Column(name = "CREATED_AT", updatable = false) @@ -33,22 +39,24 @@ public class Ether { @Column(name = "MODIFIED_AT") private LocalDateTime modifiedAt; - @Column(name = "ACCOUNT_ID") - private String accountId; - public Ether () {} - public Ether(String accountId, String reason, Long amount) { - this.accountId = accountId; - this.reason = reason; - this.amount = amount; + public Ether(Long userId, String cause, Integer goldAmount, Integer silverAmount) { + this.userId = userId; + this.cause = cause; + this.goldAmount = goldAmount; + this.silverAmount = silverAmount; + } + + public void setGoldAmount(Integer goldAmount) { + this.goldAmount = goldAmount; } - public void setAmount(Long amount) { - this.amount = amount; + public void setSilverAmount(Integer silverAmount) { + this.silverAmount = silverAmount; } - public void setReason(String reason) { - this.reason = reason; + public void setCause(String cause) { + this.cause = cause; } } diff --git a/src/main/java/com/mtvs/devlinkbackend/ether/repository/EtherRepository.java b/src/main/java/com/mtvs/devlinkbackend/ether/repository/EtherRepository.java index 4010eef..a181a45 100644 --- a/src/main/java/com/mtvs/devlinkbackend/ether/repository/EtherRepository.java +++ b/src/main/java/com/mtvs/devlinkbackend/ether/repository/EtherRepository.java @@ -8,6 +8,4 @@ @Repository public interface EtherRepository extends JpaRepository { - public List findEthersByAccountId(String accountId); - public List findEthersByReason(String reason); } diff --git a/src/main/java/com/mtvs/devlinkbackend/ether/repository/EtherViewRepository.java b/src/main/java/com/mtvs/devlinkbackend/ether/repository/EtherViewRepository.java new file mode 100644 index 0000000..60abffa --- /dev/null +++ b/src/main/java/com/mtvs/devlinkbackend/ether/repository/EtherViewRepository.java @@ -0,0 +1,16 @@ +package com.mtvs.devlinkbackend.ether.repository; + +import com.mtvs.devlinkbackend.ether.entity.Ether; +import com.mtvs.devlinkbackend.ether.repository.projection.EtherGoldAndSilver; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface EtherViewRepository extends JpaRepository { + Page findAllByUserId(Long userId, Pageable pageable); + List findEthersByUserId(Long userId); +} diff --git a/src/main/java/com/mtvs/devlinkbackend/ether/repository/projection/EtherGoldAndSilver.java b/src/main/java/com/mtvs/devlinkbackend/ether/repository/projection/EtherGoldAndSilver.java new file mode 100644 index 0000000..af5a2f1 --- /dev/null +++ b/src/main/java/com/mtvs/devlinkbackend/ether/repository/projection/EtherGoldAndSilver.java @@ -0,0 +1,6 @@ +package com.mtvs.devlinkbackend.ether.repository.projection; + +public interface EtherGoldAndSilver { + Integer getGoldAmount(); + Integer getSilverAmount(); +} diff --git a/src/main/java/com/mtvs/devlinkbackend/ether/service/EtherService.java b/src/main/java/com/mtvs/devlinkbackend/ether/service/EtherService.java index 9ac8903..badcdd1 100644 --- a/src/main/java/com/mtvs/devlinkbackend/ether/service/EtherService.java +++ b/src/main/java/com/mtvs/devlinkbackend/ether/service/EtherService.java @@ -1,6 +1,5 @@ package com.mtvs.devlinkbackend.ether.service; -import com.mtvs.devlinkbackend.ether.dto.response.EtherListResponseDTO; import com.mtvs.devlinkbackend.ether.dto.request.EtherRegistRequestDTO; import com.mtvs.devlinkbackend.ether.dto.response.EtherSingleResponseDTO; import com.mtvs.devlinkbackend.ether.dto.request.EtherUpdateRequestDTO; @@ -20,25 +19,13 @@ public EtherService(EtherRepository etherRepository) { } @Transactional - public EtherSingleResponseDTO registEther(EtherRegistRequestDTO etherRegistRequestDTO, String accountId) { + public EtherSingleResponseDTO registEther(EtherRegistRequestDTO etherRegistRequestDTO) { return new EtherSingleResponseDTO(etherRepository.save( new Ether( - accountId, - etherRegistRequestDTO.getReason(), - etherRegistRequestDTO.getAmount()) - )); - } - - public EtherSingleResponseDTO findEtherByEtherId(Long etherId) { - return new EtherSingleResponseDTO(etherRepository.findById(etherId).orElse(null)); - } - - public EtherListResponseDTO findEthersByAccountId(String accountId) { - return new EtherListResponseDTO(etherRepository.findEthersByAccountId(accountId)); - } - - public EtherListResponseDTO findEthersByReason(String reason) { - return new EtherListResponseDTO(etherRepository.findEthersByReason(reason)); + etherRegistRequestDTO.getUserId(), + etherRegistRequestDTO.getCause(), + etherRegistRequestDTO.getGoldAmount(), + etherRegistRequestDTO.getSilverAmount()))); } @Transactional @@ -46,8 +33,9 @@ public EtherSingleResponseDTO updateEther(EtherUpdateRequestDTO etherUpdateReque Optional ether = etherRepository.findById(etherUpdateRequestDTO.getEtherId()); if(ether.isPresent()) { Ether foundEther = ether.get(); - foundEther.setReason(etherUpdateRequestDTO.getReason()); - foundEther.setAmount(etherUpdateRequestDTO.getAmount()); + foundEther.setCause(etherUpdateRequestDTO.getCause()); + foundEther.setGoldAmount(etherUpdateRequestDTO.getGoldAmount()); + foundEther.setSilverAmount(etherUpdateRequestDTO.getSilverAmount()); return new EtherSingleResponseDTO(foundEther); } else throw new IllegalArgumentException("잘못된 Ether Id로 호출, ETHER_ID : " + etherUpdateRequestDTO.getEtherId()); diff --git a/src/main/java/com/mtvs/devlinkbackend/ether/service/EtherViewService.java b/src/main/java/com/mtvs/devlinkbackend/ether/service/EtherViewService.java new file mode 100644 index 0000000..07a7311 --- /dev/null +++ b/src/main/java/com/mtvs/devlinkbackend/ether/service/EtherViewService.java @@ -0,0 +1,60 @@ +package com.mtvs.devlinkbackend.ether.service; + +import com.mtvs.devlinkbackend.ether.dto.response.EtherPagingResponseDTO; +import com.mtvs.devlinkbackend.ether.dto.response.EtherSingleResponseDTO; +import com.mtvs.devlinkbackend.ether.dto.response.UserEtherAmountResponseDTO; +import com.mtvs.devlinkbackend.ether.dto.response.sub.UserIdAndAmountDTO; +import com.mtvs.devlinkbackend.ether.entity.Ether; +import com.mtvs.devlinkbackend.ether.repository.EtherViewRepository; +import com.mtvs.devlinkbackend.ether.repository.projection.EtherGoldAndSilver; +import com.mtvs.devlinkbackend.user.command.model.entity.User; +import com.mtvs.devlinkbackend.user.query.service.UserViewService; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class EtherViewService { + + private final static Integer PAGE_SIZE = 15; + + private final EtherViewRepository etherViewRepository; + private final UserViewService userViewService; + + public EtherViewService(EtherViewRepository etherViewRepository, UserViewService userViewService) { + this.etherViewRepository = etherViewRepository; + this.userViewService = userViewService; + } + + public EtherSingleResponseDTO findEtherByEtherId(Long etherId) { + return new EtherSingleResponseDTO(etherViewRepository.findById(etherId).orElse(null)); + } + + public EtherPagingResponseDTO findEthersByAccountIdWithPagination(String accountId, Integer page) { + User user = userViewService.findUserByEpicAccountId(accountId); + if (user == null) + throw new IllegalArgumentException("잘못된 에픽 계정으로 접근 중"); + + Pageable pageable = PageRequest.of(page, PAGE_SIZE, Sort.by("createdAt").ascending()); + Page etherPage = etherViewRepository.findAllByUserId(user.getUserId(), pageable); + return new EtherPagingResponseDTO(etherPage.getContent(), etherPage.getTotalPages(), etherViewRepository.count()); + } + + public UserEtherAmountResponseDTO findTotalEtherAmountByUserId(Long userId) { + List etherList = etherViewRepository.findEthersByUserId(userId); + + Integer totalGoldAmount = etherList.stream() + .mapToInt(EtherGoldAndSilver::getGoldAmount) + .sum(); + + Integer totalSilverAmount = etherList.stream() + .mapToInt(EtherGoldAndSilver::getSilverAmount) + .sum(); + + return new UserEtherAmountResponseDTO(new UserIdAndAmountDTO(userId, totalGoldAmount, totalSilverAmount)); + } +} diff --git a/src/main/java/com/mtvs/devlinkbackend/guild/controller/GuildQueryController.java b/src/main/java/com/mtvs/devlinkbackend/guild/controller/GuildQueryController.java index a3af085..5cee416 100644 --- a/src/main/java/com/mtvs/devlinkbackend/guild/controller/GuildQueryController.java +++ b/src/main/java/com/mtvs/devlinkbackend/guild/controller/GuildQueryController.java @@ -1,7 +1,7 @@ package com.mtvs.devlinkbackend.guild.controller; import com.mtvs.devlinkbackend.common.util.JwtUtil; -import com.mtvs.devlinkbackend.guild.dto.response.GuildDetailListResponseDTO; +import com.mtvs.devlinkbackend.guild.dto.response.GuildDetailPagingResponseDTO; import com.mtvs.devlinkbackend.guild.dto.response.GuildDetailSingleResponseDTO; import com.mtvs.devlinkbackend.guild.dto.response.GuildListResponseDTO; import com.mtvs.devlinkbackend.guild.service.GuildViewService; @@ -35,7 +35,7 @@ public ResponseEntity findGuildByGuildId(@PathVari @Operation(summary = "길드 목록 조회", description = "이름이 특정 문자열을 포함하는 길드 목록을 조회합니다.") @ApiResponse(responseCode = "200", description = "길드 목록이 성공적으로 조회되었습니다.") @GetMapping("/list/{page}") - public ResponseEntity findGuildsWithPagination(@PathVariable Integer page) { + public ResponseEntity findGuildsWithPagination(@PathVariable Integer page) { return ResponseEntity.ok(guildViewService.findGuildDetailsWithPagination(page)); } diff --git a/src/main/java/com/mtvs/devlinkbackend/guild/dto/response/GuildDetailListResponseDTO.java b/src/main/java/com/mtvs/devlinkbackend/guild/dto/response/GuildDetailPagingResponseDTO.java similarity index 71% rename from src/main/java/com/mtvs/devlinkbackend/guild/dto/response/GuildDetailListResponseDTO.java rename to src/main/java/com/mtvs/devlinkbackend/guild/dto/response/GuildDetailPagingResponseDTO.java index aa4c489..d049043 100644 --- a/src/main/java/com/mtvs/devlinkbackend/guild/dto/response/GuildDetailListResponseDTO.java +++ b/src/main/java/com/mtvs/devlinkbackend/guild/dto/response/GuildDetailPagingResponseDTO.java @@ -10,6 +10,8 @@ @NoArgsConstructor @AllArgsConstructor @ToString -public class GuildDetailListResponseDTO { +public class GuildDetailPagingResponseDTO { private List data; + private Integer totalPages; + private Long totalGuildCnt; } diff --git a/src/main/java/com/mtvs/devlinkbackend/guild/service/GuildViewService.java b/src/main/java/com/mtvs/devlinkbackend/guild/service/GuildViewService.java index 7cefa37..366fac4 100644 --- a/src/main/java/com/mtvs/devlinkbackend/guild/service/GuildViewService.java +++ b/src/main/java/com/mtvs/devlinkbackend/guild/service/GuildViewService.java @@ -1,6 +1,6 @@ package com.mtvs.devlinkbackend.guild.service; -import com.mtvs.devlinkbackend.guild.dto.response.GuildDetailListResponseDTO; +import com.mtvs.devlinkbackend.guild.dto.response.GuildDetailPagingResponseDTO; import com.mtvs.devlinkbackend.guild.dto.response.GuildDetailSingleResponseDTO; import com.mtvs.devlinkbackend.guild.dto.response.GuildListResponseDTO; import com.mtvs.devlinkbackend.guild.dto.response.sub.GuildAndMemberDTO; @@ -52,7 +52,7 @@ public GuildDetailSingleResponseDTO findGuildDetailByGuildId(Long guildId) { ); } - public GuildDetailListResponseDTO findGuildDetailsWithPagination(Integer page) { + public GuildDetailPagingResponseDTO findGuildDetailsWithPagination(Integer page) { Pageable pageable = PageRequest.of(page, PAGE_SIZE, Sort.by("createdAt").ascending()); Page guildPage = guildViewRepository.findAllBy(pageable); @@ -67,7 +67,7 @@ public GuildDetailListResponseDTO findGuildDetailsWithPagination(Integer page) { memberViewService.findMemberByMemberId(memberId).getData()).toList() )).toList(); - return new GuildDetailListResponseDTO(guildAndMemberDTOList); + return new GuildDetailPagingResponseDTO(guildAndMemberDTOList, guildPage.getTotalPages(), guildViewRepository.count()); } public GuildListResponseDTO findGuildsByAccountIdInGuild(String accountId) { diff --git a/src/main/java/com/mtvs/devlinkbackend/support/entity/Support.java b/src/main/java/com/mtvs/devlinkbackend/support/entity/Support.java index ba97c60..9be417d 100644 --- a/src/main/java/com/mtvs/devlinkbackend/support/entity/Support.java +++ b/src/main/java/com/mtvs/devlinkbackend/support/entity/Support.java @@ -1,5 +1,6 @@ package com.mtvs.devlinkbackend.support.entity; +import com.mtvs.devlinkbackend.common.model.AcceptStatus; import jakarta.persistence.*; import lombok.Getter; import lombok.NoArgsConstructor; @@ -23,9 +24,9 @@ public class Support { private Long teamId; @Column(name = "SUPPORT_CONFIRMATION") - private String supportConfirmation; // 상태 : waiting, accepted, rejected + private AcceptStatus supportConfirmation; // 상태 : waiting, accepted, rejected - public Support(Long projectId, Long teamId, String supportConfirmation) { + public Support(Long projectId, Long teamId, AcceptStatus supportConfirmation) { this.projectId = projectId; this.teamId = teamId; this.supportConfirmation = supportConfirmation; @@ -39,7 +40,7 @@ public void setTeamId(Long teamId) { this.teamId = teamId; } - public void setSupportConfirmation(String supportConfirmation) { + public void setSupportConfirmation(AcceptStatus supportConfirmation) { this.supportConfirmation = supportConfirmation; } } diff --git a/src/main/java/com/mtvs/devlinkbackend/support/service/SupportService.java b/src/main/java/com/mtvs/devlinkbackend/support/service/SupportService.java index f35ad4a..2acebf4 100644 --- a/src/main/java/com/mtvs/devlinkbackend/support/service/SupportService.java +++ b/src/main/java/com/mtvs/devlinkbackend/support/service/SupportService.java @@ -1,5 +1,6 @@ package com.mtvs.devlinkbackend.support.service; +import com.mtvs.devlinkbackend.common.model.AcceptStatus; import com.mtvs.devlinkbackend.support.dto.response.SupportListResponseDTO; import com.mtvs.devlinkbackend.support.dto.request.SupportRegistRequestDTO; import com.mtvs.devlinkbackend.support.dto.response.SupportSingleResponseDTO; @@ -23,7 +24,7 @@ public SupportSingleResponseDTO createSupport(SupportRegistRequestDTO supportReg return new SupportSingleResponseDTO(supportRepository.save(new Support( supportRegistRequestDTO.getProjectId(), supportRegistRequestDTO.getTeamId(), - "waiting" + AcceptStatus.PENDING ))); } diff --git a/src/main/java/com/mtvs/devlinkbackend/user/command/controller/EpicDevCommandController.java b/src/main/java/com/mtvs/devlinkbackend/user/command/controller/EpicDevCommandController.java index a961910..743495d 100644 --- a/src/main/java/com/mtvs/devlinkbackend/user/command/controller/EpicDevCommandController.java +++ b/src/main/java/com/mtvs/devlinkbackend/user/command/controller/EpicDevCommandController.java @@ -57,7 +57,7 @@ public ResponseEntity update( @ApiResponse(responseCode = "204", description = "성공적으로 삭제함"), @ApiResponse(responseCode = "404", description = "찾을 수 없음") }) - @DeleteMapping("/delete") + @DeleteMapping public ResponseEntity deleteByAuthorizationHeader( @RequestHeader("Authorization") String authorizationHeader) throws Exception { diff --git a/src/test/java/com/mtvs/devlinkbackend/crud/EtherCRUDTest.java b/src/test/java/com/mtvs/devlinkbackend/crud/EtherCRUDTest.java index 1e73ea4..f2fcd15 100644 --- a/src/test/java/com/mtvs/devlinkbackend/crud/EtherCRUDTest.java +++ b/src/test/java/com/mtvs/devlinkbackend/crud/EtherCRUDTest.java @@ -2,90 +2,136 @@ import com.mtvs.devlinkbackend.ether.dto.request.EtherRegistRequestDTO; import com.mtvs.devlinkbackend.ether.dto.request.EtherUpdateRequestDTO; +import com.mtvs.devlinkbackend.ether.dto.response.EtherSingleResponseDTO; +import com.mtvs.devlinkbackend.ether.dto.response.UserEtherAmountResponseDTO; +import com.mtvs.devlinkbackend.ether.entity.Ether; +import com.mtvs.devlinkbackend.ether.repository.EtherRepository; +import com.mtvs.devlinkbackend.ether.repository.EtherViewRepository; +import com.mtvs.devlinkbackend.ether.repository.projection.EtherGoldAndSilver; import com.mtvs.devlinkbackend.ether.service.EtherService; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Order; +import com.mtvs.devlinkbackend.ether.service.EtherViewService; +import com.mtvs.devlinkbackend.user.command.model.entity.User; +import com.mtvs.devlinkbackend.user.command.repository.UserRepository; +import com.mtvs.devlinkbackend.user.query.service.UserViewService; +import org.junit.jupiter.api.*; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.junit.jupiter.params.provider.ValueSource; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.transaction.annotation.Transactional; +import java.util.List; +import java.util.Optional; import java.util.stream.Stream; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + @SpringBootTest @Transactional public class EtherCRUDTest { @Autowired private EtherService etherService; - private static Stream newEther() { - return Stream.of( - Arguments.of(new EtherRegistRequestDTO(10L, "이유0"), "계정1"), - Arguments.of(new EtherRegistRequestDTO(100L, "이유00"), "계정2") - ); - } + @Autowired + private UserRepository userRepository; - private static Stream modifiedEther() { - return Stream.of( - Arguments.of(new EtherUpdateRequestDTO(1L,200L, "이유0")), - Arguments.of(new EtherUpdateRequestDTO(2L,500L , "이유00")) - ); - } + @Autowired + private EtherViewService etherViewService; + @Autowired + private EtherViewRepository etherViewRepository; + @Autowired + private EtherRepository etherRepository; - @DisplayName("에테르 이력 추가 테스트") - @ParameterizedTest - @MethodSource("newEther") - @Order(0) - public void testCreateEther(EtherRegistRequestDTO etherRegistRequestDTO, String accountId) { - Assertions.assertDoesNotThrow(() -> etherService.registEther(etherRegistRequestDTO, accountId)); + @BeforeEach + void setUp() { + // Create a user if none exists + if (userRepository.findAll().isEmpty()) { + User user = new User(); + user.setNickname("TestUser"); + user.setExperienceValue(0); + userRepository.save(user); + } } - @DisplayName("PK로 에테르 이력 조회 테스트") - @ValueSource(longs = {1,2}) - @ParameterizedTest - @Order(1) - public void testFindEtherByEtherId(long etherId) { - Assertions.assertDoesNotThrow(() -> - System.out.println("Ether = " + etherService.findEtherByEtherId(etherId))); + @Test + @DisplayName("Ether 등록 서비스 테스트") + public void registEtherTest() { + List user = userRepository.findAll(); + + EtherRegistRequestDTO requestDTO = new EtherRegistRequestDTO(user.get(0).getUserId(), 100, 200, "test cause"); + + EtherSingleResponseDTO responseDTO = etherService.registEther(requestDTO); + + assertThat(responseDTO).isNotNull(); + assertThat(responseDTO.getData().getGoldAmount()).isEqualTo(100); + assertThat(responseDTO.getData().getSilverAmount()).isEqualTo(200); } - @DisplayName("계정 ID에 따른 에테르 이력 조회 테스트") - @ValueSource(strings = {"계정1", "계정2"}) - @ParameterizedTest - @Order(3) - public void testFindEthersByAccountId(String accountId) { - Assertions.assertDoesNotThrow(() -> - System.out.println("Ether = " + etherService.findEthersByAccountId(accountId))); + @Test + @DisplayName("Ether 수정 서비스 테스트") + public void updateEtherTest() { + List user = userRepository.findAll(); + + EtherRegistRequestDTO registRequestDTO = new EtherRegistRequestDTO(user.get(0).getUserId(), 100, 200, "test cause"); + + EtherSingleResponseDTO registResponseDTO = etherService.registEther(registRequestDTO); + + EtherUpdateRequestDTO requestDTO = new EtherUpdateRequestDTO(registResponseDTO.getData().getEtherId(), user.get(0).getUserId(), 150, 250, "updated cause"); + + EtherSingleResponseDTO responseDTO = etherService.updateEther(requestDTO); + + assertThat(responseDTO).isNotNull(); + assertThat(responseDTO.getData().getCause()).isEqualTo("updated cause"); + assertThat(responseDTO.getData().getGoldAmount()).isEqualTo(150); + assertThat(responseDTO.getData().getSilverAmount()).isEqualTo(250); } - @DisplayName("지급 이유에 따른 에테르 이력 조회 테스트") - @ValueSource(strings = {"Salary Bonus", "Expense Compensation"}) - @ParameterizedTest - @Order(4) - public void testFindEthersByReason(String reason) { - Assertions.assertDoesNotThrow(() -> - System.out.println("Ether = " + etherService.findEthersByReason(reason))); + @Test + @DisplayName("존재하지 않는 Ether 수정 서비스 테스트") + public void updateEtherNotFoundTest() { + List user = userRepository.findAll(); + + EtherUpdateRequestDTO requestDTO = new EtherUpdateRequestDTO(1L, user.get(0).getUserId(), 150, 250, "updated cause"); + + Assertions.assertThrows(IllegalArgumentException.class, () -> etherService.updateEther(requestDTO)); } - @DisplayName("에테르 이력 수정 테스트") - @MethodSource("modifiedEther") - @ParameterizedTest - @Order(5) - public void testUpdateQuestion(EtherUpdateRequestDTO etherUpdateRequestDTO) { - Assertions.assertDoesNotThrow(() -> - System.out.println(etherService.updateEther(etherUpdateRequestDTO))); + @Test + @DisplayName("Ether 삭제 서비스 테스트") + public void deleteEtherByEtherIdTest() { + List user = userRepository.findAll(); + + EtherRegistRequestDTO requestDTO = new EtherRegistRequestDTO(user.get(0).getUserId(), 100, 200, "test cause"); + + Ether ether = etherService.registEther(requestDTO).getData(); + + assertDoesNotThrow(() -> etherService.deleteEtherByEtherId(ether.getEtherId())); } - @DisplayName("에테르 이력 삭제 테스트") - @ValueSource(longs = {0,1}) - @ParameterizedTest - @Order(6) - public void testDeleteEther(long etherId) { - Assertions.assertDoesNotThrow(() -> - etherService.deleteEtherByEtherId(etherId)); + @Test + @DisplayName("유저 ID로 Ether 총 금액 조회 테스트") + public void findTotalEtherAmountByUserIdTest() { + List userList = userRepository.findAll(); + Long userId = userList.get(0).getUserId(); + + Ether ether1 = new Ether(userId, "cause 1", 100, 200); + Ether ether2 = new Ether(userId, "cause 2", 150, 250); + etherRepository.save(ether1); + etherRepository.save(ether2); + + assertDoesNotThrow(() -> { + UserEtherAmountResponseDTO responseDTO = etherViewService.findTotalEtherAmountByUserId(userId); + assertThat(responseDTO).isNotNull(); + assertThat(responseDTO.getData().getGoldAmount()).isEqualTo(250); + assertThat(responseDTO.getData().getSilverAmount()).isEqualTo(450); + }); } } diff --git a/src/test/java/com/mtvs/devlinkbackend/crud/SupportCRUDTest.java b/src/test/java/com/mtvs/devlinkbackend/crud/SupportCRUDTest.java index a5f36d7..2e1695b 100644 --- a/src/test/java/com/mtvs/devlinkbackend/crud/SupportCRUDTest.java +++ b/src/test/java/com/mtvs/devlinkbackend/crud/SupportCRUDTest.java @@ -1,5 +1,6 @@ package com.mtvs.devlinkbackend.crud; +import com.mtvs.devlinkbackend.common.model.AcceptStatus; import com.mtvs.devlinkbackend.support.dto.request.SupportRegistRequestDTO; import com.mtvs.devlinkbackend.support.dto.response.SupportListResponseDTO; import com.mtvs.devlinkbackend.support.dto.response.SupportSingleResponseDTO; @@ -33,8 +34,8 @@ public void setUp() { MockitoAnnotations.openMocks(this); // 미리 삽입할 Support 객체 생성 - support1 = new Support(1L, 2L, "waiting"); - support2 = new Support(1L, 3L, "accepted"); + support1 = new Support(1L, 2L, AcceptStatus.PENDING); + support2 = new Support(1L, 3L, AcceptStatus.ACCEPTED); // Mocking the repository calls supportRepository.save(support1);