-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from PlanIt-Project/BE
Be
- Loading branch information
Showing
35 changed files
with
1,993 additions
and
173 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
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
44 changes: 44 additions & 0 deletions
44
src/main/java/com/sideProject/PlanIT/domain/file/controller/FileController.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,44 @@ | ||
package com.sideProject.PlanIT.domain.file.controller; | ||
|
||
import com.sideProject.PlanIT.common.response.ApiResponse; | ||
import com.sideProject.PlanIT.domain.file.service.FileService; | ||
import com.sideProject.PlanIT.domain.post.dto.request.NoticeRequestDto; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.io.IOException; | ||
|
||
@RestController | ||
@RequestMapping("/file") | ||
public class FileController { | ||
@Autowired | ||
FileService fileService; | ||
|
||
@PostMapping | ||
public ApiResponse<String> saveFile(@ModelAttribute NoticeRequestDto noticeRequestDto) { | ||
return ApiResponse.ok(fileService.saveFile(noticeRequestDto.getImage())); | ||
} | ||
@GetMapping("/{file_name:.+}") | ||
public ResponseEntity<?> sendFile(@PathVariable String file_name, HttpServletRequest request) { | ||
Resource resource = fileService.sendFile(file_name); | ||
|
||
String contentType = null; | ||
try { | ||
contentType = request.getServletContext().getMimeType(resource.getFile().getAbsolutePath()); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
if (contentType == null) { | ||
contentType = "application/octet-stream"; | ||
} | ||
|
||
return ResponseEntity.ok() | ||
.contentType(MediaType.parseMediaType(contentType)) | ||
.body(resource); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/sideProject/PlanIT/domain/file/service/FileService.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,16 @@ | ||
package com.sideProject.PlanIT.domain.file.service; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.core.io.FileSystemResource; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.UUID; | ||
|
||
public interface FileService { | ||
public String saveFile(MultipartFile file); | ||
public Resource sendFile(String fileName); | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/com/sideProject/PlanIT/domain/file/service/FileServiceImpl.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,54 @@ | ||
package com.sideProject.PlanIT.domain.file.service; | ||
|
||
import com.sideProject.PlanIT.common.response.CustomException; | ||
import com.sideProject.PlanIT.common.response.ErrorCode; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.core.io.FileSystemResource; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.MalformedURLException; | ||
import java.util.UUID; | ||
|
||
@Service | ||
public class FileServiceImpl implements FileService{ | ||
@Value("${spring.fileStorage.dir}") | ||
private String fileStorageDir; | ||
|
||
@Override | ||
public String saveFile(MultipartFile file) { | ||
if (file == null || file.isEmpty()) { | ||
return null; | ||
} | ||
try { | ||
UUID uuid = UUID.randomUUID(); | ||
String fileName = uuid + file.getOriginalFilename(); | ||
File dest = new File(fileStorageDir + File.separator + fileName); | ||
file.transferTo(dest); | ||
|
||
return fileName; | ||
} catch (IOException e) { | ||
return "이미지 업로드 오류 발생"; | ||
} | ||
} | ||
|
||
@Override | ||
public Resource sendFile(String fileName) { | ||
try { | ||
File file = new File(fileStorageDir + File.separator + fileName); | ||
|
||
Resource resource = new FileSystemResource(file); | ||
|
||
if (resource.exists() || resource.isReadable()) { | ||
return resource; | ||
} else { | ||
throw new CustomException(ErrorCode.FILE_NOT_FOUND); | ||
} | ||
} catch (Exception e) { | ||
throw new CustomException(ErrorCode.FILE_NOT_FOUND); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/sideProject/PlanIT/domain/post/controller/BannerAdminController.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 com.sideProject.PlanIT.domain.post.controller; | ||
|
||
import com.sideProject.PlanIT.common.response.ApiResponse; | ||
import com.sideProject.PlanIT.domain.post.dto.request.BannerRequestDto; | ||
import com.sideProject.PlanIT.domain.post.dto.response.BannerResponseDto; | ||
import com.sideProject.PlanIT.domain.post.service.BannerService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/admin/banner") | ||
@RequiredArgsConstructor | ||
public class BannerAdminController { | ||
private final BannerService bannerService; | ||
|
||
@PostMapping | ||
public ApiResponse<String> createBanner(@ModelAttribute BannerRequestDto bannerRequestDto) { | ||
return ApiResponse.ok(bannerService.createBanner(bannerRequestDto)); | ||
} | ||
|
||
@PutMapping("/{banner_id}") | ||
public ApiResponse<String> editBanner(@PathVariable Long banner_id, @ModelAttribute BannerRequestDto bannerRequestDto) { | ||
return ApiResponse.ok(bannerService.editBanner(banner_id, bannerRequestDto)); | ||
} | ||
|
||
@DeleteMapping("/{banner_id}") | ||
public ApiResponse<String> deleteBanner(@PathVariable Long banner_id) { | ||
return ApiResponse.ok(bannerService.deleteBanner(banner_id)); | ||
} | ||
|
||
@GetMapping | ||
public ApiResponse<List<BannerResponseDto>> findAllBanners() { | ||
return ApiResponse.ok(bannerService.findAllBanners()); | ||
} | ||
} |
35 changes: 9 additions & 26 deletions
35
src/main/java/com/sideProject/PlanIT/domain/post/controller/BannerController.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
37 changes: 37 additions & 0 deletions
37
src/main/java/com/sideProject/PlanIT/domain/post/controller/NoticeAdminController.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 com.sideProject.PlanIT.domain.post.controller; | ||
|
||
import com.sideProject.PlanIT.common.response.ApiResponse; | ||
import com.sideProject.PlanIT.domain.post.dto.request.NoticeRequestDto; | ||
import com.sideProject.PlanIT.domain.post.dto.response.NoticeResponseDto; | ||
import com.sideProject.PlanIT.domain.post.service.NoticeService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/admin/notice") | ||
@RequiredArgsConstructor | ||
public class NoticeAdminController { | ||
private final NoticeService noticeService; | ||
|
||
@PostMapping | ||
public ApiResponse<String> createNotice(@ModelAttribute NoticeRequestDto noticeRequestDto) { | ||
return ApiResponse.ok(noticeService.createNotice(noticeRequestDto)); | ||
} | ||
|
||
@PutMapping("/{notice_id}") | ||
public ApiResponse<String> editNotice(@PathVariable Long notice_id , @ModelAttribute NoticeRequestDto noticeRequestDto) { | ||
return ApiResponse.ok(noticeService.editNotice(notice_id, noticeRequestDto)); | ||
} | ||
|
||
@DeleteMapping("/{notice_id}") | ||
public ApiResponse<String> deleteNotice(@PathVariable Long notice_id) { | ||
return ApiResponse.ok(noticeService.deleteNotice(notice_id)); | ||
} | ||
|
||
@GetMapping | ||
public ApiResponse<List<NoticeResponseDto>> findAllNotices() { | ||
return ApiResponse.ok(noticeService.findAllNotices()); | ||
} | ||
} |
Oops, something went wrong.