Skip to content

Commit

Permalink
Merge pull request #6 from Oh-Lottery/store
Browse files Browse the repository at this point in the history
판매처 추가
  • Loading branch information
SalkCoding authored Dec 17, 2024
2 parents 0d47b2a + 7e3e742 commit 1aa2f41
Show file tree
Hide file tree
Showing 17 changed files with 518 additions and 20 deletions.
55 changes: 49 additions & 6 deletions src/main/java/com/ohlottery/controller/Lottery645Controller.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.ohlottery.controller;

import com.ohlottery.dto.Lottery645Dto;
import com.ohlottery.dto.LotteryStoreDto;
import com.ohlottery.entity.Lottery645Entity;
import com.ohlottery.service.LotteryService;
import com.ohlottery.entity.LotteryStoreEntity;
import com.ohlottery.service.LotteryAIService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
Expand All @@ -17,21 +19,23 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("lottery645/round")
@RequestMapping("lottery645")
@RequiredArgsConstructor

@Tag(name = "Lottery 6/45 Controller", description = "6/45 당첨 정보 API")
public class Lottery645Controller {

private final LotteryService lotteryService;
private final LotteryAIService lotteryAIService;

@GetMapping("/{round}")
@GetMapping("/round/{round}")

@Operation(summary = "6/45로또 데이터 조회", description = "해당 회차 6/45 당첨 정보를 데이터베이스에서 조회")
@ApiResponses(value ={
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "데이터 조회 성공",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Lottery645Dto.class))),
@ApiResponse(responseCode = "400", description = "잘못된 인자 값", content = @Content()),
Expand All @@ -49,7 +53,7 @@ public ResponseEntity<?> getLotteryNumber(
}

Optional<Lottery645Entity> roundResult
= lotteryService.getLottery645Result(requestRound);
= lotteryAIService.getLottery645Result(requestRound);

if (roundResult.isEmpty()) return ResponseEntity.notFound().build();

Expand All @@ -71,4 +75,43 @@ public ResponseEntity<?> getLotteryNumber(
);
return ResponseEntity.ok(resultDto);
}

@GetMapping("/round/{round}/store")

@Operation(summary = "6/45로또 1등 판매처 데이터 조회", description = "해당 회차 6/45 1등 판매처 정보를 데이터베이스에서 조회")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "데이터 조회 성공",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = LotteryStoreDto.class))),
@ApiResponse(responseCode = "400", description = "잘못된 인자 값", content = @Content()),
@ApiResponse(responseCode = "404", description = "해당 회차 당첨 정보가 없음", content = @Content())
})
public ResponseEntity<?> getRoundStoreList(
@Parameter(description = "회차", example = "1")
@PathVariable("round") String round
) {
long requestRound;
try {
requestRound = Long.parseLong(round);
} catch (NumberFormatException e) {
return ResponseEntity.badRequest().build();
}

Optional<Lottery645Entity> roundResult
= lotteryAIService.getLottery645Result(requestRound);

if (roundResult.isEmpty()) return ResponseEntity.notFound().build();
Lottery645Entity entity = roundResult.get();

List<LotteryStoreDto> storeList = new ArrayList<>();
entity.getStoreList().forEach(entityStore -> {
LotteryStoreEntity storeEntity = entityStore.getStoreEntity();
storeList.add(new LotteryStoreDto(
storeEntity.getId(),
storeEntity.getStoreName(),
storeEntity.getStoreAddress()
));
}
);
return ResponseEntity.ok(storeList);
}
}
62 changes: 55 additions & 7 deletions src/main/java/com/ohlottery/controller/Lottery720Controller.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.ohlottery.controller;

import com.ohlottery.dto.Lottery720Dto;
import com.ohlottery.dto.LotteryStoreDto;
import com.ohlottery.entity.Lottery720Entity;
import com.ohlottery.service.LotteryService;
import com.ohlottery.entity.LotteryStoreEntity;
import com.ohlottery.service.LotteryAIService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
Expand All @@ -17,16 +19,18 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("lottery720/round")
@RequestMapping("lottery720")
@RequiredArgsConstructor

