[인프런 워밍업 클럽_0기 BE] 일곱번째 과제 - JPA

[인프런 워밍업 클럽_0기 BE] 일곱번째 과제 - JPA

imageimageimage


<문제 풀이>

create table fruit (
 id bigint auto_increment,
 name varchar(20),
 price bigint,

warehousing_date date,
is_sold boolean default false,
 reg_datetime datetime default CURRENT_TIMESTAMP,
alt_datetime datetime,
primary key (id));

 

ackage com.group.libarayapp.dto.task07.request;

import java.time.LocalDate;

public class FruitCreateRequestEx07 {

    Long id;
    String name;
    LocalDate warehousing;
    Long price;
    int salesQuantity;

    public FruitCreateRequestEx07(Long id, String name, LocalDate warehousing, Long price, int salesQuantity) {
        this.id = id;
        this.name = name;
        this.warehousing = warehousing;
        this.price = price;
        this.salesQuantity = salesQuantity;
    }

    public String getName() {
        return name;
    }

    public Long getId() {
        return id;
    }

    public LocalDate getWarehousing() {
        return warehousing;
    }

    public Long getPrice() {
        return price;
    }

    public int getSalesQuantity() {
        return salesQuantity;
    }
}
package inflearn;

package com.group.libarayapp.controller.task07;

import com.group.libarayapp.domain.user.task07.Fruit;
import com.group.libarayapp.dto.task07.request.FruitCreateRequestEx07;
import com.group.libarayapp.dto.task07.request.FruitRequestEx07;
import com.group.libarayapp.dto.task07.response.FruitResponseEx07;
import com.group.libarayapp.dto.task07.response.FruitSalesCountResponseEx07;
import com.group.libarayapp.service.task07.FruitServiceEx07;
import org.springframework.web.bind.annotation.*;

import java.util.List;

public class FruitControllerEx07 {

    @RestController
    public class FruitControllerEx07 {

        private final FruitServiceEx07 fruitServiceEx07;

        public FruitControllerEx07(FruitServiceEx07 fruitServiceEx07) {
            this.fruitServiceEx07 = fruitServiceEx07;
        }

        // 문제 1
        @PostMapping("/api/v3/fruit")
        public void saveFruit(@RequestBody FruitRequestEx07 request) {
            fruitServiceEx07.saveFruit(request);
        }


        // 문제 2
        @PutMapping("/api/v3/fruit")
        public void salesQuantityFruit(@RequestBody FruitCreateRequestEx07 request) {
            fruitServiceEx07.salesQuantityFruit(request);
        }

        // 문제 3
        @GetMapping("/api/v3/fruit/stat")
        public FruitResponseEx07 SalesAmountFruit(@RequestParam String name) {
            return fruitServiceEx07.salesAmountFruit(name);
        }

        // 문제 3
        @GetMapping("/api/v3/fruit/count")
        public FruitSalesCountResponseEx07 SalesCountFruit(@RequestParam String name) {
            return fruitServiceEx07.salesCountFruit(name);
        }

        @GetMapping("/api/v3/fruit/list")
        public List<Fruit> fruitListOfGTEorLTE(
                @RequestParam(name = "option") String option,
                @RequestParam(name = "price") long price) {
            return fruitServiceEx07.fruitListOfGTEorLTE(option, price);
        }

    }
}
package com.group.libarayapp.dto.task07.request;

import java.time.LocalDate;

public class FruitRequestEx07 {

    private Long id;
    private String name;
    private LocalDate warehousingDate;

    private int salesQuantity;
    private Long price;

    public FruitRequestEx07(String name, LocalDate warehousingDate, Long price) {
        this.name = name;
        this.warehousingDate = warehousingDate;
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public LocalDate getWarehousingDate() {
        return warehousingDate;
    }

    public Long getPrice() {
        return price;
    }

    public Long getId() {
        return id;
    }

    public int getSalesQuantity() {
        return salesQuantity;
    }
}
 package com.group.libarayapp.dto.task07.response;

public class FruitResponseEx07 {
    private final long salesAmount;
    private final long notSalesAmount;

    public FruitResponseEx07(long salesAmount, long notSalesAmount) {
        this.salesAmount = salesAmount;
        this.notSalesAmount = notSalesAmount;
    }

    public long getSalesAmount() {
        return salesAmount;
    }

    public long getNotSalesAmount() {
        return notSalesAmount;
    }
}
package com.group.libarayapp.dto.task07.response;

public class FruitSalesCountResponseEx07 {

    private final long count;

    public FruitSalesCountResponseEx07(long count) {
        this.count = count;
    }

    public long getCount() {
        return count;
    }
}

 

<실행 결과>

image

댓글을 작성해보세요.

채널톡 아이콘