Sequence Diagram - bounswe/bounswe2025group10 GitHub Wiki

This page collects all the sequence diagrams for the core functionalities of the system. Each sequence diagram represents the timeline of an interaction between actors (users/admins) and the system.


📎 Index of Sequence Diagrams


👤 Actors

  • Regular User
  • Admin

📌 User Use Cases

🔐 Authentication

  • Create Account This shows the user registering, the controller delegating to the user‐service, and the database persisting the new record.
@startuml
actor User
participant "Web UI" as UI
participant "AuthController" as AC
participant "UserService" as US
database Database

== User submits registration ==
User -> UI: fill in signup form\nand click “Sign Up”
UI -> AC: POST /auth/register\n(formData)
AC -> US: createUser(formData)
US -> Database: INSERT INTO users\n(formData)
Database --> US: success
US --> AC: userCreatedResult
AC -> UI: show “Registration Successful”\nor display errors
@enduml
create_account
  • Login This captures credential submission, password check, token generation, and response.
@startuml
actor User
participant "Web UI" as UI
participant "AuthController" as AC
participant "AuthService" as AS
participant "TokenService" as TS
database Database

== User attempts login ==
User -> UI: enter username/password\nand click “Login”
UI -> AC: POST /auth/login\n(credentials)
AC -> AS: authenticate(username, password)
AS -> Database: SELECT * FROM users\nWHERE username=?
Database --> AS: userRecord
AS -> AS: verifyPasswordHash(password, userRecord.hash)

alt credentials valid
  AS -> TS: generateToken(userRecord.id)
  TS --> AS: jwtToken
  AS --> AC: authSuccess(jwtToken)
  AC -> UI: set auth cookie\nredirect to Dashboard
else invalid credentials
  AS --> AC: authFailure
  AC -> UI: show “Invalid username or password”
end
@enduml
login

🌱 Forum & Posts

  • Open another users profile openAnotherUser
@startuml
actor User
participant "UI" as UI
participant "ProfileController" as Controller
participant "ProfileService" as Service
database "User Database" as DB
User -> UI : Clicks on another user's profile
UI -> Controller : requestViewProfile(userId)
Controller -> Service : getUserProfile(userId)
Service -> DB : fetchUserData(userId)
DB --> Service : userData
Service --> Controller : userProfile
Controller --> UI : displayProfile(userProfile)
@enduml
  • Enter into own profile enterIntoOwnProfile
@startuml
actor User
participant "UI" as UI
participant "ProfileController" as Controller
participant "ProfileService" as Service
database "User Database" as DB

User -> UI : Clicks on "My Profile"
UI -> Controller : requestOwnProfile()
Controller -> Service : getOwnProfile(sessionUserId)
Service -> DB : fetchUserData(sessionUserId)
DB --> Service : userData
Service --> Controller : userProfile
Controller --> UI : displayOwnProfile(userProfile)
@enduml
  • Follow a user followUser
@startuml
actor User
participant "UI" as UI
participant "FollowController" as Controller
participant "FollowService" as Service
database "Follow Database" as FollowDB

User -> UI : Clicks "Follow" on another user's profile
UI -> Controller : followUser(targetUserId)
Controller -> Service : followUser(sessionUserId, targetUserId)
Service -> FollowDB : addFollow(sessionUserId, targetUserId)
FollowDB --> Service : followConfirmed
Service --> Controller : followSuccess
Controller --> UI : showFollowedState()
@enduml
  • Enter into forum
  • Create post
  • Open a post
  • Save post
  • Like post
  • Comment to post

📄 Profile Management

  • Upload profile picture

update_profile_picture

@startuml
title Upload Profile Picture

actor User
participant "Web UI" as UI
participant UserManagementSystem as UMS
participant Profile
participant StorageService as SS
participant DatabaseHandler as DB

User -> UI : Click "Upload Profile Picture"
activate UI

UI -> UMS : uploadProfilePicture(file)
activate UMS

