bank-info 추가
This commit is contained in:
parent
237d3eacac
commit
3d49e5212d
|
@ -6,6 +6,8 @@ import com.totopia.server.modules.game.entity.SportsEntity;
|
||||||
import com.totopia.server.modules.game.repository.LeagueRepository;
|
import com.totopia.server.modules.game.repository.LeagueRepository;
|
||||||
import com.totopia.server.modules.game.repository.SportsRepository;
|
import com.totopia.server.modules.game.repository.SportsRepository;
|
||||||
import com.totopia.server.modules.game.type.SportsName;
|
import com.totopia.server.modules.game.type.SportsName;
|
||||||
|
import com.totopia.server.modules.site.entity.BankInfoEntity;
|
||||||
|
import com.totopia.server.modules.site.repository.BankInfoRepository;
|
||||||
import com.totopia.server.modules.user.entity.GradeEntity;
|
import com.totopia.server.modules.user.entity.GradeEntity;
|
||||||
import com.totopia.server.modules.user.entity.RoleEntity;
|
import com.totopia.server.modules.user.entity.RoleEntity;
|
||||||
import com.totopia.server.modules.user.entity.UserEntity;
|
import com.totopia.server.modules.user.entity.UserEntity;
|
||||||
|
@ -51,6 +53,9 @@ public class DbInitializer implements CommandLineRunner {
|
||||||
@Autowired
|
@Autowired
|
||||||
LeagueRepository leagueRepository;
|
LeagueRepository leagueRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
BankInfoRepository bankInfoRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(String... strings) throws Exception {
|
public void run(String... strings) throws Exception {
|
||||||
if (0 == roleRepository.count()) {
|
if (0 == roleRepository.count()) {
|
||||||
|
@ -71,6 +76,10 @@ public class DbInitializer implements CommandLineRunner {
|
||||||
if (0 == leagueRepository.count()) {
|
if (0 == leagueRepository.count()) {
|
||||||
this.initDbLeague();
|
this.initDbLeague();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (0 == bankInfoRepository.count()) {
|
||||||
|
this.initDbBankInfo();
|
||||||
|
}
|
||||||
log.debug("-- Database has been initialized");
|
log.debug("-- Database has been initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -403,4 +412,48 @@ public class DbInitializer implements CommandLineRunner {
|
||||||
this.leagueRepository.save(leagueEntity);
|
this.leagueRepository.save(leagueEntity);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initDbBankInfo() {
|
||||||
|
BankInfoEntity bankInfoEntity;
|
||||||
|
|
||||||
|
bankInfoEntity = BankInfoEntity.builder()
|
||||||
|
.name("국민은행")
|
||||||
|
.number("11111-11-11111")
|
||||||
|
.holder("테스트1")
|
||||||
|
.description("1번계좌")
|
||||||
|
.build();
|
||||||
|
bankInfoRepository.save(bankInfoEntity);
|
||||||
|
|
||||||
|
bankInfoEntity = BankInfoEntity.builder()
|
||||||
|
.name("우리은행")
|
||||||
|
.number("22222-22-22222")
|
||||||
|
.holder("테스트2")
|
||||||
|
.description("2번계좌")
|
||||||
|
.build();
|
||||||
|
bankInfoRepository.save(bankInfoEntity);
|
||||||
|
|
||||||
|
bankInfoEntity = BankInfoEntity.builder()
|
||||||
|
.name("기업은행")
|
||||||
|
.number("33333-33-33333")
|
||||||
|
.holder("테스트3")
|
||||||
|
.description("3번계좌")
|
||||||
|
.build();
|
||||||
|
bankInfoRepository.save(bankInfoEntity);
|
||||||
|
|
||||||
|
bankInfoEntity = BankInfoEntity.builder()
|
||||||
|
.name("신한은행")
|
||||||
|
.number("44444-44-444444")
|
||||||
|
.holder("테스트4")
|
||||||
|
.description("4번계좌")
|
||||||
|
.build();
|
||||||
|
bankInfoRepository.save(bankInfoEntity);
|
||||||
|
|
||||||
|
bankInfoEntity = BankInfoEntity.builder()
|
||||||
|
.name("국민은행")
|
||||||
|
.number("55555-55-55555")
|
||||||
|
.holder("테스트5")
|
||||||
|
.description("5번계좌")
|
||||||
|
.build();
|
||||||
|
bankInfoRepository.save(bankInfoEntity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.totopia.server.modules.site.controller;
|
||||||
|
|
||||||
|
import com.totopia.server.commons.data.payload.ApiResponse;
|
||||||
|
import com.totopia.server.modules.game.entity.LeagueEntity;
|
||||||
|
import com.totopia.server.modules.site.entity.BankInfoEntity;
|
||||||
|
import com.totopia.server.modules.site.service.BankInfoService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.data.web.SortDefault;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class BankInfoController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
BankInfoService bankInfoService;
|
||||||
|
|
||||||
|
@GetMapping(value = "/bank_info")
|
||||||
|
public Page<BankInfoEntity> all(
|
||||||
|
@SortDefault.SortDefaults({
|
||||||
|
@SortDefault(
|
||||||
|
sort = "id",
|
||||||
|
direction = Sort.Direction.ASC) })
|
||||||
|
Pageable pageable) {
|
||||||
|
return this.bankInfoService.getAllBankInfo(pageable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/league")
|
||||||
|
@ResponseStatus(code = HttpStatus.CREATED)
|
||||||
|
public ResponseEntity<?> save(@Valid @RequestBody BankInfoEntity bankInfoEntity) throws Exception{
|
||||||
|
this.bankInfoService.save(bankInfoEntity);
|
||||||
|
return ResponseEntity.ok().body(new ApiResponse(true, "BankInfo registered successfully"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping(value = "/league/{leagueId}")
|
||||||
|
public ResponseEntity<?> updateLeague(@PathVariable Long leagueId, BankInfoEntity bankInfoEntity) throws Exception {
|
||||||
|
BankInfoEntity leagueEntity1 = this.bankInfoService.modify(bankInfoEntity);
|
||||||
|
return ResponseEntity.ok(leagueEntity1);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
package com.totopia.server.modules.site.entity;
|
||||||
|
|
||||||
|
import com.totopia.server.commons.data.entity.DateAuditEntity;
|
||||||
|
import lombok.*;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "bank_info")
|
||||||
|
@Data
|
||||||
|
@SuperBuilder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Builder
|
||||||
|
public class BankInfoEntity extends DateAuditEntity {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(generator = "bank_info_generator")
|
||||||
|
@SequenceGenerator(name = "bank_info_generator", sequenceName = "bank_info_sequence", initialValue = 1)
|
||||||
|
private Short id;
|
||||||
|
|
||||||
|
@Basic
|
||||||
|
@Column(name = "name", nullable = false, length = 100)
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Basic
|
||||||
|
@Column(name = "number", nullable = false, length = 100)
|
||||||
|
private String number;
|
||||||
|
|
||||||
|
@Basic
|
||||||
|
@Column(name = "holder", nullable = false, length = 100)
|
||||||
|
private String holder;
|
||||||
|
|
||||||
|
@Basic
|
||||||
|
@Column(name = "description", nullable = false, length = 200)
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.totopia.server.modules.site.repository;
|
||||||
|
|
||||||
|
import com.totopia.server.modules.site.entity.BankInfoEntity;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface BankInfoRepository extends JpaRepository<BankInfoEntity, Short> {
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.totopia.server.modules.site.service;
|
||||||
|
|
||||||
|
import com.totopia.server.commons.exception.ResourceNotFoundException;
|
||||||
|
import com.totopia.server.modules.site.entity.BankInfoEntity;
|
||||||
|
import com.totopia.server.modules.site.repository.BankInfoRepository;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class BankInfoService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
BankInfoRepository bankInfoRepository;
|
||||||
|
|
||||||
|
public BankInfoEntity save(BankInfoEntity entity) {
|
||||||
|
return this.bankInfoRepository.save(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BankInfoEntity modify(BankInfoEntity entity) {
|
||||||
|
if(entity == null || entity.getId() == 0) {
|
||||||
|
log.error("id is not null");
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.bankInfoRepository.save(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Short removeById(Short bankInfoId) {
|
||||||
|
return bankInfoRepository.findById(bankInfoId).map(bankInfo -> {
|
||||||
|
bankInfoRepository.delete(bankInfo);
|
||||||
|
return bankInfoId;
|
||||||
|
}).orElseThrow(() -> new ResourceNotFoundException("BankInfoEntity", "bankInfoId", bankInfoId));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Page<BankInfoEntity> getAllBankInfo(Pageable pageable) {
|
||||||
|
|
||||||
|
return this.bankInfoRepository.findAll(pageable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BankInfoEntity getBankInfoById(Short bankInfoId) {
|
||||||
|
return this.bankInfoRepository.findById(bankInfoId).orElseThrow(null);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
package com.totopia.server.modules.site.service;
|
||||||
|
|
||||||
|
import com.totopia.server.modules.site.repository.BankInfoRepository;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
public class BankInfoServiceTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
BankInfoRepository bankInfoRepository;
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void save() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void modify() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void removeById() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAllBankInfo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getBankInfoById() {
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user