Skip to content

Commit

Permalink
Merge branch 'main' into feat/update-InitDb(#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinhoon227 authored Sep 19, 2023
2 parents 5dea3bb + 4e69cd8 commit a3f951d
Show file tree
Hide file tree
Showing 25 changed files with 388 additions and 31 deletions.
3 changes: 3 additions & 0 deletions src/main/java/iampotato/iampotato/InitDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,9 @@ public void dbStores3() throws ParseException {
.loginId("hi")
.password("123")
.nickname("likeCoffee")
.customerNumber("2017038000")
.customerDept("소프트웨어학과")
.customerCollege("충북대학교")
.build();
em.persist(customer);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package iampotato.iampotato.domain.customer.api;

import iampotato.iampotato.domain.customer.application.CertifyCustomerService;
import iampotato.iampotato.domain.customer.application.CustomerImageService;
import iampotato.iampotato.domain.customer.application.CustomerSignInService;
import iampotato.iampotato.domain.customer.application.CustomerSignUpService;
import iampotato.iampotato.domain.customer.application.*;
import iampotato.iampotato.domain.customer.domain.Customer;
import iampotato.iampotato.domain.customer.dto.*;
import iampotato.iampotato.domain.order.domain.Order;
import iampotato.iampotato.domain.order.dto.OrderDetailResponse;
import iampotato.iampotato.global.util.Result;
import iampotato.iampotato.global.util.SecurityUtil;
import lombok.RequiredArgsConstructor;
Expand All @@ -16,13 +15,17 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequiredArgsConstructor
public class CustomerApi {
private final CustomerSignInService customerSignInService;
private final CustomerSignUpService customerSignUpService;
private final CustomerImageService customerImageService;
private final CertifyCustomerService certifyCustomerService;
private final GetUnauthorizedCustomersService getUnauthorizedCustomersService;

@PostMapping("/api/v1/customers/signUp")
public Result<SignUpResponse> signUp(@RequestBody SignUpRequest signUpRequest) throws Exception{ //회원 가입하는 POST API
Expand All @@ -31,6 +34,9 @@ public Result<SignUpResponse> signUp(@RequestBody SignUpRequest signUpRequest) t
.loginId(signUpRequest.getLoginId())
.password(signUpRequest.getPassword())
.nickname(signUpRequest.getNickname())
.customerNumber(signUpRequest.getCustomerNumber())
.customerDept(signUpRequest.getCustomerDept())
.customerCollege(signUpRequest.getCustomerCollege())
.build();
String id = customerSignUpService.signUp(customer);
return new Result<>(Result.CODE_SUCCESS,Result.MESSAGE_OK, new SignUpResponse(id));
Expand All @@ -55,6 +61,23 @@ public Result<String> certifyCustomer(@RequestBody CertifyCustomerRequest certif
return new Result<>(Result.CODE_SUCCESS, Result.MESSAGE_OK, null);
}

@GetMapping("/api/v1/customers/unauthorizedCustomers")
public Result<List<UnauthorizedCustomer>> getUnauthorizedCustomers() throws Exception {

List<Customer> unauthorizedCustomers = getUnauthorizedCustomersService.getUnauthorizedCustomers();
List<UnauthorizedCustomer> responses = unauthorizedCustomers.stream()
.map(unauthorizedCustomer -> new UnauthorizedCustomer(
unauthorizedCustomer.getId(),
unauthorizedCustomer.getCustomerNumber(),
unauthorizedCustomer.getCustomerDept(),
unauthorizedCustomer.getCustomerCollege(),
unauthorizedCustomer.getCustomerImage()
))
.collect(Collectors.toList());

return new Result<>(Result.CODE_SUCCESS, Result.MESSAGE_OK, responses);
}

@GetMapping(value = "/image/view", produces = {"image/jpeg", "image/png", "image/gif"})
public byte[] getImage(@RequestParam("customerStoredImage") String customerStoredImage) throws IOException {
FileInputStream fis = null; //파일로부터 바이트로 입력받기
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package iampotato.iampotato.domain.customer.application;


import iampotato.iampotato.domain.customer.dao.CustomerRepository;
import iampotato.iampotato.domain.customer.domain.Customer;
import iampotato.iampotato.domain.customer.dto.UnauthorizedCustomer;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class GetUnauthorizedCustomersService {
private final CustomerRepository customerRepository;

public List<Customer> getUnauthorizedCustomers() {
List<Customer> unauthorizedCustomers = customerRepository.findUnauthorizedCustomers();
return unauthorizedCustomers;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package iampotato.iampotato.domain.customer.dao;
import iampotato.iampotato.domain.customer.domain.Customer;
import iampotato.iampotato.domain.customer.domain.CustomerStatus;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
import javax.persistence.EntityManager;
Expand Down Expand Up @@ -39,6 +40,17 @@ public Optional<Customer> findById(String username) {
.getResultList();
return result.stream().findAny();
}

public List<Customer> findUnauthorizedCustomers() {
List<Customer> result = em.createQuery("select c from Customer c" +
" where c.customerImage.customerStoredImage != NULL" +
" and c.customerStatus = :customerStatus", Customer.class)
.setParameter("customerStatus", CustomerStatus.UNAUTHORIZED)
.getResultList();

return result;
}

public void delete(Customer customer) {
em.remove(customer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,14 @@ public class Customer implements UserDetails {

private LocalDateTime createdDate;
private LocalDateTime modifiedDate;

@NotNull
private String customerNumber;

@NotNull
private String customerDept;

@NotNull
private String customerCollege;
private String customerGrade;
@Embedded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ public class SignUpRequest { //회원 가입시 RequestBody
private String loginId;
private String password;
private String nickname;
private String customerNumber;
private String customerDept;
private String customerCollege;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package iampotato.iampotato.domain.customer.dto;

import iampotato.iampotato.domain.customer.domain.CustomerImage;
import lombok.Data;

@Data
public class UnauthorizedCustomer {
private String id;
private String customerNumber;
private String customerDept;
private String customerCollege;
private CustomerImage customerImage;

public UnauthorizedCustomer(String id, String customerNumber, String customerDept, String customerCollege, CustomerImage customerImage) {
this.id = id;
this.customerNumber = customerNumber;
this.customerDept = customerDept;
this.customerCollege = customerCollege;
this.customerImage = customerImage;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package iampotato.iampotato.domain.owner.dao;

import iampotato.iampotato.domain.owner.domain.Owner;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;

@Repository
@RequiredArgsConstructor
public class OwnerRepository {

private final EntityManager em;

public Owner findById(String id) {
return em.find(Owner.class, id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package iampotato.iampotato.domain.ownerstore.application;

import iampotato.iampotato.domain.owner.domain.Owner;
import iampotato.iampotato.domain.ownerstore.dao.OwnerStoreRepository;
import iampotato.iampotato.domain.ownerstore.domain.OwnerStore;
import iampotato.iampotato.domain.store.domain.Store;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class OwnerStoreService {

private final OwnerStoreRepository ownerStoreRepository;

@Transactional
public void registerOwnerStore(Store store, Owner owner) {

OwnerStore ownerStore = OwnerStore.builder()
.store(store)
.owner(owner)
.build();

ownerStoreRepository.save(ownerStore);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package iampotato.iampotato.domain.ownerstore.dao;

import iampotato.iampotato.domain.ownerstore.domain.OwnerStore;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;

@Repository
@RequiredArgsConstructor
public class OwnerStoreRepository {

private final EntityManager em;

public void save(OwnerStore ownerStore) {
em.persist(ownerStore);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

import iampotato.iampotato.domain.owner.domain.Owner;
import iampotato.iampotato.domain.store.domain.Store;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;

import javax.persistence.*;

@Entity
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class OwnerStore {

@Id @GeneratedValue
@Id
@GeneratedValue
@Column(name = "owner_store_id")
private Long id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@Getter
@Builder
@AllArgsConstructor
public class ReviewResultOfCafe {
public class ReviewResult {

private int allNum;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public int countAllOfCafe() {
countManyOutlet();
}

public ReviewResultOfCafe getReviewResultOfCafe() {
return ReviewResultOfCafe.builder()
public ReviewResult getReviewResultOfCafe() {
return ReviewResult.builder()
.greatBeverageNum(countGreatBeverage())
.greatCoffeeNum(countGreatCoffee())
.greatFoodNum(countGreatFood())
Expand Down
43 changes: 29 additions & 14 deletions src/main/java/iampotato/iampotato/domain/store/api/StoreApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@
import iampotato.iampotato.domain.store.dto.map.StoreMapResponse;
import iampotato.iampotato.domain.store.dto.maplist.StoreMapListRequest;
import iampotato.iampotato.domain.store.dto.maplist.StoreMapListResponse;
import iampotato.iampotato.domain.store.dto.register.StoreRegistrationRequest;
import iampotato.iampotato.domain.store.dto.register.StoreRegistrationResponse;
import iampotato.iampotato.domain.store.dto.search.StoreSearchRequest;
import iampotato.iampotato.domain.store.dto.search.StoreSearchResponse;
import iampotato.iampotato.domain.store.dto.todaydiscount.StoreTodayDiscountRequest;
import iampotato.iampotato.domain.store.dto.todaydiscount.StoreTodayDiscountResponse;
import iampotato.iampotato.domain.store.dto.update.StoreUpdateRequest;
import iampotato.iampotato.domain.store.dto.update.StoreUpdateResponse;
import iampotato.iampotato.global.util.Result;
import iampotato.iampotato.global.util.SecurityUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
Expand All @@ -32,17 +37,27 @@ public class StoreApi {

/**
* 가게 정보 등록 POST API
* 가게 정보를 등록할려면 admin Page 에서 데이터를 받아야 하는데
* 아직 갈길이 머므로 껍데기만 만들었습니다.
*/
// @PostMapping("api/v1/stores")
// public StoreRegistrationResponse registerStore(@RequestBody StoreRegistrationResponse storeRegistrationResponse) {
//
// Store store = Store.createStoreWithRequiredValue();
// Long id = storeService.registerStore(store);
//
// return new StoreRegistrationResponse(id);
// }
@PostMapping("api/v1/stores")
public Result<StoreRegistrationResponse> registerStore(@RequestBody StoreRegistrationRequest request) {

Store store = storeService.registerStore(SecurityUtil.getCurrentUserId(), request);
StoreRegistrationResponse response = new StoreRegistrationResponse(store);

return new Result<>(Result.CODE_SUCCESS, Result.MESSAGE_OK, response);
}

/**
* 가게 정보 등록 UPDATE API
*/
@PutMapping("api/v1/stores")
public Result<StoreUpdateResponse> updateStore(@RequestBody StoreUpdateRequest request) {

Store store = storeService.updateStore(request);
StoreUpdateResponse response = new StoreUpdateResponse(store);

return new Result<>(Result.CODE_SUCCESS, Result.MESSAGE_OK, response);
}

/**
* 위치정보를 받으면 해당 위치에서 특정반경 이내에 있는 가게정보를 반환합니다.
Expand Down Expand Up @@ -106,8 +121,8 @@ public Result<List<StoreTodayDiscountResponse>> findStoresByDiscountDayForTodayD
@Operation(summary = "가게세부정보", description = "가게 전체 정보를 가져오는 api 입니다.")
@GetMapping("api/v1/stores/detail")
public Result<StoreDetailResponse> findStoreDetail(StoreDetailRequest storeDetailRequest,
@RequestParam(value = "offset", defaultValue = "0") int offset,
@RequestParam(value = "limit", defaultValue = "100") int limit) {
@RequestParam(value = "offset", defaultValue = "0") int offset,
@RequestParam(value = "limit", defaultValue = "100") int limit) {

Store store = storeService.findByIdV2(storeDetailRequest.getId(), offset, limit);
StoreDetailResponse storeDetailResponse = new StoreDetailResponse(store);
Expand All @@ -119,8 +134,8 @@ public Result<StoreDetailResponse> findStoreDetail(StoreDetailRequest storeDetai
@Operation(summary = "가게 및 아이템 검색", description = "검색어 기준 가게이름과 아이템이름에 매칭되는것을 반환하는 api 입니다.")
@GetMapping("api/v1/stores/name")
public Result<List<StoreSearchResponse>> searchStoreBy(StoreSearchRequest storeSearchRequest,
@RequestParam(value = "offset", defaultValue = "0") int offset,
@RequestParam(value = "limit", defaultValue = "100") int limit) {
@RequestParam(value = "offset", defaultValue = "0") int offset,
@RequestParam(value = "limit", defaultValue = "100") int limit) {

List<Store> stores = storeService.searchStoresBy(storeSearchRequest.getName());
List<StoreSearchResponse> storeSearchResponses = stores.stream()
Expand Down
Loading

0 comments on commit a3f951d

Please sign in to comment.