alt valid file
    UMS -> Profile : setProfileImage(file)
    activate Profile

    Profile -> SS : storeImage(file)
    activate SS
    SS --> Profile : imageURL
    deactivate SS

    Profile -> DB : sendQuery("UPDATE Profile\nSET profileImage = imageURL\nWHERE id = …")
    activate DB

    alt update succeeds
        DB --> Profile : success
        deactivate DB

        Profile --> UMS : updateSuccess
        deactivate Profile

        UMS --> UI : showSuccess("Profile picture uploaded")
    else update fails
        DB --> Profile : error
        deactivate DB

        Profile --> UMS : updateError("DB error")
        deactivate Profile

        UMS --> UI : showError("Could not save profile picture")
    end

else invalid file
    UMS --> UI : showError("Invalid file format or size")
end

deactivate UMS
UI --> User : Display result
deactivate UI

@enduml
  • Upload new profile picture

upload_new_profile_picture

@startuml
title Upload New Profile Picture

actor User
participant "Web UI" as UI
participant UserManagementSystem as UMS
participant Profile
participant StorageService as SS
participant DatabaseHandler as DB

User -> UI : Click "Change Profile Picture"
activate UI

UI -> UMS : uploadNewProfilePicture(newFile)
activate UMS

alt valid file
    UMS -> Profile : getProfileImage()
    activate Profile
    Profile --> UMS : oldImageURL
    deactivate Profile

    UMS -> Profile : removeOldImage(oldImageURL)
    activate Profile
    Profile -> SS : deleteImage(oldImageURL)
    activate SS

    alt deletion succeeds
        SS --> Profile : deletionSuccess
        deactivate SS
        Profile --> UMS : deletionSuccess
        deactivate Profile
    else deletion fails
        SS --> Profile : deletionError
        deactivate SS
        Profile --> UMS : deletionError("Could not remove old image")
        deactivate Profile
        UMS --> UI : showWarning("Old image not found or already deleted")
    end

    UMS -> Profile : setProfileImage(newFile)
    activate Profile

    Profile -> SS : storeImage(newFile)
    activate SS
    SS --> Profile : newImageURL
    deactivate SS

    Profile -> DB : sendQuery("UPDATE Profile\nSET profileImage = newImageURL\nWHERE id = …")
    activate DB

    alt update succeeds
        DB --> Profile : success
        deactivate DB
        Profile --> UMS : updateSuccess
        deactivate Profile
        UMS --> UI : showSuccess("Profile picture updated")
    else update fails
        DB --> Profile : error
        deactivate DB
        Profile --> UMS : updateError("DB error")
        deactivate Profile
        UMS --> UI : showError("Could not update profile picture")
    end

else invalid file
    UMS --> UI : showError("Invalid file format or size")
end

deactivate UMS
UI --> User : Display result
deactivate UI
@enduml

🧠 Tips System

  • Enter into tips section

enter_into_tips_section

@startuml
title Enter Into Tips Section

actor User
participant "Web UI" as UI
participant Tips
participant DatabaseHandler as DB

User -> UI : Click "Tips" menu
activate UI

UI -> Tips : listTips()
activate Tips

Tips -> DB : sendQuery("SELECT * FROM Tips")
activate DB

alt query succeeds
    DB --> Tips : tipsList
    deactivate DB

    Tips --> UI : tipsList
    deactivate Tips

    UI --> User : Render tips list
else query fails
    DB --> Tips : error
    deactivate DB

    Tips --> UI : showError("Could not load tips")
    deactivate Tips

    UI --> User : Display error message
end

deactivate UI
@enduml
  • Submit a tip

submitTipSeqDiagram1

@startuml
actor User
boundary "Tip Submit View" as View
entity   "TipService"       as TipService
entity   "Tip"              as Tip
database "TipsTable"        as DB

