-
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.
Showing
36 changed files
with
868 additions
and
307 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,4 @@ out/ | |
|
||
### VS Code ### | ||
.vscode/ | ||
logs/spring-boot.log |
Binary file not shown.
141 changes: 72 additions & 69 deletions
141
src/main/java/com/ureca/sole_paradise/community/controller/CommunityCommentController.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,69 +1,72 @@ | ||
//package com.ureca.sole_paradise.community.controller; | ||
// | ||
//import java.util.List; | ||
// | ||
//import org.springframework.http.HttpStatus; | ||
//import org.springframework.http.MediaType; | ||
//import org.springframework.http.ResponseEntity; | ||
//import org.springframework.web.bind.annotation.DeleteMapping; | ||
//import org.springframework.web.bind.annotation.GetMapping; | ||
//import org.springframework.web.bind.annotation.PathVariable; | ||
//import org.springframework.web.bind.annotation.PostMapping; | ||
//import org.springframework.web.bind.annotation.PutMapping; | ||
//import org.springframework.web.bind.annotation.RequestBody; | ||
//import org.springframework.web.bind.annotation.RequestMapping; | ||
//import org.springframework.web.bind.annotation.RestController; | ||
// | ||
//import com.ureca.sole_paradise.community.db.dto.CommunityCommentDTO; | ||
//import com.ureca.sole_paradise.community.service.CommunityCommentService; | ||
// | ||
//import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
//import jakarta.validation.Valid; | ||
// | ||
//@RestController | ||
//@RequestMapping(value = "/api/communityComments", produces = MediaType.APPLICATION_JSON_VALUE) | ||
//public class CommunityCommentController { | ||
// | ||
// private final CommunityCommentService communityCommentService; | ||
// | ||
// public CommunityCommentController(final CommunityCommentService communityCommentService) { | ||
// this.communityCommentService = communityCommentService; | ||
// } | ||
// | ||
// @GetMapping | ||
// public ResponseEntity<List<CommunityCommentDTO>> getAllCommunityComments() { | ||
// return ResponseEntity.ok(communityCommentService.findAll()); | ||
// } | ||
// | ||
// @GetMapping("/{commentId}") | ||
// public ResponseEntity<CommunityCommentDTO> getCommunityComment( | ||
// @PathVariable(name = "commentId") final Integer commentId) { | ||
// return ResponseEntity.ok(communityCommentService.get(commentId)); | ||
// } | ||
// | ||
// @PostMapping | ||
// @ApiResponse(responseCode = "201") | ||
// public ResponseEntity<Integer> createCommunityComment( | ||
// @RequestBody @Valid final CommunityCommentDTO communityCommentDTO) { | ||
// final Integer createdCommentId = communityCommentService.create(communityCommentDTO); | ||
// return new ResponseEntity<>(createdCommentId, HttpStatus.CREATED); | ||
// } | ||
// | ||
// @PutMapping("/{commentId}") | ||
// public ResponseEntity<Integer> updateCommunityComment( | ||
// @PathVariable(name = "commentId") final Integer commentId, | ||
// @RequestBody @Valid final CommunityCommentDTO communityCommentDTO) { | ||
// communityCommentService.update(commentId, communityCommentDTO); | ||
// return ResponseEntity.ok(commentId); | ||
// } | ||
// | ||
// @DeleteMapping("/{commentId}") | ||
// @ApiResponse(responseCode = "204") | ||
// public ResponseEntity<Void> deleteCommunityComment( | ||
// @PathVariable(name = "commentId") final Integer commentId) { | ||
// communityCommentService.delete(commentId); | ||
// return ResponseEntity.noContent().build(); | ||
// } | ||
// | ||
// | ||
//} | ||
package com.ureca.sole_paradise.community.controller; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.CrossOrigin; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.ureca.sole_paradise.community.db.dto.CommunityCommentDTO; | ||
import com.ureca.sole_paradise.community.service.CommunityCommentService; | ||
|
||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import jakarta.validation.Valid; | ||
|
||
@CrossOrigin("*") | ||
@RestController | ||
@RequestMapping(value = "/api/communityComments", produces = MediaType.APPLICATION_JSON_VALUE) | ||
public class CommunityCommentController { | ||
|
||
private final CommunityCommentService communityCommentService; | ||
|
||
public CommunityCommentController(final CommunityCommentService communityCommentService) { | ||
this.communityCommentService = communityCommentService; | ||
} | ||
|
||
@GetMapping | ||
public ResponseEntity<List<CommunityCommentDTO>> getAllCommunityComments() { | ||
return ResponseEntity.ok(communityCommentService.findAll()); | ||
} | ||
|
||
@GetMapping("/{commentId}") | ||
public ResponseEntity<CommunityCommentDTO> getCommunityComment( | ||
@PathVariable(name = "commentId") final Integer commentId) { | ||
return ResponseEntity.ok(communityCommentService.get(commentId)); | ||
} | ||
|
||
@PostMapping | ||
@ApiResponse(responseCode = "201") | ||
public ResponseEntity<Integer> createCommunityComment( | ||
@RequestBody @Valid final CommunityCommentDTO communityCommentDTO) { | ||
final Integer createdCommentId = communityCommentService.create(communityCommentDTO); | ||
return new ResponseEntity<>(createdCommentId, HttpStatus.CREATED); | ||
} | ||
|
||
@PutMapping("/{commentId}") | ||
public ResponseEntity<Integer> updateCommunityComment( | ||
@PathVariable(name = "commentId") final Integer commentId, | ||
@RequestBody @Valid final CommunityCommentDTO communityCommentDTO) { | ||
communityCommentService.update(commentId, communityCommentDTO); | ||
return ResponseEntity.ok(commentId); | ||
} | ||
|
||
@DeleteMapping("/{commentId}") | ||
@ApiResponse(responseCode = "204") | ||
public ResponseEntity<Void> deleteCommunityComment( | ||
@PathVariable(name = "commentId") final Integer commentId) { | ||
communityCommentService.delete(commentId); | ||
return ResponseEntity.noContent().build(); | ||
} | ||
|
||
|
||
} | ||
|
188 changes: 120 additions & 68 deletions
188
src/main/java/com/ureca/sole_paradise/community/controller/CommunityController.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,76 +1,128 @@ | ||
//package com.ureca.sole_paradise.community.controller; | ||
// | ||
//import java.util.List; | ||
// | ||
//import org.springframework.http.HttpStatus; | ||
//import org.springframework.http.MediaType; | ||
//import org.springframework.http.ResponseEntity; | ||
//import org.springframework.web.bind.annotation.DeleteMapping; | ||
//import org.springframework.web.bind.annotation.GetMapping; | ||
//import org.springframework.web.bind.annotation.PathVariable; | ||
//import org.springframework.web.bind.annotation.PostMapping; | ||
//import org.springframework.web.bind.annotation.PutMapping; | ||
//import org.springframework.web.bind.annotation.RequestBody; | ||
//import org.springframework.web.bind.annotation.RequestMapping; | ||
//import org.springframework.web.bind.annotation.RestController; | ||
// | ||
////import io.bootify.back_end01.model.CommunityDTO; | ||
////import io.bootify.back_end01.service.CommunityService; | ||
////import io.bootify.back_end01.util.ReferencedException; | ||
////import io.bootify.back_end01.util.ReferencedWarning; | ||
////import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
////import jakarta.validation.Valid; | ||
// | ||
//@RestController | ||
//@RequestMapping(value = "/api/communities", produces = MediaType.APPLICATION_JSON_VALUE) | ||
//public class CommunityController { | ||
// | ||
// | ||
// private final CommunityService communityService; | ||
// | ||
// public CommunityResource(final CommunityService communityService) { | ||
// this.communityService = communityService; | ||
// } | ||
// | ||
// @GetMapping | ||
// public ResponseEntity<List<CommunityDTO>> getAllCommunities() { | ||
// return ResponseEntity.ok(communityService.findAll()); | ||
// } | ||
// | ||
// @GetMapping("/{postId}") | ||
// public ResponseEntity<CommunityDTO> getCommunity( | ||
// @PathVariable(name = "postId") final Integer postId) { | ||
// return ResponseEntity.ok(communityService.get(postId)); | ||
// } | ||
// | ||
package com.ureca.sole_paradise.community.controller; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.time.OffsetDateTime; | ||
import java.util.List; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.CrossOrigin; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import com.ureca.sole_paradise.community.db.dto.CommunityDTO; | ||
import com.ureca.sole_paradise.community.service.CommunityService; | ||
import com.ureca.sole_paradise.util.ReferencedException; | ||
import com.ureca.sole_paradise.util.ReferencedWarning; | ||
|
||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import jakarta.validation.Valid; | ||
|
||
@RestController | ||
@CrossOrigin("*") | ||
@RequestMapping(value = "/api/communities", produces = MediaType.APPLICATION_JSON_VALUE) | ||
public class CommunityController { | ||
|
||
|
||
private final CommunityService communityService; | ||
|
||
public CommunityController(final CommunityService communityService) { | ||
this.communityService = communityService; | ||
} | ||
//목록 | ||
@GetMapping | ||
public ResponseEntity<List<CommunityDTO>> getAllCommunities() { | ||
return ResponseEntity.ok(communityService.findAll()); | ||
} | ||
// 상세 | ||
@GetMapping("/{postId}") | ||
public ResponseEntity<CommunityDTO> getCommunity( | ||
@PathVariable(name = "postId") final Integer postId) { | ||
return ResponseEntity.ok(communityService.get(postId)); | ||
} | ||
//등록 | ||
// @PostMapping | ||
// @ApiResponse(responseCode = "201") | ||
// public ResponseEntity<Integer> createCommunity( | ||
// @RequestBody @Valid final CommunityDTO communityDTO) { | ||
// final Integer createdPostId = communityService.create(communityDTO); | ||
// return new ResponseEntity<>(createdPostId, HttpStatus.CREATED); | ||
// } | ||
// | ||
// @PutMapping("/{postId}") | ||
// public ResponseEntity<Integer> updateCommunity( | ||
// @PathVariable(name = "postId") final Integer postId, | ||
// @RequestBody @Valid final CommunityDTO communityDTO) { | ||
// communityService.update(postId, communityDTO); | ||
// return ResponseEntity.ok(postId); | ||
// } | ||
// | ||
// @DeleteMapping("/{postId}") | ||
// @ApiResponse(responseCode = "204") | ||
// public ResponseEntity<Void> deleteCommunity( | ||
// @PathVariable(name = "postId") final Integer postId) { | ||
// final ReferencedWarning referencedWarning = communityService.getReferencedWarning(postId); | ||
// if (referencedWarning != null) { | ||
// throw new ReferencedException(referencedWarning); | ||
// } | ||
// communityService.delete(postId); | ||
// return ResponseEntity.noContent().build(); | ||
// } | ||
// | ||
// | ||
//} | ||
//수정 | ||
@PutMapping("/{postId}") | ||
public ResponseEntity<Integer> updateCommunity( | ||
@PathVariable(name = "postId") final Integer postId, | ||
@RequestBody @Valid final CommunityDTO communityDTO) { | ||
communityService.update(postId, communityDTO); | ||
return ResponseEntity.ok(postId); | ||
} | ||
//삭제 | ||
@DeleteMapping("/{postId}") | ||
@ApiResponse(responseCode = "204") | ||
public ResponseEntity<Void> deleteCommunity( | ||
@PathVariable(name = "postId") final Integer postId) { | ||
final ReferencedWarning referencedWarning = communityService.getReferencedWarning(postId); | ||
if (referencedWarning != null) { | ||
throw new ReferencedException(referencedWarning); | ||
} | ||
communityService.delete(postId); | ||
return ResponseEntity.noContent().build(); | ||
} | ||
|
||
|
||
|
||
|
||
// 사진 업로드 등록 | ||
|
||
private static final String UPLOAD_DIR = "src/main/resources/static/uploads/";; | ||
@PostMapping | ||
public ResponseEntity<?> uploadPet(@RequestParam("title") String title, | ||
@RequestParam("contents") String contents, | ||
@RequestParam("user") Integer user, | ||
@RequestParam("createdAt") OffsetDateTime createdAt, | ||
@RequestParam(value = "imageUrl", required = false) MultipartFile file){ | ||
try { | ||
CommunityDTO communityDTO = new CommunityDTO(); | ||
communityDTO.setTitle(title); | ||
communityDTO.setContents(contents); | ||
communityDTO.setCreatedAt(createdAt); | ||
communityDTO.setUser(user); // user ID 설정 | ||
|
||
if (file != null && !file.isEmpty()) { | ||
String fileName = System.currentTimeMillis()+"";// + "_" + file.getOriginalFilename(); | ||
String[] exts = file.getOriginalFilename().split("\\."); | ||
String ext = exts[exts.length-1];//확장자 | ||
Path filePath = Paths.get(UPLOAD_DIR + fileName+"."+ext); | ||
Files.createDirectories(filePath.getParent()); | ||
Files.copy(file.getInputStream(), filePath); | ||
String fp = filePath.toString(); | ||
System.out.println("fp="+fp); | ||
int staticIndex = fp.lastIndexOf("uploads"); | ||
String ss = fp.substring(staticIndex+8); | ||
communityDTO.setImageUrl(ss); // 파일 이름만 저장 | ||
System.out.println("ss="+ss); | ||
} | ||
|
||
final Integer createdpostId = communityService.create(communityDTO); | ||
return new ResponseEntity<>(createdpostId, HttpStatus.CREATED); | ||
|
||
} catch (IOException e) { | ||
return ResponseEntity.internalServerError().body("Could not upload the petItem: " + e.getMessage()); | ||
} | ||
} | ||
|
||
|
||
|
||
} |
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
Oops, something went wrong.