-
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.
* feature: 관심사 목록 조회 구현 * style: 개행 제거 * feature: 관심사 생성 구현
- Loading branch information
Showing
12 changed files
with
204 additions
and
3 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
22 changes: 22 additions & 0 deletions
22
src/main/java/daybyquest/interest/application/GetInterestsService.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 daybyquest.interest.application; | ||
|
||
import daybyquest.interest.domain.Interests; | ||
import daybyquest.interest.dto.response.InterestResponse; | ||
import daybyquest.interest.dto.response.MultiInterestResponse; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
public class GetInterestsService { | ||
|
||
private final Interests interests; | ||
|
||
public GetInterestsService(final Interests interests) { | ||
this.interests = interests; | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public MultiInterestResponse invoke() { | ||
return new MultiInterestResponse(interests.findAll().stream().map(InterestResponse::of).toList()); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/daybyquest/interest/application/SaveInterestService.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 daybyquest.interest.application; | ||
|
||
import daybyquest.global.utils.MultipartFileUtils; | ||
import daybyquest.image.vo.Image; | ||
import daybyquest.image.vo.ImageIdentifierGenerator; | ||
import daybyquest.image.vo.Images; | ||
import daybyquest.interest.domain.Interest; | ||
import daybyquest.interest.domain.Interests; | ||
import daybyquest.interest.dto.request.SaveInterestRequest; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@Service | ||
public class SaveInterestService { | ||
|
||
private static final String CATEGORY = "INTEREST"; | ||
|
||
private final Interests interests; | ||
|
||
private final Images images; | ||
|
||
private final ImageIdentifierGenerator generator; | ||
|
||
public SaveInterestService(final Interests interests, final Images images, | ||
final ImageIdentifierGenerator generator) { | ||
this.interests = interests; | ||
this.images = images; | ||
this.generator = generator; | ||
} | ||
|
||
@Transactional | ||
public void invoke(final SaveInterestRequest request, final MultipartFile file) { | ||
final String identifier = generator.generateIdentifier(CATEGORY, file.getOriginalFilename()); | ||
images.upload(identifier, MultipartFileUtils.getInputStream(file)); | ||
final Interest interest = new Interest(request.getName(), new Image(identifier)); | ||
interests.save(interest); | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
src/main/java/daybyquest/interest/dto/request/SaveInterestRequest.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,13 @@ | ||
package daybyquest.interest.dto.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class SaveInterestRequest { | ||
|
||
@NotBlank | ||
private String name; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/daybyquest/interest/dto/response/InterestResponse.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,23 @@ | ||
package daybyquest.interest.dto.response; | ||
|
||
import daybyquest.interest.domain.Interest; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class InterestResponse { | ||
|
||
private String name; | ||
|
||
private String imageIdentifier; | ||
|
||
private InterestResponse(final String name, final String imageIdentifier) { | ||
this.name = name; | ||
this.imageIdentifier = imageIdentifier; | ||
} | ||
|
||
public static InterestResponse of(final Interest interest) { | ||
return new InterestResponse(interest.getName(), interest.getImageIdentifier()); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/daybyquest/interest/dto/response/MultiInterestResponse.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 daybyquest.interest.dto.response; | ||
|
||
import java.util.List; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class MultiInterestResponse { | ||
|
||
private List<InterestResponse> interests; | ||
|
||
public MultiInterestResponse(final List<InterestResponse> interests) { | ||
this.interests = interests; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/daybyquest/interest/presentation/InterestCommandApi.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,31 @@ | ||
package daybyquest.interest.presentation; | ||
|
||
import daybyquest.auth.Authorization; | ||
import daybyquest.auth.domain.AccessUser; | ||
import daybyquest.interest.application.SaveInterestService; | ||
import daybyquest.interest.dto.request.SaveInterestRequest; | ||
import jakarta.validation.Valid; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestPart; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@RestController | ||
public class InterestCommandApi { | ||
|
||
private final SaveInterestService saveInterestService; | ||
|
||
public InterestCommandApi(final SaveInterestService saveInterestService) { | ||
this.saveInterestService = saveInterestService; | ||
} | ||
|
||
@PostMapping("/interest") | ||
@Authorization(admin = true) | ||
public ResponseEntity<Void> saveInterest(final AccessUser user, | ||
@RequestPart("image") final MultipartFile file, | ||
@RequestPart("request") @Valid final SaveInterestRequest request) { | ||
saveInterestService.invoke(request, file); | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/daybyquest/interest/presentation/InterestQueryApi.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,23 @@ | ||
package daybyquest.interest.presentation; | ||
|
||
import daybyquest.interest.application.GetInterestsService; | ||
import daybyquest.interest.dto.response.MultiInterestResponse; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class InterestQueryApi { | ||
|
||
private final GetInterestsService getInterestsService; | ||
|
||
public InterestQueryApi(final GetInterestsService getInterestsService) { | ||
this.getInterestsService = getInterestsService; | ||
} | ||
|
||
@GetMapping("/interest") | ||
public ResponseEntity<MultiInterestResponse> getInterests() { | ||
final MultiInterestResponse response = getInterestsService.invoke(); | ||
return ResponseEntity.ok(response); | ||
} | ||
} |