User        -> View        : enter title & description\nclick "Submit"
View        -> TipService  : addTip(title, description)
TipService  -> Tip         : new(title, description)
Tip         --> TipService
TipService  -> DB          : INSERT Tip

alt insert succeeded
    DB          --> TipService : OK
    TipService  --> View       : success
    View        --> User       : "Tip added successfully"
else insert failed
    DB          --> TipService : error
    TipService  --> View       : failure
    View        --> User       : "Failed to add tip"
end
@enduml
  • Comment on a tip

commentOnATipSeqDiagram1

@startuml
actor User
boundary "Tip Detail View" as View
entity   "TipService"       as TipService
entity   "TipComment"       as TipComment
database "TipsTable"        as DB

User       -> View        : enter comment text\nclick "Comment"
View       -> TipService  : addTipComment(tipId, content, userId)
TipService -> TipComment  : new(content, userId)
TipComment --> TipService
TipService -> DB          : INSERT TipComment

alt insert succeeded
    DB          --> TipService : OK
    TipService  --> View       : success
    View        --> User       : "Comment added successfully"
else insert failed
    DB          --> TipService : error
    TipService  --> View       : failure
    View        --> User       : "Failed to add comment"
end
@enduml
  • Like a tip

likeATipSeqDiagram1

@startuml
actor User
boundary "Tip List View" as View
entity   "TipService"    as TipService
database "TipsTable"     as DB

User       -> View        : click "Like"
View       -> TipService  : likeTip(tipId, userId)
TipService -> DB          : UPDATE Tip SET likeCount = likeCount + 1\nWHERE id = tipId

alt update succeeded
    DB          --> TipService : OK
    TipService  --> View       : success
    View        --> User       : "Like registered"
else update failed
    DB          --> TipService : error
    TipService  --> View       : failure
    View        --> User       : "Failed to like tip"
end
@enduml
  • Dislike a tip

dislikeATipSeqDiagram1

@startuml
actor User
boundary "Tip List View" as View
entity   "TipService"    as TipService
database "TipsTable"     as DB

User       -> View        : click "Dislike"
View       -> TipService  : dislikeTip(tipId, userId)
TipService -> DB          : UPDATE Tip SET dislikeCount = dislikeCount + 1\nWHERE id = tipId

alt update succeeded
    DB          --> TipService : OK
    TipService  --> View       : success
    View        --> User       : "Dislike registered"
else update failed
    DB          --> TipService : error
    TipService  --> View       : failure
    View        --> User       : "Failed to dislike tip"
end
@enduml

🏆 Achievements & Reports

  • Enter into the achievement page

swe_13131

@startuml
title Enter into the achievement page (using getAchievementById)

    actor User
    participant "AchievementPage (UI)" as UI
    participant "ManagementSystem (MS)" as MS
    participant "UserManagementSystem (UMS)" as UMS
    participant "DatabaseHandler (DBH)" as DBH
    participant AchievementClass as Ach

    User -> UI : click "View Achievements"
    UI -> MS : userManagementSystem.getUserById(userId)
    MS -> UMS : getUserById(userId)
    UMS -> DBH : sendQuery("SELECT id\n FROM UserAchievements\n WHERE userId = ?")

    alt [DB_query_succeeds]
        DBH --> UMS : QueryReturn(idRows)

        alt [has_achievements]
            loop for each idRow in idRows
                UMS -> Ach : getAchievementById(idRow.id)
                Ach -> DBH : sendQuery("SELECT *\n FROM Achievements\n WHERE id = ?")
                DBH --> Ach : QueryReturn(fullRow)
                Ach -> Ach : set fields from fullRow
                Ach --> UMS : Achievement instance
            end
            UMS --> MS : return User (with populated achievements)
            MS --> UI : User
            UI -> UI : render User.profile.achievements
            UI --> User : display achievements page

        else [no_achievements]
            UMS --> MS : return User (with empty achievements)
            MS --> UI : User
            UI -> UI : render "No achievements yet"
            UI --> User : display empty state
        end

    else [error]
        DBH --> UMS : error (e.g. SQL exception)
        UMS --> MS : propagate error
        MS --> UI : 500 Internal Server Error
        UI --> User : show error message
    end
