Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}
Expand All @@ -31,59 +30,21 @@ public EtherController(EtherService etherService, JwtUtil jwtUtil) {
})
@PostMapping
public ResponseEntity<EtherSingleResponseDTO> 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<EtherSingleResponseDTO> 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<EtherListResponseDTO> 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<EtherListResponseDTO> 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가 성공적으로 수정됨"),
@ApiResponse(responseCode = "400", description = "잘못된 수정 데이터"),
@ApiResponse(responseCode = "401", description = "인증되지 않음")
})
@PatchMapping
public ResponseEntity<EtherSingleResponseDTO> updateEther(@RequestBody EtherUpdateRequestDTO etherUpdateRequestDTO) {
public ResponseEntity<EtherSingleResponseDTO> updateEther(
@RequestBody EtherUpdateRequestDTO etherUpdateRequestDTO) {
try {
EtherSingleResponseDTO updatedEther = etherService.updateEther(etherUpdateRequestDTO);
return ResponseEntity.ok(updatedEther);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<EtherSingleResponseDTO> 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<EtherPagingResponseDTO> 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<UserEtherAmountResponseDTO> findTotalEtherAmountByUserId(@PathVariable Long userId) {
UserEtherAmountResponseDTO ethers = etherViewService.findTotalEtherAmountByUserId(userId);
return ResponseEntity.ok(ethers);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class EtherListResponseDTO {
public class EtherPagingResponseDTO {
private List<Ether> data;
private Integer totalPages;
private Long totalEtherCnt;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
38 changes: 23 additions & 15 deletions src/main/java/com/mtvs/devlinkbackend/ether/entity/Ether.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@

@Repository
public interface EtherRepository extends JpaRepository<Ether, Long> {
public List<Ether> findEthersByAccountId(String accountId);
public List<Ether> findEthersByReason(String reason);
}
Original file line number Diff line number Diff line change
@@ -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<Ether, Long> {
Page<Ether> findAllByUserId(Long userId, Pageable pageable);
List<EtherGoldAndSilver> findEthersByUserId(Long userId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.mtvs.devlinkbackend.ether.repository.projection;

public interface EtherGoldAndSilver {
Integer getGoldAmount();
Integer getSilverAmount();
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,34 +19,23 @@ 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
public EtherSingleResponseDTO updateEther(EtherUpdateRequestDTO etherUpdateRequestDTO) {
Optional<Ether> 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());
Expand Down
Loading