Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/main/java/com/example/api/account/entity/Location.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

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

import java.util.Objects;

@Entity
@Getter
@ToString
public class Location {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -25,4 +29,17 @@ public Location(String zipcode, String address, String detailAddress) {
this.address = address;
this.detailAddress = detailAddress;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Location location = (Location) o;
return Objects.equals(id, location.id);
}

@Override
public int hashCode() {
return Objects.hash(id);
}
}
10 changes: 7 additions & 3 deletions src/main/java/com/example/api/business/BusinessRepository.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package com.example.api.business;

import com.example.api.domain.Business;
import java.util.Optional;
import com.example.api.employer.controller.dto.EmployerBusinessesRequest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

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

@Repository
public interface BusinessRepository extends JpaRepository<Business, Long> {

@Query("SELECT b FROM Business b JOIN FETCH b.employer JOIN FETCH b.businessCategories WHERE b.businessId = :businessId")
Optional<Business> getDetails(@Param("businessId") final Long businessId);

}
@Query("select new com.example.api.employer.controller.dto.EmployerBusinessesRequest(b.businessName, b.location) from Business b where b.employer.accountId = :employerId order by b.location.id")
List<EmployerBusinessesRequest> findBusinessesByEmployeeId(@Param("employerId")final Long employerId);
}
12 changes: 7 additions & 5 deletions src/main/java/com/example/api/domain/Business.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class Business extends BaseEntity {
private String businessName;

@OneToOne(fetch = LAZY)
@JoinColumn(name = "BUSINESS_LOCATION")
@JoinColumn(name = "BUSINESS_LOCATION", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private Location location;

private String representationName;
Expand Down Expand Up @@ -79,8 +79,10 @@ public Business(String businessName, Location location, String representationNam
this.openDate = openDate;
this.registrationNumber = registrationNumber;
}
}




public Business(Account employer, String businessName, Location location) {
this.employer = employer;
this.businessName = businessName;
this.location = location;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.api.employer.controller;

import com.example.api.board.dto.request.EmployeeIdRequest;
import com.example.api.employer.controller.dto.EmployerBusinessesRequest;
import com.example.api.employer.controller.dto.LikeEmployeeDTO;
import com.example.api.employer.service.EmployerService;
import lombok.RequiredArgsConstructor;
Expand All @@ -11,15 +12,22 @@

import java.util.List;

@RestController
@RestController("/api/v1/employees/")
@RequiredArgsConstructor
public class EmployerController {
private final EmployerService employerService;

@GetMapping("/api/v1/employees/favorites/{employerId}")
@GetMapping("favorites/{employerId}")
public ResponseEntity getLikeEmployee(@PathVariable() Long employerId) {
EmployeeIdRequest employeeIdRequest = new EmployeeIdRequest(employerId);
List<LikeEmployeeDTO> result = employerService.getLikeEmployee(employeeIdRequest);
return ResponseEntity.ok(result);
}

@GetMapping("businesses/{employerId}")
public ResponseEntity getEmployeeBusinessList(@PathVariable Long employerId) {
EmployeeIdRequest employeeIdRequest = new EmployeeIdRequest(employerId);
List<EmployerBusinessesRequest> businesses = employerService.getEmployerBusinessList(employeeIdRequest);
return ResponseEntity.ok(businesses);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.api.employer.controller.dto;

import com.example.api.account.entity.Location;
import jakarta.validation.constraints.NotNull;

public record EmployerBusinessesRequest(
@NotNull String businessName,
@NotNull Location businessLocation
) {
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.example.api.employer.service;

import com.example.api.board.dto.request.EmployeeIdRequest;
import com.example.api.business.BusinessRepository;
import com.example.api.domain.repository.EmployeeRepository;
import com.example.api.domain.repository.ExternalCareerRepository;
import com.example.api.domain.repository.FlavoredRepository;
import com.example.api.domain.Account;
import com.example.api.employer.controller.dto.EmployerBusinessesRequest;
import com.example.api.employer.controller.dto.LikeEmployeeDTO;
import com.example.api.employer.repository.ScrapRepository;
import lombok.RequiredArgsConstructor;
Expand All @@ -22,6 +24,7 @@ public class EmployerService {
private final EmployeeRepository employeeRepository;
private final ExternalCareerRepository externalCareerRepository;
private final FlavoredRepository flavoredRepository;
private final BusinessRepository businessRepository;

@Transactional(readOnly = true)
public List<LikeEmployeeDTO> getLikeEmployee(final EmployeeIdRequest employeeIdRequest) {
Expand All @@ -43,4 +46,9 @@ public List<LikeEmployeeDTO> getLikeEmployee(final EmployeeIdRequest employeeIdR
)
).collect(Collectors.toList());
}

@Transactional(readOnly = true)
public List<EmployerBusinessesRequest> getEmployerBusinessList(final EmployeeIdRequest employeeIdRequest) {
return businessRepository.findBusinessesByEmployeeId(employeeIdRequest.employeeId());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.example.api.employer.service;

import com.example.api.account.entity.Location;
import com.example.api.account.repository.AccountRepository;
import com.example.api.account.repository.LocationRepository;
import com.example.api.board.dto.request.EmployeeIdRequest;
import com.example.api.business.BusinessRepository;
import com.example.api.domain.Account;
import com.example.api.domain.Business;
import com.example.api.employer.controller.dto.EmployerBusinessesRequest;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

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

@SpringBootTest
class EmployerServiceTest {
@Autowired
private EmployerService employerService;
@Autowired
private AccountRepository accountRepository;
@Autowired
private BusinessRepository businessRepository;
@Autowired
private LocationRepository locationRepository;
private List<EmployerBusinessesRequest> businessesList = new ArrayList<>();

@BeforeEach
void setUp() {
Account account = new Account();
accountRepository.save(account);
Location location1 = new Location("zipcode1", "address1", "detailAddress1");
Location location2 = new Location("zipcode2", "address2", "detailAddress2");
Location location3 = new Location("zipcode3", "address3", "detailAddress3");
locationRepository.save(location1);
locationRepository.save(location2);
locationRepository.save(location3);
Business business1 = new Business(account, "가게명1", location1);
Business business2 = new Business(account, "가게명2", location2);
Business business3 = new Business(account, "가게명3", location3);
businessRepository.save(business1);
businessRepository.save(business2);
businessRepository.save(business3);
businessesList.add(new EmployerBusinessesRequest(business1.getBusinessName(), business1.getLocation()));
businessesList.add(new EmployerBusinessesRequest(business2.getBusinessName(), business2.getLocation()));
businessesList.add(new EmployerBusinessesRequest(business3.getBusinessName(), business3.getLocation()));
}

@Test
void testGetBusinessesByOwnerId(){
List<EmployerBusinessesRequest> employerBusinessList = employerService.getEmployerBusinessList(new EmployeeIdRequest(1L));
Assertions.assertThat(employerBusinessList).isEqualTo(businessesList);
}
}
Empty file.
Loading
Loading