@Tag(name = "Lottery 720 Controller", description = "연금복권 당첨 정보 API")
public class Lottery720Controller {

private final LotteryService lotteryService;
private final LotteryAIService lotteryAIService;

@Operation(summary = "연금복권 데이터 조회", description = "해당 회차 연금복권 당첨 정보를 데이터베이스에서 조회")
@ApiResponses(value ={
Expand All @@ -35,15 +39,20 @@ public class Lottery720Controller {
@ApiResponse(responseCode = "400", description = "잘못된 인자 값", content = @Content()),
@ApiResponse(responseCode = "404", description = "해당 회차 당첨 정보가 없음", content = @Content())
})
@GetMapping("/{round}")
@GetMapping("/round/{round}")
public ResponseEntity<?> getLotteryNumber(
@Parameter(description = "회차", example = "1")
@PathVariable("round") Long requestRound
@PathVariable("round") String round
) {
if(requestRound == null) return ResponseEntity.badRequest().build();
long requestRound;
try {
requestRound = Long.parseLong(round);
} catch (NumberFormatException e) {
return ResponseEntity.badRequest().build();
}

Optional<Lottery720Entity> roundResult
= lotteryService.getLottery720Result(requestRound);
= lotteryAIService.getLottery720Result(requestRound);

if (roundResult.isEmpty()) return ResponseEntity.notFound().build();

Expand All @@ -58,4 +67,43 @@ public ResponseEntity<?> getLotteryNumber(
return ResponseEntity.ok(resultDto);
}

@GetMapping("/round/{round}/store")

@Operation(summary = "연금복권 1등 판매처 데이터 조회", description = "해당 회차 연금복권 1등 판매처 정보를 데이터베이스에서 조회")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "데이터 조회 성공",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = LotteryStoreDto.class))),
@ApiResponse(responseCode = "400", description = "잘못된 인자 값", content = @Content()),
@ApiResponse(responseCode = "404", description = "해당 회차 당첨 정보가 없음", content = @Content())
})
public ResponseEntity<?> getRoundStoreList(
@Parameter(description = "회차", example = "1")
@PathVariable("round") String round
) {
long requestRound;
try {
requestRound = Long.parseLong(round);
} catch (NumberFormatException e) {
return ResponseEntity.badRequest().build();
}

Optional<Lottery720Entity> roundResult
= lotteryAIService.getLottery720Result(requestRound);

if (roundResult.isEmpty()) return ResponseEntity.notFound().build();
Lottery720Entity entity = roundResult.get();

List<LotteryStoreDto> storeList = new ArrayList<>();
entity.getStoreList().forEach(entityStore -> {
LotteryStoreEntity storeEntity = entityStore.getStoreEntity();
storeList.add(new LotteryStoreDto(
storeEntity.getId(),
storeEntity.getStoreName(),
storeEntity.getStoreAddress()
));
}
);
return ResponseEntity.ok(storeList);
}

}
54 changes: 54 additions & 0 deletions src/main/java/com/ohlottery/controller/LotteryAIController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.ohlottery.controller;

