From 3d49e5212db1c812988855dffb21c024d8577a2c Mon Sep 17 00:00:00 2001 From: byung eun park Date: Tue, 3 Sep 2019 19:05:10 +0900 Subject: [PATCH] =?UTF-8?q?bank-info=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../totopia/server/init/DbInitializer.java | 53 +++++++++++++++++++ .../site/controller/BankInfoController.java | 46 ++++++++++++++++ .../modules/site/entity/BankInfoEntity.java | 39 ++++++++++++++ .../site/repository/BankInfoRepository.java | 7 +++ .../modules/site/service/BankInfoService.java | 46 ++++++++++++++++ .../site/service/BankInfoServiceTest.java | 39 ++++++++++++++ 6 files changed, 230 insertions(+) create mode 100644 src/main/java/com/totopia/server/modules/site/controller/BankInfoController.java create mode 100644 src/main/java/com/totopia/server/modules/site/entity/BankInfoEntity.java create mode 100644 src/main/java/com/totopia/server/modules/site/repository/BankInfoRepository.java create mode 100644 src/main/java/com/totopia/server/modules/site/service/BankInfoService.java create mode 100644 src/test/java/com/totopia/server/modules/site/service/BankInfoServiceTest.java diff --git a/src/main/java/com/totopia/server/init/DbInitializer.java b/src/main/java/com/totopia/server/init/DbInitializer.java index 5813b98..a616780 100644 --- a/src/main/java/com/totopia/server/init/DbInitializer.java +++ b/src/main/java/com/totopia/server/init/DbInitializer.java @@ -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.SportsRepository; 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.RoleEntity; import com.totopia.server.modules.user.entity.UserEntity; @@ -51,6 +53,9 @@ public class DbInitializer implements CommandLineRunner { @Autowired LeagueRepository leagueRepository; + @Autowired + BankInfoRepository bankInfoRepository; + @Override public void run(String... strings) throws Exception { if (0 == roleRepository.count()) { @@ -71,6 +76,10 @@ public class DbInitializer implements CommandLineRunner { if (0 == leagueRepository.count()) { this.initDbLeague(); } + + if (0 == bankInfoRepository.count()) { + this.initDbBankInfo(); + } log.debug("-- Database has been initialized"); } @@ -403,4 +412,48 @@ public class DbInitializer implements CommandLineRunner { 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); + } } diff --git a/src/main/java/com/totopia/server/modules/site/controller/BankInfoController.java b/src/main/java/com/totopia/server/modules/site/controller/BankInfoController.java new file mode 100644 index 0000000..0e3712f --- /dev/null +++ b/src/main/java/com/totopia/server/modules/site/controller/BankInfoController.java @@ -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 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); + } +} diff --git a/src/main/java/com/totopia/server/modules/site/entity/BankInfoEntity.java b/src/main/java/com/totopia/server/modules/site/entity/BankInfoEntity.java new file mode 100644 index 0000000..217d997 --- /dev/null +++ b/src/main/java/com/totopia/server/modules/site/entity/BankInfoEntity.java @@ -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; + +} diff --git a/src/main/java/com/totopia/server/modules/site/repository/BankInfoRepository.java b/src/main/java/com/totopia/server/modules/site/repository/BankInfoRepository.java new file mode 100644 index 0000000..73e8e40 --- /dev/null +++ b/src/main/java/com/totopia/server/modules/site/repository/BankInfoRepository.java @@ -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 { +} diff --git a/src/main/java/com/totopia/server/modules/site/service/BankInfoService.java b/src/main/java/com/totopia/server/modules/site/service/BankInfoService.java new file mode 100644 index 0000000..d47b1b2 --- /dev/null +++ b/src/main/java/com/totopia/server/modules/site/service/BankInfoService.java @@ -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 getAllBankInfo(Pageable pageable) { + + return this.bankInfoRepository.findAll(pageable); + } + + public BankInfoEntity getBankInfoById(Short bankInfoId) { + return this.bankInfoRepository.findById(bankInfoId).orElseThrow(null); + } +} diff --git a/src/test/java/com/totopia/server/modules/site/service/BankInfoServiceTest.java b/src/test/java/com/totopia/server/modules/site/service/BankInfoServiceTest.java new file mode 100644 index 0000000..16c99c0 --- /dev/null +++ b/src/test/java/com/totopia/server/modules/site/service/BankInfoServiceTest.java @@ -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() { + } +} \ No newline at end of file