@enduml
  • Open discussion section swe123
@startuml
title Open discussion section with Pagination

actor User
participant "DiscussionPage (UI)" as UI
participant "ManagementSystem (MS)" as MS
participant "PostManagementSystem (PMS)" as PMS
participant "DatabaseHandler (DBH)" as DBH
database "Post DB" as DB
participant Post
participant Comment

User -> UI : click "Open Discussion"
UI -> MS : postManagementSystem.loadPosts(pageNumber, postPerPage)
MS -> PMS : loadPosts(pageNumber, postPerPage)

PMS -> DBH : getPosts(pageNumber, postPerPage)
DBH -> DB : executeQuery("SELECT *\nFROM Posts\nLIMIT ? OFFSET ?")
DB --> DBH : resultSet(postRows)

alt [posts loaded]
    DBH --> PMS : List<Post>(postRows)
    loop for each postRow in postRows
        PMS -> Post : new Post(postRow)
        PMS -> DBH : getCommentsByPostId(postRow.id)
        DBH -> DB : executeQuery("SELECT *\nFROM Comments\nWHERE postId = ?")
        DB --> DBH : resultSet(commentRows)
        DBH --> PMS : List<Comment>(commentRows)
        loop for each commentRow in commentRows
            PMS -> Comment : new Comment(commentRow)
            PMS -> Post : addComment(Comment)
        end
    end
    PMS --> MS : return List<Post>
    MS --> UI : posts
    UI -> UI : render posts with nested comments
    UI --> User : display discussion section

else [no posts]
    DBH --> PMS : List<Post>(empty)
    PMS --> MS : return empty List<Post>
    MS --> UI : posts (empty)
    UI -> UI : render "No posts yet"
    UI --> User : display empty state

else [DB error]
    DB -> DBH : error (e.g. SQL exception)
    DBH --> PMS : propagate error
    PMS --> MS : propagate error
    MS --> UI : 500 Internal Server Error
    UI --> User : show error message
end
@enduml
  • Create summary reports

image

@startuml
title Generate Waste Summary Report

actor User
participant "App UI" as UI
participant "ManagementSystem (MS)" as MS
participant "PostManagementSystem (PMS)" as PMS
participant "Profile" as Profile
participant "Waste" as Waste
participant "DatabaseHandler (DBH)" as DBH
database "Waste DB" as DB

User -> UI : click "Generate Waste Summary"\n(interval: startDate, endDate, format: "week/month/year")
UI -> MS : postManagementSystem.loadPosts()
MS -> PMS : loadPosts()
PMS -> Profile : getWasteForSummary(format)
Profile -> Waste : getWasteForSummary(format)
Waste -> DBH : sendQuery("SELECT *\n" + "FROM Waste\n" + "WHERE date >= ? AND date <= ? AND type = ?")
DBH -> DB : executeQuery(query)
DB --> DBH : resultSet(wasteRows)

alt [query succeeds]
  DBH --> Waste : QueryReturn(wasteRows)
  Waste -> Profile : instantiate Waste objects
  Profile --> MS : true
  MS --> UI : 200 OK

  UI -> Waste : listAllWaste()
  Waste --> UI : List<Waste>

  alt [waste in interval]
    UI -> UI : filter waste by date interval
    UI -> UI : compute waste summary metrics\n(total waste, recycled, types, etc.)
    UI --> User : display waste summary report
  else [no waste]
    UI --> User : display "No waste in interval"
  end

else [DB error]
  DB --> DBH : error
  DBH --> Waste : propagate error
  Waste --> MS : false / error
  MS --> UI : 500 Internal Server Error
  UI --> User : show error message
end
@enduml

🗓️ Challenge System

  • Evaluate Progress
  • Customize Visualization by Time/Metric
  • Create challenge
  • Edit challenge
  • Delete challenge
  • Track challenge

📘 Waste Tracking

  • Log waste entry log_waste
@startuml
title Log Waste Entry

actor User
participant "Web UI" as UI
participant UserManagementSystem as UMS
participant Profile
participant DatabaseHandler as DB

User -> UI : Enter waste type and amount\nClick "Log Waste"
activate UI

UI -> UMS : logWaste(wasteData)
activate UMS

alt wasteData valid
    UMS -> Profile : logWaste(wasteData)
    activate Profile

    Profile -> DB : sendQuery("INSERT INTO WasteEntries\n(user_id, challenge_id, type, amount, date)\nVALUES (…, wasteData.type, wasteData.amount, NOW())")
    activate DB

    alt insert succeeds
        DB --> Profile : success
        deactivate DB

        Profile --> UMS : true
        deactivate Profile

        UMS --> UI : showSuccess("Waste entry logged")
    else insert fails
        DB --> Profile : error
        deactivate DB

        Profile --> UMS : false
        deactivate Profile

        UMS --> UI : showError("Could not log waste entry")
    end

else invalid data
    UMS --> UI : showError("Invalid waste type or amount")
end

deactivate UMS
UI --> User : Display result
deactivate UI

@enduml
  • Customize Visualization by Time/Metric time:metric
@startuml Customize_Visualization
title Customize Visualization by Time/Metric

actor User
participant "Web UI" as UI
participant "VisualizationController" as VC
participant "AnalyticsService" as AS
database "Waste DB" as WDB

User -> UI : Select start/end dates\nand metric, click “Apply”
activate UI

UI -> VC : GET /visualizations\n?start=&end=&metric=
activate VC

VC -> AS : getVisualizationData(start, end, metric)
activate AS

AS -> WDB : SELECT SUM/AVG(...) FROM waste_entries
WDB --> AS : dataRows

AS --> VC : chartData (JSON)
deactivate AS

VC --> UI : 200 OK {chartData}
deactivate VC
UI --> User : Render chart
deactivate UI
@enduml
  • Evaluate Progress progress
@startuml Evaluate_Progress
title Evaluate Progress

actor User
participant "Web UI" as UI
participant "ProgressController" as PC
participant "ProgressService" as PS
participant "ReportService" as RS
participant "NotificationService" as NS
database "Waste DB" as WDB

User -> UI : Click “View Progress”
activate UI

UI -> PC : GET /progress
activate PC

PC -> PS : evaluateProgress()
activate PS

PS -> WDB : SELECT * FROM waste_entries\nWHERE userId=…
WDB --> PS : entriesList

PS -> PS : computeTrend(entriesList)
PS -> RS : generateReport(trendData)
activate RS
RS --> PS : reportObject
deactivate RS

PS --> PC : {trendData, reportObject}
deactivate PS

alt milestone reached
    PC -> NS : POST /notify/user/{id} {summary}
    activate NS
    NS --> NS : send email/push
    NS --> PC : 202 Accepted
    deactivate NS
end

PC --> UI : 200 OK {progressData, reportLink}
deactivate PC
UI --> User : Display trends & link to report
deactivate UI
@enduml

Post Use Cases

Post Operations (e.g save,like,comment)

User saves Post

userSavePost2

 @startuml
      title User saves a post 
      actor User
      participant "User Class" as userClass
      database UserDB as UserDB

      User -> userClass : savePost(Post)
      userClass -> UserDB : addToSavedPost(Post)
      alt not found / db error
          UserDB --> userClass : databaseError
          userClass --> User : "Post could not be saved"
  
      else saved
          UserDB-->userClass: DatabaseSuccess
          userClass-->User:"Post saved"
      end
      @enduml

User likes a post

user_like

 @startuml User_Likes_Post
      title User likes a post 
      actor User
      participant "Post Class" as post
      database PostDB as db

      User -> post : incrementLike()
      post -> db : addLike(user_id,post_id)
      alt not found / db error
          db --> post : databaseError
          post --> User : "Like couldn't saved"
  
      else saved
          db-->post: DatabaseSuccess
          post-->User:"Like saved"
      end
      @enduml

User comments on a post

comment

 @startuml User_Comment_Post
      title User comments a post 
      actor User
      participant "Post Class" as post
      database PostDB as db

      User -> post : commentPost(comment,user)
      post -> db : addComment(post_id,comment,user)
      alt not found / db error
          db --> post : databaseError
          post --> User : "Comment couldn't saved"
  
      else saved
          db-->post: DatabaseSuccess
          post-->User:"Comment saved"
      end
      @enduml

🛠️ Admin Use Cases

Authorization

Admin Login

admin_login_sequence

@startuml Admin_Login
title Admin logs in through shared Auth service
actor Admin
participant "Admin UI" as UI
participant "Auth Service" as Auth
database "User DB" as DB

Admin -> UI : enter credentials
UI -> Auth : POST /login {username, password}
Auth -> DB : verifyUser()
alt success
    DB --> Auth : user, hashedPw, roles
    Auth --> UI : 200 OK {JWT / session}
    UI --> Admin : show dashboard
else invalidcreds
    DB --> Auth : not‑found / pw‑mismatch
    Auth --> UI : 401 Unauthorized
    UI --> Admin : show error ("Invalid credentials")
end
@enduml

🔧 Moderation

Change user role

admin_change_user_role_sequence

      @startuml Admin_Change_User_Role
      title Admin changes a user's role (e.g., promote to moderator)
      actor Admin
      participant "Admin UI" as UI
      participant "User Svc" as User
      participant "Notification Svc" as Notify
      database "User DB" as UDB

      Admin -> UI : select user, newRole
      UI -> User : PATCH /users/{id} {role=newRole}
      User -> UDB : UPDATE user.role = newRole
      alt success
          UDB --> User : OK
          User -> Notify : POST /notify(user, "Your role was changed to {newRole}")
          Notify --> Notify : push/email
          Notify --> User : 202
          User --> UI : 200 OK
          UI --> Admin : toast "Role updated"
      else invalidRole / dbError
          UDB --> User : error
          User --> UI : error
          UI --> Admin : show error msg
      end
      @enduml

Delete post:

admin_post_delete_sequence

      @startuml Admin_Delete_Post
      title Admin deletes a post (hard delete, notify author, pin strike)
      actor Admin
      participant "Admin UI" as UI
      participant "Post Svc" as Post
      participant "Notification Svc" as Notify
      participant "User Svc" as User
      database "Post DB" as PDB
      database "User DB" as UDB

      Admin -> UI : click "Delete Post"
      UI -> Post : DELETE /posts/{postId}
      Post -> PDB : DELETE post(row)
      alt not found / db error
          PDB --> Post : 404 / error
          Post --> UI : error
          UI --> Admin : show failure msg
      else deleted
          PDB --> Post : 204
          Post -> User : GET /users/{authorId}
          User -> UDB : SELECT user
          UDB --> User : userRow
          User --> Post : userData
          Post -> Notify : POST /notify(author, "Your post was removed by Admin")
          Notify --> Notify : send email/push
          Notify --> Post : 202
          Post -> User : PATCH /users/{authorId} {moderationStrike +=1}
          User -> UDB : UPDATE strikes
          UDB --> User : OK
          User --> Post : OK
          Post --> UI : 204
          UI --> Admin : toast "Post deleted & author notified"
      end
      @enduml

Delete comment

admin_comment_delete_sequence

      @startuml Admin_Delete_Comment
      title Admin deletes a comment (hard delete, notify author, pin strike)
      actor Admin
      participant "Admin UI" as UI
      participant "Comment Svc" as Comment
      participant "Notification Svc" as Notify
      participant "User Svc" as User
      database "Comment DB" as CDB
      database "User DB" as UDB

      Admin -> UI : click "Delete Comment"
      UI -> Comment : DELETE /comments/{id}
      Comment -> CDB : DELETE comment(row)
      alt error
          CDB --> Comment : 404 / error
          Comment --> UI : error
          UI --> Admin : failure msg
      else deleted
          CDB --> Comment : 204
          Comment -> User : GET /users/{authorId}
          User -> UDB : SELECT user
          UDB --> User : userRow
          User --> Comment : userData
          Comment -> Notify : POST /notify(author, "Your comment was removed by Admin")
          Notify --> Notify : push/email
          Notify --> Comment : 202
          Comment -> User : PATCH /users/{authorId} {moderationStrike +=1}
          User -> UDB : UPDATE strikes
          UDB --> User : OK
          User --> Comment : OK
          Comment --> UI : 204
          UI --> Admin : toast "Comment deleted & author notified"
      end
      @enduml

Delete post and Delete comment:

image

@startuml
title System Administrator Moderates Posts (with Success & Error Handling)

actor SystemAdministrator
participant ManagementSystem
participant PostManagementSystem as PMS
participant Post
participant Comment

SystemAdministrator -> ManagementSystem : getPostManagementSystem()
ManagementSystem --> SystemAdministrator : PMS

SystemAdministrator -> PMS : getPostById(postId)

loop for each post in posts
    PMS -> PMS : check post.id == postId
end

alt Post Found
    PMS --> SystemAdministrator : Post
    
    alt Delete Post
        SystemAdministrator -> PMS : deletePost(post)
        PMS --> SystemAdministrator : void
        note over PMS : Post successfully deleted.
    else Delete Comment
        SystemAdministrator -> PMS : getCommentById(commentId)

        loop for each comment in post.comments
            PMS -> PMS : check comment.id == commentId
        end

        alt Comment Found
            PMS --> SystemAdministrator : Comment
            SystemAdministrator -> PMS : deleteComment(post, comment)
            PMS --> SystemAdministrator : void
            note over PMS : Comment successfully deleted.
        else Comment Not Found
            PMS --> SystemAdministrator : null
            note over PMS : Comment not found. Cannot delete.
        end
    end

else Post Not Found
    PMS --> SystemAdministrator : null
    note over PMS : Post not found. Cannot proceed.
end

@enduml

⚙️ Admin Challenge Management

Change challenge reward

admin_change_challenge_reward

      @startuml Admin_Change_Challenge_Reward
      title Admin changes the reward of a challenge
      actor Admin
      participant "Admin UI" as UI
      participant "Challenge Svc" as Challenge
      participant "Notification Svc" as Notify
      database "Challenge DB" as CDB

      Admin -> UI : set new reward value
      UI -> Challenge : PATCH /challenges/{id} {reward=…}
      Challenge -> CDB : UPDATE reward
      alt success
          CDB --> Challenge : 200 OK
          Challenge -> Notify : POST /bulkNotify(affectedUsers, "Challenge reward updated")
          Notify --> Notify : push/email
          Notify --> Challenge : 202 Accepted
          Challenge --> UI : 200 OK
          UI --> Admin : toast "Reward updated"
      else validation / db error
          CDB --> Challenge : 400|409|500
          Challenge --> UI : error payload
          UI --> Admin : show error msg
      end
      @enduml

Delete challenge

