-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [FEAT]: Building 상세 정보 조회 API 구현 * [FEAT]: 이미지 업로드 API 구현
- Loading branch information
Showing
15 changed files
with
244 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/org/khtml/hexagonal/domain/building/BlobManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.khtml.hexagonal.domain.building; | ||
|
||
import com.azure.storage.blob.BlobClient; | ||
import com.azure.storage.blob.BlobContainerClient; | ||
import com.azure.storage.blob.BlobServiceClient; | ||
import com.azure.storage.blob.BlobServiceClientBuilder; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.InputStream; | ||
|
||
@Component | ||
public class BlobManager { | ||
|
||
@Value("${azure.storage.account-name}") | ||
private String accountName; | ||
|
||
@Value("${azure.storage.account-key}") | ||
private String accountKey; | ||
|
||
public String storeFile(String filename, InputStream content, long length) { | ||
BlobClient client = containerClient().getBlobClient(filename.trim()); | ||
client.upload(content, length); | ||
return "File uploaded with success!"; | ||
} | ||
|
||
private BlobContainerClient containerClient() { | ||
String connectionString = "DefaultEndpointsProtocol=https;" | ||
+ "AccountName=" + accountName | ||
+ ";AccountKey=" + accountKey | ||
+ ";EndpointSuffix=core.windows.net"; | ||
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder() | ||
.connectionString(connectionString).buildClient(); | ||
return blobServiceClient.getBlobContainerClient("images"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/org/khtml/hexagonal/domain/building/BuildingController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.khtml.hexagonal.domain.building; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.khtml.hexagonal.domain.auth.JwtValidator; | ||
import org.khtml.hexagonal.domain.building.application.BuildingService; | ||
import org.khtml.hexagonal.domain.user.User; | ||
import org.khtml.hexagonal.global.support.response.ApiResponse; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
@RequestMapping("/api/v1/buildings") | ||
@RequiredArgsConstructor | ||
@RestController | ||
public class BuildingController { | ||
|
||
private final BuildingService buildingService; | ||
private final JwtValidator jwtValidator; | ||
|
||
@GetMapping("/{building-id}") | ||
public ApiResponse<BuildingDetailResponse> getBuildingDetail( | ||
@PathVariable(name = "building-id") String buildingId | ||
) { | ||
return ApiResponse.success(BuildingDetailResponse.toResponse(buildingService.getBuilding(buildingId))); | ||
} | ||
|
||
@PostMapping("/{building-id}/register") | ||
public ApiResponse<?> registerBuilding( | ||
@RequestHeader("Authorization") String token, | ||
@RequestParam("images") List<MultipartFile> multipartFiles | ||
) throws IOException { | ||
User requestUser = jwtValidator.getUserFromToken(token); | ||
buildingService.registerBuilding(requestUser, multipartFiles); | ||
return ApiResponse.success(); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/org/khtml/hexagonal/domain/building/BuildingDetailResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.khtml.hexagonal.domain.building; | ||
|
||
public record BuildingDetailResponse( | ||
String buildingId, | ||
String address, | ||
String description, | ||
String phoneNumber, | ||
Integer crackScore, | ||
Integer leakScore, | ||
Integer corrosionScore, | ||
Integer agingScore, | ||
Integer totalScore, | ||
String repairList, | ||
String roofMaterial, | ||
String buildingStructureType, | ||
String wallMaterial, | ||
String windowDoorMaterial | ||
) { | ||
public static BuildingDetailResponse toResponse(Building building) { | ||
return new BuildingDetailResponse( | ||
building.getGisBuildingId(), | ||
building.getLegalDistrictName() + " " + building.getLandLotNumber(), | ||
building.getDescription(), | ||
building.getUser() == null ? null : building.getUser().getPhoneNumber(), | ||
building.getCrackScore(), | ||
building.getLeakScore(), | ||
building.getCorrosionScore(), | ||
building.getAgingScore(), | ||
building.getTotalScore(), | ||
building.getRepairList(), | ||
building.getRoofMaterial(), | ||
building.getBuildingStructureType(), | ||
building.getWallMaterial(), | ||
building.getWindowDoorMaterial() | ||
); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/org/khtml/hexagonal/domain/building/BuildingImage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.khtml.hexagonal.domain.building; | ||
|
||
|
||
import jakarta.persistence.*; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.khtml.hexagonal.domain.common.BaseEntity; | ||
|
||
@Table(name = "building_image") | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Entity | ||
public class BuildingImage extends BaseEntity { | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "building_id") | ||
private Building building; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "image_id") | ||
private Image image; | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/org/khtml/hexagonal/domain/building/BuildingRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
package org.khtml.hexagonal.domain.building; | ||
|
||
import org.springframework.data.jpa.repository.EntityGraph; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface BuildingRepository extends JpaRepository<Building, Long> { | ||
|
||
@EntityGraph(attributePaths = {"user"}) | ||
Optional<Building> findBuildingByGisBuildingId(String gisBuildingId); | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/org/khtml/hexagonal/domain/building/Image.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.khtml.hexagonal.domain.building; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.khtml.hexagonal.domain.common.BaseEntity; | ||
import org.khtml.hexagonal.domain.user.User; | ||
|
||
@Table(name = "image") | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Entity | ||
public class Image extends BaseEntity { | ||
|
||
private String url; | ||
|
||
@OneToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "user_id") | ||
private User user; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/org/khtml/hexagonal/domain/user/UserController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.khtml.hexagonal.domain.user; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RequestMapping("/api/v1/users") | ||
@RequiredArgsConstructor | ||
@RestController | ||
public class UserController { | ||
|
||
private final UserService userService; | ||
|
||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/org/khtml/hexagonal/domain/user/UserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.khtml.hexagonal.domain.user; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
@Service | ||
public class UserService { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters