-
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.
Showing
17 changed files
with
195 additions
and
59 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
26 changes: 26 additions & 0 deletions
26
src/main/java/org/sopt/seonyakServer/domain/senior/controller/SeniorController.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,26 @@ | ||
package org.sopt.seonyakServer.domain.senior.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.sopt.seonyakServer.domain.senior.dto.SeniorProfileRequest; | ||
import org.sopt.seonyakServer.domain.senior.service.SeniorService; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
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/v1/senior") | ||
public class SeniorController { | ||
|
||
private final SeniorService seniorService; | ||
|
||
@PatchMapping("/profile") | ||
public ResponseEntity<Void> patchProfile( | ||
@RequestBody final SeniorProfileRequest seniorProfileRequest | ||
) { | ||
seniorService.patchSeniorProfile(seniorProfileRequest); | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
Empty file.
12 changes: 12 additions & 0 deletions
12
src/main/java/org/sopt/seonyakServer/domain/senior/dto/SeniorProfileRequest.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,12 @@ | ||
package org.sopt.seonyakServer.domain.senior.dto; | ||
|
||
import org.sopt.seonyakServer.domain.senior.model.PreferredTimeList; | ||
|
||
public record SeniorProfileRequest( | ||
String catchphrase, | ||
String career, | ||
String award, | ||
String story, | ||
PreferredTimeList preferredTimeList | ||
) { | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/org/sopt/seonyakServer/domain/senior/model/PreferredTimeList.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.sopt.seonyakServer.domain.senior.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAnySetter; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
public class PreferredTimeList { | ||
private Map<String, List<TimeRange>> preferredTimeList = new HashMap<>(); | ||
|
||
@JsonAnySetter | ||
public void setPreferredTime(String day, List<TimeRange> times) { | ||
preferredTimeList.put(day, times); | ||
} | ||
|
||
} |
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/org/sopt/seonyakServer/domain/senior/model/TimeRange.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 org.sopt.seonyakServer.domain.senior.model; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
public class TimeRange { | ||
private String startTime; | ||
private String endTime; | ||
} |
Empty file.
19 changes: 19 additions & 0 deletions
19
src/main/java/org/sopt/seonyakServer/domain/senior/repository/SeniorRepository.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,19 @@ | ||
package org.sopt.seonyakServer.domain.senior.repository; | ||
|
||
import java.util.Optional; | ||
import org.sopt.seonyakServer.domain.senior.model.Senior; | ||
import org.sopt.seonyakServer.global.exception.enums.ErrorType; | ||
import org.sopt.seonyakServer.global.exception.model.CustomException; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface SeniorRepository extends JpaRepository<Senior, Long> { | ||
|
||
Optional<Senior> findSeniorById(Long id); | ||
|
||
Optional<Senior> findSeniorByMemberId(Long id); | ||
|
||
default Senior findSeniorByIdOrThrow(Long id) { | ||
return findSeniorById(id) | ||
.orElseThrow(() -> new CustomException(ErrorType.NOT_FOUND_MEMBER_ERROR)); | ||
} | ||
} |
Empty file.
34 changes: 34 additions & 0 deletions
34
src/main/java/org/sopt/seonyakServer/domain/senior/service/SeniorService.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,34 @@ | ||
package org.sopt.seonyakServer.domain.senior.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.sopt.seonyakServer.domain.senior.dto.SeniorProfileRequest; | ||
import org.sopt.seonyakServer.domain.senior.model.Senior; | ||
import org.sopt.seonyakServer.domain.senior.repository.SeniorRepository; | ||
import org.sopt.seonyakServer.global.auth.PrincipalHandler; | ||
import org.sopt.seonyakServer.global.exception.enums.ErrorType; | ||
import org.sopt.seonyakServer.global.exception.model.CustomException; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class SeniorService { | ||
|
||
private final SeniorRepository seniorRepository; | ||
private final PrincipalHandler principalHandler; | ||
|
||
public void patchSeniorProfile(SeniorProfileRequest seniorProfileRequest) { | ||
Senior senior = seniorRepository.findSeniorByMemberId(principalHandler.getUserIdFromPrincipal()) | ||
.orElseThrow(() -> new CustomException(ErrorType.NOT_FOUND_SENIOR_BY_MEMBER)); | ||
|
||
senior.updateSenior( | ||
seniorProfileRequest.catchphrase(), | ||
seniorProfileRequest.career(), | ||
seniorProfileRequest.award(), | ||
seniorProfileRequest.story(), | ||
seniorProfileRequest.preferredTimeList() | ||
); | ||
seniorRepository.save(senior); | ||
} | ||
} |
File renamed without changes.
35 changes: 0 additions & 35 deletions
35
src/main/java/org/sopt/seonyakServer/domain/util/JsonConverter.java
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
src/main/java/org/sopt/seonyakServer/global/auth/PrincipalHandler.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,26 @@ | ||
package org.sopt.seonyakServer.global.auth; | ||
|
||
import org.sopt.seonyakServer.global.exception.enums.ErrorType; | ||
import org.sopt.seonyakServer.global.exception.model.CustomException; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class PrincipalHandler { | ||
|
||
private static final String ANONYMOUS_USER = "anonymousUser"; | ||
|
||
public Long getUserIdFromPrincipal() { | ||
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); | ||
isPrincipalNull(principal); | ||
return Long.valueOf(principal.toString()); | ||
} | ||
|
||
public void isPrincipalNull( | ||
final Object principal | ||
) { | ||
if (principal.toString().equals(ANONYMOUS_USER)) { | ||
throw new CustomException(ErrorType.EMPTY_PRINCIPLE_ERROR); | ||
} | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
src/main/java/org/sopt/seonyakServer/global/config/JpaAuditingConfig.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,9 @@ | ||
package org.sopt.seonyakServer.global.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | ||
|
||
@Configuration | ||
@EnableJpaAuditing | ||
public class JpaAuditingConfig { | ||
} |
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