admin_challenge_delete_sequence

      @startuml Admin_Delete_Challenge
      title Admin deletes a sustainability challenge (cascade → progress, notify users)
      actor Admin
      participant "Admin UI" as UI
      participant "Challenge Svc" as Challenge
      participant "Progress Svc" as Progress
      participant "Notification Svc" as Notify
      database "Challenge DB" as CDB
      database "Progress DB" as PDB

      Admin -> UI : click "Delete Challenge"
      UI -> Challenge : DELETE /challenges/{id}
      Challenge -> CDB : DELETE challenge(id)
      alt DB error
          CDB --> Challenge : SQLException
          Challenge --> UI : 500 Error
          UI --> Admin : show "Delete failed"
      else Deleted
          CDB --> Challenge : 204 No Content
          Challenge -> Progress : DELETE /progress?challengeId={id}
          Progress -> PDB : deleteAllRows(challengeId)
          alt cascade error
              PDB --> Progress : error
              Progress --> Challenge : 500
              Challenge --> UI : 500 (partial failure)
              UI --> Admin : show "Progress cleanup failed"
          else Progress cleared
              PDB --> Progress : 204
              Progress --> Challenge : OK
              Challenge -> Notify : POST /bulkNotify(affectedUsers, "Challenge deleted")
              Notify --> Notify : send push / email
              Notify --> Challenge : 202 Accepted
              Challenge --> UI : 204
              UI --> Admin : toast "Challenge deleted"
          end
      end
      @enduml

📘 User Challenge Management

Create a Challenge

create_challenge

@startuml
title User Creates a Challenge

actor User
participant "Web UI" as UI
participant ChallengeManagementSystem as CMS
participant Challenge as C
participant DatabaseHandler as DB

User -> UI : Fill and submit "Create Challenge" form\ntitle, description, target, reward
activate UI

UI -> CMS : createChallenge(details)
activate CMS

alt details valid
    CMS -> C : new Challenge(details)
    activate C
    C --> CMS : challengeObj
    deactivate C

    CMS -> DB : sendQuery("INSERT INTO Challenges\n(title, description, target_amount, reward_id)\nVALUES (…, …, …, …)")
    activate DB

    alt insert succeeds
        DB --> CMS : { generatedId }
        deactivate DB

        CMS -> DB : sendQuery("INSERT INTO UserChallenges\n(user_id, challenge_id)\nVALUES (currentUserId, generatedId)")
        activate DB

        alt enrollment succeeds
            DB --> CMS : success
            deactivate DB

            CMS --> UI : showSuccess("Challenge created and joined")
        else enrollment fails
            DB --> CMS : error
            deactivate DB

            CMS --> UI : showWarning("Challenge created but enrollment failed")
        end

    else insert fails
        DB --> CMS : error
        deactivate DB

        CMS --> UI : showError("Could not create challenge")
    end

else details invalid
    CMS --> UI : showError("Invalid challenge data")
end

deactivate CMS
UI --> User : Display result
deactivate UI

@enduml

Delete challenge

delete_challenge

@startuml
title User Deletes a Challenge

actor User
participant "Web UI" as UI
participant ChallengeManagementSystem as CMS
participant Challenge as C
participant DatabaseHandler as DB

User -> UI : Click "Delete Challenge" button
activate UI

UI -> CMS : deleteChallenge(challengeId)
activate CMS

alt challenge exists
    CMS -> C : getChallengeById(challengeId)
    activate C
    C --> CMS : challengeObj
    deactivate C

    CMS -> C : delete()
    activate C

    C -> DB : sendQuery("DELETE FROM Challenges\nWHERE id = challengeId")
    activate DB

    alt deletion succeeds
        DB --> C : success
        deactivate DB

        C --> CMS : deletionSuccess
        deactivate C

        CMS --> UI : showSuccess("Challenge deleted")
    else deletion fails
        DB --> C : error
        deactivate DB

        C --> CMS : deletionError("DB error")
        deactivate C

        CMS --> UI : showError("Could not delete challenge")
    end

else challenge not found
    CMS --> UI : showError("Challenge not found")
end

deactivate CMS
UI --> User : Display result
deactivate UI

@enduml

🔄 Update Policy

This page is maintained by the development team. If new features are introduced or existing use cases evolve, corresponding sequence diagrams must be added or updated.

⚠️ **GitHub.com Fallback** ⚠️