-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat: λ΄μ¬μ νμκ°μ λ‘μ§μ ꡬννλ€.
- Loading branch information
Showing
26 changed files
with
784 additions
and
5 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
31 changes: 31 additions & 0 deletions
31
src/main/java/com/clova/anifriends/domain/volunteer/controller/VolunteerController.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 com.clova.anifriends.domain.volunteer.controller; | ||
|
||
import com.clova.anifriends.domain.volunteer.dto.request.RegisterVolunteerRequest; | ||
import com.clova.anifriends.domain.volunteer.service.VolunteerService; | ||
import jakarta.validation.Valid; | ||
import java.net.URI; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/volunteers") | ||
public class VolunteerController { | ||
|
||
private final VolunteerService volunteerService; | ||
private static final String BASE_URI = "/api/volunteers/"; | ||
|
||
@PostMapping | ||
public ResponseEntity<Void> registerVolunteer( | ||
@RequestBody @Valid RegisterVolunteerRequest registerVolunteerRequest | ||
) { | ||
Long registeredVolunteerID = volunteerService.registerVolunteer(registerVolunteerRequest); | ||
URI location = URI.create(BASE_URI + registeredVolunteerID); | ||
return ResponseEntity.created(location).build(); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...main/java/com/clova/anifriends/domain/volunteer/dto/request/RegisterVolunteerRequest.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,14 @@ | ||
package com.clova.anifriends.domain.volunteer.dto.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
|
||
public record RegisterVolunteerRequest( | ||
@NotBlank(message = "μ΄λ©μΌμ νμ νλͺ©μ λλ€.") String email, | ||
@NotBlank(message = "λΉλ°λ²νΈλ νμ νλͺ©μ λλ€.") String password, | ||
@NotBlank(message = "μ΄λ¦μ νμ νλͺ©μ λλ€.") String name, | ||
@NotBlank(message = "μλ μμΌμ νμ νλͺ©μ λλ€.") String birthDate, | ||
@NotBlank(message = "μ νλ²νΈλ νμ νλͺ©μ λλ€.") String phoneNumber, | ||
@NotBlank(message = "μ±λ³μ νμ νλͺ©μ λλ€.") String gender | ||
) { | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...ava/com/clova/anifriends/domain/volunteer/exception/NotFoundVolunteerGenderException.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,10 @@ | ||
package com.clova.anifriends.domain.volunteer.exception; | ||
|
||
import com.clova.anifriends.global.exception.NotFoundException; | ||
|
||
public class NotFoundVolunteerGenderException extends NotFoundException { | ||
|
||
public NotFoundVolunteerGenderException(String message) { | ||
super(message); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...in/java/com/clova/anifriends/domain/volunteer/exception/VolunteerBadRequestException.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,10 @@ | ||
package com.clova.anifriends.domain.volunteer.exception; | ||
|
||
import com.clova.anifriends.global.exception.BadRequestException; | ||
|
||
public class VolunteerBadRequestException extends BadRequestException { | ||
|
||
public VolunteerBadRequestException(String message) { | ||
super(message); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/clova/anifriends/domain/volunteer/repository/VolunteerImageRepository.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,8 @@ | ||
package com.clova.anifriends.domain.volunteer.repository; | ||
|
||
import com.clova.anifriends.domain.volunteer.VolunteerImage; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface VolunteerImageRepository extends JpaRepository<VolunteerImage, Long> { | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/clova/anifriends/domain/volunteer/service/VolunteerService.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,30 @@ | ||
package com.clova.anifriends.domain.volunteer.service; | ||
|
||
import com.clova.anifriends.domain.volunteer.Volunteer; | ||
import com.clova.anifriends.domain.volunteer.dto.request.RegisterVolunteerRequest; | ||
import com.clova.anifriends.domain.volunteer.repository.VolunteerRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class VolunteerService { | ||
|
||
private final VolunteerRepository volunteerRepository; | ||
|
||
@Transactional | ||
public Long registerVolunteer(RegisterVolunteerRequest registerVolunteerRequest) { | ||
Volunteer volunteer = new Volunteer( | ||
registerVolunteerRequest.email(), | ||
registerVolunteerRequest.password(), | ||
registerVolunteerRequest.birthDate(), | ||
registerVolunteerRequest.phoneNumber(), | ||
registerVolunteerRequest.gender(), | ||
registerVolunteerRequest.name() | ||
); | ||
|
||
volunteerRepository.save(volunteer); | ||
return volunteer.getVolunteerId(); | ||
} | ||
} |
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/com/clova/anifriends/domain/volunteer/wrapper/VolunteerName.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,19 +1,34 @@ | ||
package com.clova.anifriends.domain.volunteer.wrapper; | ||
|
||
import com.clova.anifriends.domain.volunteer.exception.VolunteerBadRequestException; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Embeddable | ||
public class VolunteerName { | ||
|
||
private static final int MAX_VOLUNTEER_NAME_LENGTH = 10; | ||
|
||
@Column(name = "name") | ||
private String name; | ||
|
||
protected VolunteerName() { | ||
} | ||
|
||
public VolunteerName(String value) { | ||
validateVolunteerName(value); | ||
this.name = value; | ||
} | ||
|
||
private void validateVolunteerName(String name) { | ||
if (name == null || name.isBlank()) { | ||
throw new VolunteerBadRequestException("μ΄λ¦μ νμ νλͺ©μ λλ€."); | ||
} | ||
|
||
if (name.length() > MAX_VOLUNTEER_NAME_LENGTH) { | ||
throw new VolunteerBadRequestException("μ΄λ¦μ μ΅λ 10μμ λλ€."); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/clova/anifriends/domain/volunteer/wrapper/VolunteerPassword.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,19 +1,31 @@ | ||
package com.clova.anifriends.domain.volunteer.wrapper; | ||
|
||
import com.clova.anifriends.domain.volunteer.exception.VolunteerBadRequestException; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Embeddable | ||
public class VolunteerPassword { | ||
|
||
private static final int MIN_PASSWORD_LENGTH = 6; | ||
private static final int MAX_PASSWORD_LENGTH = 16; | ||
|
||
@Column(name = "password") | ||
private String password; | ||
|
||
protected VolunteerPassword() { | ||
} | ||
|
||
public VolunteerPassword(String value) { | ||
validateVolunteerPassword(value); | ||
this.password = value; | ||
} | ||
|
||
private void validateVolunteerPassword(String password) { | ||
if (password.length() < MIN_PASSWORD_LENGTH || password.length() > MAX_PASSWORD_LENGTH) { | ||
throw new VolunteerBadRequestException("λΉλ°λ²νΈλ μ΅μ 6μ, μ΅λ 16μμ λλ€."); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/clova/anifriends/domain/volunteer/wrapper/VolunteerPhoneNumber.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,18 +1,32 @@ | ||
package com.clova.anifriends.domain.volunteer.wrapper; | ||
|
||
import com.clova.anifriends.domain.volunteer.exception.VolunteerBadRequestException; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Embeddable | ||
public class VolunteerPhoneNumber { | ||
|
||
private static final int MIN_PHONE_NUMBER_LENGTH = 9; | ||
private static final int MAX_PHONE_NUMBER_LENGTH = 11; | ||
|
||
@Column(name = "phone_number") | ||
private String phoneNumber; | ||
|
||
protected VolunteerPhoneNumber() { | ||
} | ||
|
||
public VolunteerPhoneNumber(String value) { | ||
validateVolunteerPhoneNumber(value); | ||
this.phoneNumber = value; | ||
} | ||
|
||
private void validateVolunteerPhoneNumber(String phoneNumber) { | ||
if (phoneNumber.length() < MIN_PHONE_NUMBER_LENGTH | ||
|| phoneNumber.length() > MAX_PHONE_NUMBER_LENGTH) { | ||
throw new VolunteerBadRequestException("μ νλ²νΈλ μ΅μ 9μ, μ΅λ 11μμ λλ€."); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/clova/anifriends/domain/volunteer/wrapper/VolunteerTemperature.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,19 +1,30 @@ | ||
package com.clova.anifriends.domain.volunteer.wrapper; | ||
|
||
import com.clova.anifriends.domain.volunteer.exception.VolunteerBadRequestException; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Embeddable | ||
public class VolunteerTemperature { | ||
|
||
private static final int MAX_VOLUNTEER_TEMPERATURE = 99; | ||
|
||
@Column(name = "temperature") | ||
private Integer temperature; | ||
|
||
protected VolunteerTemperature() { | ||
} | ||
|
||
public VolunteerTemperature(int value) { | ||
validateVolunteerTemperature(value); | ||
this.temperature = value; | ||
} | ||
|
||
private void validateVolunteerTemperature(int temperature) { | ||
if (temperature > MAX_VOLUNTEER_TEMPERATURE) { | ||
throw new VolunteerBadRequestException("λ΄μ¬μ 체μ¨μ 99λ μ΄νμ λλ€."); | ||
} | ||
} | ||
} |
Oops, something went wrong.