import com.ohlottery.dto.Lottery645Dto;
import com.ohlottery.dto.Lottery720Dto;
import com.ohlottery.service.LotteryAIService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/lottery/ai")
public class LotteryAIController {

private final LotteryAIService lotteryAIService;

@GetMapping("/predict/645/{round}")
public ResponseEntity<Lottery645Dto> get645Predict(
@PathVariable long round
) {
return null;
}

@GetMapping("/statistic/645")
public ResponseEntity<?> get645Statistic() {
return ResponseEntity.ok(null);
}

@GetMapping("/trend/645")
public ResponseEntity<?> get645Trend() {
return ResponseEntity.ok(null);
}

@GetMapping("/predict/720/{round}")
public ResponseEntity<Lottery720Dto> get720Predict(
@PathVariable long round
) {
return null;
}

@GetMapping("/statistic/720")
public ResponseEntity<?> get720Statistic() {
return ResponseEntity.ok(null);
}

@GetMapping("/trend/720")
public ResponseEntity<?> get720Trend() {
return ResponseEntity.ok(null);
}

}
21 changes: 21 additions & 0 deletions src/main/java/com/ohlottery/dto/LotteryStoreDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.ohlottery.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
@Schema(description = "로또 판매점 정보")
public class LotteryStoreDto {

@Schema(description = "판매처 ID", example = "1")
private long storeId;

@Schema(description = "판매처 이름", example = "1148")
private String storeName;

@Schema(description = "판매처 주소", example = "서울특별시 서초구 남부순환로 2423")
private String storeAddress;
}

6 changes: 6 additions & 0 deletions src/main/java/com/ohlottery/entity/Lottery645Entity.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.ohlottery.entity;

import com.ohlottery.entity.middle.Lottery645EntityStore;
import jakarta.persistence.*;
import lombok.*;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

@Entity
@Getter
Expand Down Expand Up @@ -31,4 +34,7 @@ public class Lottery645Entity {
private long firstWinAmount;
// 총 판매금액
private long totalSellAmount;

@OneToMany(mappedBy = "lotteryEntity", cascade = CascadeType.ALL, orphanRemoval = true)
private final List<Lottery645EntityStore> storeList = new ArrayList<>();
}
18 changes: 18 additions & 0 deletions src/main/java/com/ohlottery/entity/Lottery645WinningEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.ohlottery.entity;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor
public class Lottery645WinningEntity extends LotteryWinningEntity {

@Enumerated(EnumType.STRING)
private WinningType type;

public Lottery645WinningEntity(WinningType type) {
this.type = type;
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/ohlottery/entity/Lottery720Entity.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.ohlottery.entity;

import com.ohlottery.entity.middle.Lottery720EntityStore;
import jakarta.persistence.*;
import lombok.*;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

@Entity
@Getter
Expand All @@ -19,4 +22,7 @@ public class Lottery720Entity {
private byte rankClass;// 조 번호
private int rankNo;// 당첨 번호
private int bonusNo;// 보너스 번호

@OneToMany(mappedBy = "lotteryEntity", cascade = CascadeType.ALL, orphanRemoval = true)
private final List<Lottery720EntityStore> storeList = new ArrayList<>();
}
38 changes: 38 additions & 0 deletions src/main/java/com/ohlottery/entity/LotteryStoreEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.ohlottery.entity;

import com.ohlottery.entity.middle.Lottery645EntityStore;
import com.ohlottery.entity.middle.Lottery720EntityStore;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Entity
@Getter
@NoArgsConstructor
public class LotteryStoreEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String storeName;
private String storeAddress;

@OneToMany(mappedBy = "storeEntity", cascade = CascadeType.ALL, orphanRemoval = true)
private final List<Lottery645EntityStore> entity645List = new ArrayList<>();

@OneToMany(mappedBy = "storeEntity", cascade = CascadeType.ALL, orphanRemoval = true)
private final List<Lottery720EntityStore> entity720List = new ArrayList<>();

@OneToMany(mappedBy = "store", cascade = CascadeType.ALL, orphanRemoval = true)
private final List<LotteryWinningEntity> winningList = new ArrayList<>();

public LotteryStoreEntity(String storeName, String storeAddress) {
this.storeName = storeName;
this.storeAddress = storeAddress;
}
}

23 changes: 23 additions & 0 deletions src/main/java/com/ohlottery/entity/LotteryWinningEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.ohlottery.entity;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Entity
@Getter
@NoArgsConstructor
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn
public class LotteryWinningEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "store_id")
@Setter
private LotteryStoreEntity store;
}
Loading

0 comments on commit 1aa2f41

Please sign in to comment.